Skip to content

Commit

Permalink
Use array args instead of string args for system command
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Jan 1, 2024
1 parent 660ea09 commit c27dbe1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,22 @@ Rails.application.config.dartsass.builds = {

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 both the hash key and the hash value are directories instead of files, it configures a directory to directory compliation, which compiles all public Sass files whose filenames do not start with underscore (`_`).

```ruby
# config/initializers/dartsass.rb
Rails.application.config.dartsass.builds = {
"." => "."
}
```

## Configuring build options

By default, sass is invoked with `--style=compressed --no-source-map`. You can adjust these options by overwriting `Rails.application.config.dartsass.build_options`.
By default, sass is invoked with `["--style=compressed", "--no-source-map"]`. You can adjust these options by overwriting `Rails.application.config.dartsass.build_options`.

```ruby
# config/initializers/dartsass.rb
Rails.application.config.dartsass.build_options << " --quiet-deps"
Rails.application.config.dartsass.build_options << "--no-charset" << "--quiet-deps"
```

## Importing assets from gems
Expand Down
2 changes: 1 addition & 1 deletion dartsass-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
"rubygems_mfa_required" => "true"
}

spec.files = Dir["{lib,exe}/**/*", "MIT-LICENSE", "LICENSE-DEPENDENCIES", "Rakefile", "README.md"]
spec.files = Dir["{lib,exe}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
spec.bindir = "exe"
spec.executables << "dartsass"

Expand Down
2 changes: 1 addition & 1 deletion lib/dartsass/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module Dartsass
class Engine < ::Rails::Engine
config.dartsass = ActiveSupport::OrderedOptions.new
config.dartsass.builds = { "application.scss" => "application.css" }
config.dartsass.build_options = "--style=compressed --no-source-map"
config.dartsass.build_options = ["--style=compressed", "--no-source-map"]
end
end
14 changes: 7 additions & 7 deletions lib/tasks/build.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ CSS_BUILD_PATH = Rails.root.join("app/assets/builds")

def dartsass_build_mapping
Rails.application.config.dartsass.builds.map { |input, output|
"#{Shellwords.escape(CSS_LOAD_PATH.join(input))}:#{Shellwords.escape(CSS_BUILD_PATH.join(output))}"
}.join(" ")
"#{CSS_LOAD_PATH.join(input)}:#{CSS_BUILD_PATH.join(output)}"
}
end

def dartsass_build_options
Rails.application.config.dartsass.build_options
Rails.application.config.dartsass.build_options.map(&:strip)
end

def dartsass_load_paths
[ CSS_LOAD_PATH ].concat(Rails.application.config.assets.paths).map { |path| "--load-path #{Shellwords.escape(path)}" }.join(" ")
[ CSS_LOAD_PATH ].concat(Rails.application.config.assets.paths).flat_map { |path| ["--load-path", path.to_s] }
end

def dartsass_compile_command
"#{EXEC_PATH} #{dartsass_build_options} #{dartsass_load_paths} #{dartsass_build_mapping}"
[ RbConfig.ruby, EXEC_PATH ].concat(dartsass_build_options).concat(dartsass_load_paths).concat(dartsass_build_mapping)
end

namespace :dartsass do
desc "Build your Dart Sass CSS"
task build: :environment do
system dartsass_compile_command, exception: true
system(*dartsass_compile_command, exception: true)
end

desc "Watch and build your Dart Sass CSS on file changes"
task watch: :environment do
system "#{dartsass_compile_command} -w", exception: true
system(*dartsass_compile_command, "--watch", exception: true)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/install.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace :dartsass do
desc "Install Dart Sass into the app"
task :install do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/dartsass.rb", __dir__)}", exception: true
system RbConfig.ruby, "./bin/rails", "app:template", "LOCATION=#{File.expand_path("../install/dartsass.rb", __dir__)}", exception: true
end
end

0 comments on commit c27dbe1

Please sign in to comment.