Skip to content

Commit

Permalink
Merge pull request #45 from ntkme/exec-array
Browse files Browse the repository at this point in the history
Use array args instead of string args for system command
  • Loading branch information
dhh authored Jan 1, 2024
2 parents 660ea09 + 2201587 commit 1f31ec4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
- "3.0"
- "3.1"
- "3.2"
- "3.3"
gemfile:
- Gemfile
- gemfiles/rails_7_0_propshaft.gemfile
Expand All @@ -17,6 +18,11 @@ jobs:
- gemfiles/rails_7_0_sprockets.gemfile
- gemfiles/rails_7_1_sprockets.gemfile
- gemfiles/rails_main_sprockets.gemfile
exclude:
- ruby-version: "3.0"
gemfile: gemfiles/rails_main_propshaft.gemfile
- ruby-version: "3.0"
gemfile: gemfiles/rails_main_sprockets.gemfile
continue-on-error: [ false ]

name: ${{ format('Tests (Ruby {0}, {1})', matrix.ruby-version, matrix.gemfile) }}
Expand Down
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.flat_map(&:split)
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 1f31ec4

Please sign in to comment.