dartsass-rails 0.1.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 926726f873ae7ec4d5b024cfad0dc452c290baa35842100bd98c74bb13d91eea
4
- data.tar.gz: 65e0520536f1b0649f1394386df0dde7a0f4774155b7a689e04e514e96e3de81
3
+ metadata.gz: 165bcaadffc761840fcd9a39e1b2f6f862974e62b22dab5e6841d485dc94d072
4
+ data.tar.gz: 6629e2d3f46c0a2787fc8af5ba25298f613f5817b3e237c988958ef8d57f2aca
5
5
  SHA512:
6
- metadata.gz: 22ab26793030f9679e5e130567322e999027df10275e922de89f3ffc9ce2976e5dfae6d9b1a8db7c03cf92cd2bd044867e0d30c73fbe1337f45d1d1afba5f92e
7
- data.tar.gz: 3d5c7241ad28f38147543e8dda20f49abc49fbe1361206fb19a1381861a3581701eb3004ced39dd7449bd3082d8d6c1d7a1fbe51aec4d55194ac39ddb44bb93b
6
+ metadata.gz: d5dceba364d547b14f80da2eebf9b55c7b402b911ffa242ccab950b1c54425ca334d5b42916903ea82fa7f0536f1150a6931c8a9c727ef92b05ce2b2dd0b20c1
7
+ data.tar.gz: 352ac02425d2b164d506c36496d19ea016e423e0c01c2bcf4b0e0474fb5c6aad261994be84c1a880b3079694219bcea1c77e932fa1a9caa32ca682700b64171c
data/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  [Sass](https://sass-lang.com) is a stylesheet language that’s compiled to CSS. It allows you to use variables, nested rules, mixins, functions, and more, all with a fully CSS-compatible syntax.
4
4
 
5
- This gem wraps [the standalone executable version](https://github.com/sass/dart-sass/releases) of the Dart version of Sass. These executables are platform specific, but included in this gem are the ones for macOS, Linux, and Windows. The Linux and Windows versions are the ones for 64-bit, and the macOS version is compiled for Intel but will run on ARM as well.
5
+ This gem wraps [the standalone executable version](https://github.com/sass/dart-sass/releases) of the Dart version of Sass. These executables are platform specific, but included in this gem are the ones for macOS (Intel, Apple Silicon), Linux (x86-64, AArch64), and Windows (x86-64).
6
6
 
7
- The installer will create your Sass input file in `app/assets/stylesheets/application.scss`. This is where you should import all the style files to be compiled [using the @use rule](https://sass-lang.com/documentation/at-rules/use). When you run `rails dartsass:build`, this input file will be used to generate the output in `app/assets/builds/application.css`. That's the output CSS that you'll include in your app.
7
+ The installer will create your default Sass input file in `app/assets/stylesheets/application.scss`. This is where you should import all the style files to be compiled [using the @use rule](https://sass-lang.com/documentation/at-rules/use). When you run `rails dartsass:build`, this input file will be used to generate the output in `app/assets/builds/application.css`. That's the output CSS that you'll include in your app. The load path for Sass is automatically configured to be `app/assets/stylesheets`.
8
8
 
9
- If you need to use a custom input or output file, you can run `bundle exec dartsass` to access the platform-specific executable, and give it your own build options.
9
+ If you need to configure the build process beyond configuring the build files – you can run `bundle exec dartsass` to access the platform-specific executable, and give it your own build options.
10
10
 
11
- When you're developing your application, you want to run Dart Sass in watch mode, so changes are automatically reflected in the generated CSS output. You can do this either by running `rails dartsass:watch` as a separate process, or by running `./bin/dev` which uses [foreman](https://github.com/ddollar/foreman) to starts both the Dart Sass watch process and the rails server in development mode.
11
+ When you're developing your application, you want to run Dart Sass in watch mode, so changes are automatically reflected in the generated CSS output. You can do this either by running `rails dartsass:watch` as a separate process, or by running `./bin/dev` which uses [foreman](https://github.com/ddollar/foreman) to start both the Dart Sass watch process and the rails server in development mode.
12
12
 
13
13
 
14
14
  ## Installation
@@ -16,11 +16,110 @@ When you're developing your application, you want to run Dart Sass in watch mode
16
16
  1. Run `./bin/bundle add dartsass-rails`
17
17
  2. Run `./bin/rails dartsass:install`
18
18
 
19
-
20
19
  ## Building in production
21
20
 
22
21
  The `dartsass:build` is automatically attached to `assets:precompile`, so before the asset pipeline digests the files, the Dart Sass output will be generated.
23
22
 
23
+ ## Configuring builds
24
+
25
+ By default, only `app/assets/stylesheets/application.scss` will be built. If you'd like to change the path of this stylesheet, add additional entry points, or customize the name of the built file, use the `Rails.application.config.dartsass.builds` configuration hash.
26
+
27
+
28
+ ```ruby
29
+ # config/initializers/dartsass.rb
30
+ Rails.application.config.dartsass.builds = {
31
+ "app/index.sass" => "app.css",
32
+ "site.scss" => "site.css"
33
+ }
34
+ ```
35
+
36
+ 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/`.
37
+
38
+ ## Configuring build options
39
+
40
+ By default, sass is invoked with `--style=compressed --no-source-map`. You can adjust these options by overwriting `Rails.application.config.dartsass.build_options`.
41
+
42
+ ```ruby
43
+ # config/initializers/dartsass.rb
44
+ Rails.application.config.dartsass.build_options << " --quiet-deps"
45
+ ```
46
+
47
+ ## Importing assets from gems
48
+ `dartsass:build` includes application [assets paths](https://guides.rubyonrails.org/asset_pipeline.html#search-paths) as Sass [load paths](https://sass-lang.com/documentation/at-rules/use#load-paths). Assuming the gem has made assets visible to the Rails application, no additional configuration is required to use them.
49
+
50
+ ## Migrating from sass-rails
51
+
52
+ If you're migrating from [sass-rails](https://github.com/rails/sass-rails)
53
+ (applies to [sassc-rails](https://github.com/sass/sassc-rails) as well)
54
+ and want to switch to dartsass-rails, follow these instructions below:
55
+
56
+ 1. Remove the sass-rails gem from the Gemfile by running
57
+
58
+ ```
59
+ ./bin/bundle remove sass-rails
60
+ ```
61
+
62
+ 1. Install dartsass-rails by following the
63
+ [Installation](#installation) instructions above
64
+
65
+ 1. Remove any references to Sass files from the Sprockets manifest file:
66
+ `app/assets/config/manifest.js`
67
+
68
+ 1. In your continuous integration pipeline, before running any tests that
69
+ interact with the browser, make sure to build the Sass files by running:
70
+
71
+ ```
72
+ bundle exec rails dartsass:build
73
+ ```
74
+
75
+ ## Troubleshooting
76
+
77
+ Some common problems experienced by users:
78
+
79
+ ### LoadError: cannot load such file -- sassc
80
+
81
+ The reason for the above error is that Sprockets is trying to build Sass files
82
+ but the sass-rails or sassc-rails gems are not installed. This is expected,
83
+ since Dart Sass is used instead to build Sass files, and the solution is
84
+ to make sure that Sprockets is not building any Sass files.
85
+
86
+ There are three reasons why this error can occur:
87
+
88
+ #### Sass files are referenced in the Sprockets manifest file
89
+
90
+ If any Sass files are referenced in the Sprockets manifest file
91
+ (`app/assets/config/manifest.js`) Sprockets will try to build the Sass files and
92
+ fail.
93
+
94
+ ##### Solution
95
+
96
+ Remove any references to Sass files from the Sprockets manifest file. These are
97
+ now handled by Dart Sass. If you have more Sass files than `application.scss`,
98
+ make sure these are compiled by Dart Sass
99
+ (see [Configuring builds](#configuring-builds) above).
100
+
101
+ #### Running locally
102
+
103
+ If you receive this error when running the Rails server locally and have
104
+ already removed any references to Sass files from the Sprockets manifest file,
105
+ the Dart Sass process is most likely not running.
106
+
107
+ ##### Solution
108
+
109
+ Make sure the Dart Sass process is running by starting the Rails sever by
110
+ running: `./bin/dev`.
111
+
112
+ #### Running continuous integration pipelines
113
+
114
+ If you receive this error when running tests that interact with the browser in
115
+ a continuous integration pipeline and have removed any references to Sass files
116
+ from the Sprockets manifest file, the Sass files have most likely not been
117
+ built.
118
+
119
+ ##### Solution
120
+
121
+ Add a step to the continuous integration pipeline to build the Sass files with
122
+ the following command: `bundle exec rails dartsass:build`.
24
123
 
25
124
  ## Version
26
125
 
Binary file
Binary file
data/exe/dartsass CHANGED
@@ -2,17 +2,21 @@
2
2
  # because rubygems shims assume a gem's executables are Ruby
3
3
 
4
4
  require "shellwords"
5
+ require "rbconfig"
5
6
 
6
- os = Gem::Platform.local.os
7
+ system_config = RbConfig::CONFIG
8
+ platform_string = "#{system_config["host_cpu"]}-#{system_config["host_os"]}"
7
9
 
8
- exe_path =
9
- case os
10
- when "darwin" then File.join(__dir__, "darwin/sass")
11
- when "linux" then File.join(__dir__, "linux/sass")
12
- when "mingw32" then File.join(__dir__, "mingw32/sass.bat")
10
+ exe_path =
11
+ case platform_string
12
+ when /aarch64-linux/ then File.join(__dir__, "aarch64-linux/sass")
13
+ when /arm64-darwin/ then File.join(__dir__, "arm64-darwin/sass")
14
+ when /darwin/ then File.join(__dir__, "darwin/sass")
15
+ when /linux/ then File.join(__dir__, "linux/sass")
16
+ when /mswin|mingw|cygwin/ then File.join(__dir__, "mingw32/sass.bat")
13
17
  else
14
18
  STDERR.puts(<<~ERRMSG)
15
- ERROR: dartsass-rails does not support the #{os} operating system
19
+ ERROR: dartsass-rails does not support the #{platform_string} platform
16
20
  ERRMSG
17
21
  exit 1
18
22
  end
@@ -2,5 +2,8 @@ require "rails"
2
2
 
3
3
  module Dartsass
4
4
  class Engine < ::Rails::Engine
5
+ config.dartsass = ActiveSupport::OrderedOptions.new
6
+ config.dartsass.builds = { "application.scss" => "application.css" }
7
+ config.dartsass.build_options = "--style=compressed --no-source-map"
5
8
  end
6
9
  end
@@ -1,3 +1,3 @@
1
1
  module Dartsass
2
- VERSION = "0.1.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -5,6 +5,13 @@ say "Build into app/assets/builds"
5
5
  empty_directory "app/assets/builds"
6
6
  keep_file "app/assets/builds"
7
7
 
8
+ if (sprockets_manifest_path = Rails.root.join("app/assets/config/manifest.js")).exist?
9
+ append_to_file sprockets_manifest_path, %(//= link_tree ../builds\n)
10
+
11
+ say "Stop linking stylesheets automatically"
12
+ gsub_file "app/assets/config/manifest.js", "//= link_directory ../stylesheets .css\n", ""
13
+ end
14
+
8
15
  if Rails.root.join(".gitignore").exist?
9
16
  append_to_file(".gitignore", %(\n/app/assets/builds/*\n!/app/assets/builds/.keep\n))
10
17
  end
data/lib/tasks/build.rake CHANGED
@@ -1,14 +1,34 @@
1
- DARTSASS_COMPILE_COMMAND = "#{Pathname.new(__dir__).to_s}/../../exe/dartsass #{Rails.root.join("app/assets/stylesheets/application.scss")} #{Rails.root.join("app/assets/builds/application.scss")}"
1
+ EXEC_PATH = "#{Pathname.new(__dir__).to_s}/../../exe/dartsass"
2
+ CSS_LOAD_PATH = Rails.root.join("app/assets/stylesheets")
3
+ CSS_BUILD_PATH = Rails.root.join("app/assets/builds")
4
+
5
+ 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(" ")
9
+ end
10
+
11
+ def dartsass_build_options
12
+ Rails.application.config.dartsass.build_options
13
+ end
14
+
15
+ def dartsass_load_paths
16
+ [ CSS_LOAD_PATH ].concat(Rails.application.config.assets.paths).map { |path| "--load-path #{path}" }.join(" ")
17
+ end
18
+
19
+ def dartsass_compile_command
20
+ "#{EXEC_PATH} #{dartsass_build_options} #{dartsass_load_paths} #{dartsass_build_mapping}"
21
+ end
2
22
 
3
23
  namespace :dartsass do
4
24
  desc "Build your Dart Sass CSS"
5
- task :build do
6
- system DARTSASS_COMPILE_COMMAND
25
+ task build: :environment do
26
+ system dartsass_compile_command, exception: true
7
27
  end
8
28
 
9
29
  desc "Watch and build your Dart Sass CSS on file changes"
10
- task :watch do
11
- system "#{DARTSASS_COMPILE_COMMAND} -w"
30
+ task watch: :environment do
31
+ system "#{dartsass_compile_command} -w", exception: true
12
32
  end
13
33
  end
14
34
 
@@ -2,6 +2,7 @@ namespace :dartsass do
2
2
  desc "Remove CSS builds"
3
3
  task :clobber do
4
4
  rm_rf Dir["app/assets/builds/[^.]*.css"], verbose: false
5
+ rm_rf Dir["app/assets/builds/[^.]*.css\.map"], verbose: false
5
6
  end
6
7
  end
7
8
 
@@ -1,6 +1,6 @@
1
1
  namespace :dartsass do
2
2
  desc "Install Dart Sass into the app"
3
3
  task :install do
4
- system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/dartsass.rb", __dir__)}"
4
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/dartsass.rb", __dir__)}", exception: true
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dartsass-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-22 00:00:00.000000000 Z
11
+ date: 2022-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -35,6 +35,8 @@ files:
35
35
  - MIT-LICENSE
36
36
  - README.md
37
37
  - Rakefile
38
+ - exe/aarch64-linux/sass
39
+ - exe/arm64-darwin/sass
38
40
  - exe/dartsass
39
41
  - exe/darwin/LICENSE
40
42
  - exe/darwin/sass
@@ -77,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
79
  - !ruby/object:Gem::Version
78
80
  version: '0'
79
81
  requirements: []
80
- rubygems_version: 3.2.32
82
+ rubygems_version: 3.3.14
81
83
  signing_key:
82
84
  specification_version: 4
83
85
  summary: Integrate Dart Sass with the asset pipeline in Rails.