cssbundling-rails 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 643412ab70b4a60ccf019381db175e18fb2e779c34439cf89c19d0caa3a8dfd5
4
- data.tar.gz: 80888732e4252b4e59ef90843010ef5dd6cf3e395c72ea8d2539c27557752dec
3
+ metadata.gz: 1de04a37474ee74462c81c8c531c659bc5566aa8e19f4a7697e56d09f243c8c2
4
+ data.tar.gz: 9f958afff8e9068ad47291f2285eba9c28032785ff64a70ac66b11b8483cb3bc
5
5
  SHA512:
6
- metadata.gz: a14d2636c1b596f6cd4106c9214b1963f1f5e65329b3beaa27557de5dbfa6e57dcb9c688130e11ce75fc68a823fad74fddc3e3a14557e1fa6d3e663dc22a05a1
7
- data.tar.gz: 687cd595a551a1feef7279fe59ff8a6a4c623e00c35b33aeb4a3dc13259f89f548e8a6ece4d1c7d727cedb71dd3feb88f4a8577278eba825f1074d6606286185
6
+ metadata.gz: 54cd75ab9d1f2fa908fdeb14e9385ac77543af91d7757b0dc0b3ad4378e0b1764cfbf0b4d359a1eed5e8f28a9ae8b21619845dcaa28d7d6c6bd5341ea4534214
7
+ data.tar.gz: 55bb55f73f38a2ff2b39431ba20417797245cba519f3488861f90d5731ec7e6aeb71bd8b78040d5490ea2a177604fea5477d452e6b6dd364332dc4b8cb17e504
data/README.md CHANGED
@@ -43,6 +43,15 @@ Some CSS packages use new CSS features that are not supported by the default Sas
43
43
 
44
44
  A common issue is that your repository does not contain the output directory used by the build commands. You must have `app/assets/builds` available. Add the directory with a `.gitkeep` file, and you'll ensure it's available in production.
45
45
 
46
+ ### How do I avoid `ActionView::Template::Error: Error: Function rgb is missing argument $green`?
47
+
48
+ This might happen if your Gemfile.lock contains the legacy `sassc-rails`, which might be need while progressively migrating your project, or which might be a transitive dependency of a gem your project depends on and over which you have no control. In this case, prevent Sprockets from bundling the CSS on top of the bundling already performed by this gem. Make sure do this for all environments, not only production, otherwise your test suite may fail.
49
+
50
+ ```
51
+ # config/initializers/assets.rb
52
+ Rails.application.config.assets.css_compressor = nil
53
+ ```
54
+
46
55
  ### Why isn't Rails using my updated css files?
47
56
 
48
57
  Watch out - if you precompile your files locally, those will be served over the dynamically created ones you expect. The solution:
@@ -51,6 +60,15 @@ Watch out - if you precompile your files locally, those will be served over the
51
60
  rails assets:clobber
