Skip to content

Commit

Permalink
Add an ability to build assets from Rails root folder
Browse files Browse the repository at this point in the history
Update README file
  • Loading branch information
mekhovov committed Feb 17, 2022
1 parent 3ff15ea commit 2de1273
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ By default, only `app/assets/stylesheets/application.scss` will be built. If you
```
# config/initializers/dartsass.rb
Rails.application.config.dartsass.builds = {
"app/index.sass" => "app.css",
"site.scss" => "site.css"
"index.sass" => "app.css",
"site.scss" => "site.css"
"engines/travel/app/assets/stylesheets/travel/main.scss" => "travel/main.css",
"lib/stylesheets/common.css" => "common.css",
}
```

The hash key is the relative path to a Sass file in `app/assets/stylesheets/` and the hash value will be the name of the file output to `app/assets/builds/`.

If file does not exist in `app/assets/stylesheets/` directory - relative path will be changed to `Rails.root`.

## Version

Expand Down
10 changes: 7 additions & 3 deletions lib/tasks/build.rake
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
EXEC_PATH = "#{Pathname.new(__dir__).to_s}/../../exe/dartsass"
CSS_LOAD_PATH = Rails.root.join("app/assets/stylesheets")
CSS_BUILD_PATH = Rails.root.join("app/assets/builds")
CSS_LOAD_FROM_RAILS_ROOT_PATH = Rails.root

def dartsass_build_mapping
Rails.application.config.dartsass.builds.map { |input, output|
"#{CSS_LOAD_PATH.join(input)}:#{CSS_BUILD_PATH.join(output)}"
}.join(" ")
builds_map = Rails.application.config.dartsass.builds.map { |input, output|
input_file_path = "#{CSS_LOAD_PATH.join(input)}"
input_file_path = "#{CSS_LOAD_FROM_RAILS_ROOT_PATH.join(input)}" unless File.exist?(input_file_path)
"#{input_file_path}:#{CSS_BUILD_PATH.join(output)}"
}
builds_map.uniq.join(" ")
end

def dartsass_build_options
Expand Down

0 comments on commit 2de1273

Please sign in to comment.