Skip to content

Commit 2de1273

Browse files
committed
Add an ability to build assets from Rails root folder
Update README file
1 parent 3ff15ea commit 2de1273

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ By default, only `app/assets/stylesheets/application.scss` will be built. If you
2929
```
3030
# config/initializers/dartsass.rb
3131
Rails.application.config.dartsass.builds = {
32-
"app/index.sass" => "app.css",
33-
"site.scss" => "site.css"
32+
"index.sass" => "app.css",
33+
"site.scss" => "site.css"
34+
"engines/travel/app/assets/stylesheets/travel/main.scss" => "travel/main.css",
35+
"lib/stylesheets/common.css" => "common.css",
3436
}
3537
```
3638

3739
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/`.
3840

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

4043
## Version
4144

lib/tasks/build.rake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
EXEC_PATH = "#{Pathname.new(__dir__).to_s}/../../exe/dartsass"
22
CSS_LOAD_PATH = Rails.root.join("app/assets/stylesheets")
33
CSS_BUILD_PATH = Rails.root.join("app/assets/builds")
4+
CSS_LOAD_FROM_RAILS_ROOT_PATH = Rails.root
45

56
def dartsass_build_mapping
6-
Rails.application.config.dartsass.builds.map { |input, output|
7-
"#{CSS_LOAD_PATH.join(input)}:#{CSS_BUILD_PATH.join(output)}"
8-
}.join(" ")
7+
builds_map = Rails.application.config.dartsass.builds.map { |input, output|
8+
input_file_path = "#{CSS_LOAD_PATH.join(input)}"
9+
input_file_path = "#{CSS_LOAD_FROM_RAILS_ROOT_PATH.join(input)}" unless File.exist?(input_file_path)
10+
"#{input_file_path}:#{CSS_BUILD_PATH.join(output)}"
11+
}
12+
builds_map.uniq.join(" ")
913
end
1014

1115
def dartsass_build_options

0 commit comments

Comments
 (0)