52
61
  ```
53
62
 
63
+ ### How do I include 3rd party stylesheets from `node_modules` in my bundle?
64
+
65
+ Use an `@import` statement and path to a specific stylesheet, omitting the `node_modules/` segment and the file's extension. For example:
66
+
67
+ ```scss
68
+ /* Desired file is at at node_modules/select2/dist/css/select2.css */
69
+ @import "select2/dist/css/select2";
70
+ ```
71
+
54
72
  ## License
55
73
 
56
74
  CSS Bundling for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,3 +1,3 @@
1
1
  module Cssbundling
2
- VERSION = "1.3.2"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -1,6 +1,8 @@
1
1
  require_relative "../helpers"
2
2
  self.extend Helpers
3
3
 
4
+ apply "#{__dir__}/../install.rb"
5
+
4
6
  say "Install Bootstrap with Bootstrap Icons, Popperjs/core and Autoprefixer"
5
7
  copy_file "#{__dir__}/application.bootstrap.scss",
6
8
  "app/assets/stylesheets/application.bootstrap.scss"
@@ -19,10 +21,23 @@ else
19
21
  say %(Add import * as bootstrap from "bootstrap" to your entry point JavaScript file), :red
20
22
  end
21
23
 
24
+ if Rails.root.join("config/importmap.rb").exist?
25
+ say "Pin Bootstrap"
26
+ append_to_file "config/importmap.rb", %(pin "bootstrap", to: "bootstrap.min.js"\n)
27
+
28
+ inject_into_file "config/initializers/assets.rb", after: /.*Rails.application.config.assets.paths.*\n/ do
29
+ <<~RUBY
30
+ Rails.application.config.assets.paths << Rails.root.join("node_modules/bootstrap/dist/js")
31
+ RUBY
32
+ end
33
+
34
+ append_to_file "config/initializers/assets.rb", %(Rails.application.config.assets.precompile << "bootstrap.min.js")
35
+ end
36
+
22
37
  add_package_json_script("build:css:compile", "sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules")
23
38
  add_package_json_script("build:css:prefix", "postcss ./app/assets/builds/application.css --use=autoprefixer --output=./app/assets/builds/application.css")
24
39
  add_package_json_script("build:css", "#{bundler_run_cmd} build:css:compile && #{bundler_run_cmd} build:css:prefix")
25
- add_package_json_script("watch:css", "nodemon --watch ./app/assets/stylesheets/ --ext scss --exec \"#{bundler_run_cmd} build:css\"", false)
40
+ add_package_json_script("watch:css", "nodemon --watch ./app/assets/stylesheets/ --ext scss --exec \\\"#{bundler_run_cmd} build:css\\\"", false)
26
41
 
27
42
  gsub_file "Procfile.dev", "build:css --watch", "watch:css"
28
43
 
@@ -1,6 +1,8 @@
1
1
  require_relative "../helpers"
2
2
  self.extend Helpers
3
3
 
4
+ apply "#{__dir__}/../install.rb"
5
+
4
6
  say "Install Bulma"
5
7
  copy_file "#{__dir__}/application.bulma.scss",
6
8
  "app/assets/stylesheets/application.bulma.scss"
data/lib/install/dev CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env sh
2
2
 
3
- if ! gem list foreman -i --silent; then
3
+ if gem list --no-installed --exact --silent foreman; then
4
4
  echo "Installing foreman..."
5
5
  gem install foreman
6
6
  fi
@@ -21,7 +21,7 @@ module Helpers
21
21
  if using_bun?
22
22
  package_json = JSON.parse(File.read("package.json"))
23
23
  package_json["scripts"] ||= {}
24
- package_json["scripts"][name] = script
24
+ package_json["scripts"][name] = script.gsub('\\"', '"')
25
25
  File.write("package.json", JSON.pretty_generate(package_json))
26
26
  run %(bun run #{name}) if run_script
27
27
  else
@@ -1,6 +1,8 @@
1
1
  require_relative "../helpers"
2
2
  self.extend Helpers
3
3
 
4
+ apply "#{__dir__}/../install.rb"
5
+
4
6
  say "Install PostCSS w/ nesting and autoprefixer"
5
7
  copy_file "#{__dir__}/postcss.config.js", "postcss.config.js"
6
8
  copy_file "#{__dir__}/application.postcss.css", "app/assets/stylesheets/application.postcss.css"
@@ -1,6 +1,8 @@
1
1
  require_relative "../helpers"
2
2
  self.extend Helpers
3
3
 
4
+ apply "#{__dir__}/../install.rb"
5
+
4
6
  say "Install Sass"
5
7
  copy_file "#{__dir__}/application.sass.scss", "app/assets/stylesheets/application.sass.scss"
6
8
  run "#{bundler_cmd} add sass"
@@ -1,6 +1,8 @@
1
1
  require_relative "../helpers"
2
2
  self.extend Helpers
3
3
 
4
+ apply "#{__dir__}/../install.rb"
5
+
4
6
  say "Install Tailwind (+PostCSS w/ autoprefixer)"
5
7
  copy_file "#{__dir__}/tailwind.config.js", "tailwind.config.js"
6
8
  copy_file "#{__dir__}/application.tailwind.css", "app/assets/stylesheets/application.tailwind.css"
@@ -22,15 +22,36 @@ module Cssbundling
22
22
  extend self
23
23
 
24
24
  def install_command
25
- return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
26
- return "yarn install" if File.exist?('yarn.lock') || tool_exists?('yarn')
27
- raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies"
25
+ case tool
26
+ when :bun then "bun install"
27
+ when :yarn then "yarn install"
28
+ when :pnpm then "pnpm install"
29
+ when :npm then "npm install"
30
+ else raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies"
31
+ end
28
32
  end
29
33
 
30
34
  def build_command
31
- return "bun run build:css" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
32
- return "yarn build:css" if File.exist?('yarn.lock') || tool_exists?('yarn')
33
- raise "cssbundling-rails: No suitable tool found for building CSS"
35
+ case tool
36
+ when :bun then "bun run build:css"
37
+ when :yarn then "yarn build:css"
38
+ when :pnpm then "pnpm build:css"
39
+ when :npm then "npm run build:css"
40
+ else raise "cssbundling-rails: No suitable tool found for building CSS"
41
+ end
42
+ end
43
+
44
+ def tool
45
+ case
46
+ when File.exist?('bun.lockb') then :bun
47
+ when File.exist?('yarn.lock') then :yarn
48
+ when File.exist?('pnpm-lock.yaml') then :pnpm
49
+ when File.exist?('package-lock.json') then :npm
50
+ when tool_exists?('bun') then :bun
51
+ when tool_exists?('yarn') then :yarn
52
+ when tool_exists?('pnpm') then :pnpm
53
+ when tool_exists?('npm') then :npm
54
+ end
34
55
  end
35
56
 
36
57
  def tool_exists?(tool)
@@ -1,32 +1,27 @@
1
1
  namespace :css do
2
2
  namespace :install do
3
- desc "Install shared elements for all bundlers"
4
- task :shared do
5
- system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/install.rb", __dir__)}"
6
- end
7
-
8
3
  desc "Install Tailwind"
9
- task tailwind: "css:install:shared" do
4
+ task :tailwind do
10
5
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/tailwind/install.rb", __dir__)}"
11
6
  end
12
7
 
13
8
  desc "Install PostCSS"
14
- task postcss: "css:install:shared" do
9
+ task :postcss do
15
10
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/postcss/install.rb", __dir__)}"
16
11
  end
17
12
 
18
13
  desc "Install Sass"
19
- task sass: "css:install:shared" do
14
+ task :sass do
20
15
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/sass/install.rb", __dir__)}"
21
16
  end
22
17
 
23
18
  desc "Install Bootstrap"
24
- task bootstrap: "css:install:shared" do
19
+ task :bootstrap do
25
20
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bootstrap/install.rb", __dir__)}"
26
21
  end
27
22
 
28
23
  desc "Install Bulma"
29
- task bulma: "css:install:shared" do
24
+ task :bulma do
30
25
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bulma/install.rb", __dir__)}"
31
26
  end
32
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cssbundling-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-09-14 00:00:00.000000000 Z
12
+ date: 2024-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.4.10
80
+ rubygems_version: 3.4.20
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Bundle and process CSS with Tailwind, Bootstrap, PostCSS, Sass in Rails via