ruby_cms 0.2.0.3 → 0.2.0.4

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: 6812068b183da96c729d26ae664a39d599aea509a17a11ac0851b715c652cdcf
4
- data.tar.gz: b087d0fe4f6bb7af6db0aef47e195e7f4f179ab65476a2b6f1048bef514444ab
3
+ metadata.gz: 5cadc0fbcba9f0f9d51aba4ea436755d87c9a7a8dbc3652b35d97c0f4abc99ff
4
+ data.tar.gz: df887a8c0f1cb7dffe4ca59d6792502e87d2934c0f989e81db9c2ef222296add
5
5
  SHA512:
6
- metadata.gz: e0f9ca986cdc2d3c5caa5681261e49d015940c9e19be90406e341fffa215c5d1092ae9f47a30d64a39db9a221d2add4e6caac4eccaa3b79f9a8d3afd8e79343f
7
- data.tar.gz: 5043cc31c3d8adcd61480d3fafc64b851d468d57ee7daf6e251793150c663c4d6cae9c94e43a880bfbd940d414b38408a7d32148bcd63db18404cf8e8b579c07
6
+ metadata.gz: 448db9b93fb067ff98c219a893cbf5434fba9d443b666c0eb83b4d5662c57081895b74e762e03a6314c43fe966f59df33b0353690048600f1dcfc81cb679d67e
7
+ data.tar.gz: ee7378839a0e3a625ffb0b761a987f72b97d325ae6e724b7b7f48251f75b947468c6db783d7947c35f762f4a5f224788291a372e943591a19b03a6934f7546db
data/README.md CHANGED
@@ -493,27 +493,9 @@ rails ruby_cms:css:compile_gem
493
493
  ### Faster Docker Builds (`assets:precompile`)
494
494
 
495
495
  `assets:precompile` loads the Rails app in production mode and can be slow in Docker/Fly builds.
496
- RubyCMS skips non-asset runtime initializers during this phase (navigation registration,
496
+ RubyCMS now skips non-asset runtime initializers during this phase (navigation registration,
497
497
  dashboard registration, versioning hook, settings import, and permission seeding), which reduces
498
- precompile overhead. Detection uses `ARGV` (not only `$PROGRAM_NAME`) so it still applies when the
499
- Ruby program name is `ruby` instead of `rails`.
500
-
501
- **Tailwind CSS:** Do not add multiple `@source` globs that point at the same RubyCMS gem (e.g. both
502
- `../../../../gems/ruby_cms/...` and `/usr/local/bundle/.../ruby_cms-*`). That scans the engine twice
503
- and slows `tailwindcss:build` a lot. Instead, rely on [tailwindcss-rails engine support](https://github.com/rails/tailwindcss-rails#rails-engines-support-experimental):
504
-
505
- 1. RubyCMS ships `app/assets/tailwind/ruby_cms_engine/engine.css` with `@source` paths relative to the gem
506
- (the directory matches Rails’ `engine_name` for `RubyCms::Engine`, which is `ruby_cms_engine`).
507
- 2. `rails tailwindcss:engines` (run automatically before `tailwindcss:build`) generates
508
- `app/assets/builds/tailwind/ruby_cms_engine.css` in the host app.
509
- 3. In the host’s `app/assets/tailwind/application.css`, add **once**:
510
-
511
- ```css
512
- @import "../builds/tailwind/ruby_cms_engine";
513
- ```
514
-
515
- Place it next to your other `@import` lines (e.g. after `@import "tailwindcss";`). Remove any
516
- hand-written `@source` lines aimed at the RubyCMS gem.
498
+ precompile overhead.
517
499
 
518
500
  Recommended Docker layer order:
519
501
 
@@ -855,45 +855,18 @@ module RubyCms
855
855
  end.join("\n")
856
856
  end
857
857
 
858
- # Adds a single @import for tailwindcss-rails' engine shim (see gem app/assets/tailwind/ruby_cms_engine/engine.css).
859
- # Avoids duplicate @source globs to the gem, which makes tailwindcss:build much slower.
858
+ # Helper: add @source for RubyCMS views/components so Tailwind finds utility classes.
859
+ # Not a generator task.
860
860
  def add_ruby_cms_tailwind_source(tailwind_css_path)
861
861
  return unless tailwind_css_path.to_s.present? && File.exist?(tailwind_css_path)
862
862
 
863
863
  content = File.read(tailwind_css_path)
864
- return if content.match?(%r{builds/tailwind/ruby_cms_engine})
864
+ gem_source_lines = build_gem_source_lines(tailwind_css_path)
865
+ return if gem_source_lines.all? {|line| content.include?(line) }
865
866
 
866
- injection = +"\n/* RubyCMS: Tailwind content via tailwindcss-rails engine (see ruby_cms README). */\n"
867
- injection << "@import \"../builds/tailwind/ruby_cms_engine\";\n"
868
-
869
- inserted = inject_ruby_cms_engine_import_after_tailwind!(tailwind_css_path, content, injection)
870
- unless inserted
871
- inject_into_file tailwind_css_path.to_s, after: /\A/ do
872
- injection
873
- end
874
- end
875
-
876
- say "✓ Task tailwind/source: Added RubyCMS engine import to #{tailwind_css_path}.", :green
867
+ inject_tailwind_source(tailwind_css_path, content, gem_source_lines)
877
868
  rescue StandardError => e
878
- say "⚠ Task tailwind/source: Could not add engine import: #{e.message}. Add manually.", :yellow
879
- end
880
-
881
- def inject_ruby_cms_engine_import_after_tailwind!(tailwind_css_path, content, injection)
882
- patterns = [
883
- %(@import "tailwindcss";\n),
884
- %(@import "tailwindcss";),
885
- %(@import "tailwindcss"\n),
886
- %(@import "tailwindcss")
887
- ]
888
- patterns.each do |after_pattern|
889
- next unless content.include?(after_pattern)
890
-
891
- inject_into_file tailwind_css_path.to_s, after: after_pattern do
892
- injection
893
- end
894
- return true
895
- end
896
- false
869
+ say "⚠ Task tailwind/source: Could not add @source: #{e.message}. Add manually.", :yellow
897
870
  end
898
871
 
899
872
  # Tailwind v3 support (tailwind.config.js content array)
@@ -932,6 +905,65 @@ module RubyCms
932
905
  ]
933
906
  end
934
907
 
908
+ def build_gem_source_lines(tailwind_css_path)
909
+ css_dir = Pathname.new(tailwind_css_path).dirname
910
+ gem_views = path_relative_to_css_or_absolute(RubyCms::Engine.root.join("app/views"),
911
+ css_dir)
912
+ gem_components = path_relative_to_css_or_absolute(
913
+ RubyCms::Engine.root.join("app/components"), css_dir
914
+ )
915
+ [
916
+ %(@source "#{gem_views}/**/*.erb";),
917
+ %(@source "#{gem_components}/**/*.rb";)
918
+ ]
919
+ end
920
+
921
+ def path_relative_to_css_or_absolute(target_path, css_dir)
922
+ Pathname.new(target_path).relative_path_from(css_dir).to_s
923
+ rescue ArgumentError
924
+ # Different mount/volume: fall back to absolute path.
925
+ Pathname.new(target_path).to_s
926
+ end
927
+
928
+ def inject_tailwind_source(tailwind_css_path, content, gem_source_lines)
929
+ to_inject = build_tailwind_source_injection(gem_source_lines)
930
+ inserted = try_insert_after_patterns?(tailwind_css_path, content, to_inject)
931
+ inject_at_start(tailwind_css_path, to_inject) unless inserted
932
+ say "✓ Task tailwind/source: Added @source for RubyCMS views/components to " \
933
+ "tailwind/application.css.",
934
+ :green
935
+ end
936
+
937
+ def build_tailwind_source_injection(gem_source_lines)
938
+ to_inject = +"\n/* Include RubyCMS views/components so Tailwind finds utility classes. */\n"
939
+ Array(gem_source_lines).each {|line| to_inject << line << "\n" }
940
+ to_inject << "\n"
941
+ to_inject
942
+ end
943
+
944
+ def try_insert_after_patterns?(tailwind_css_path, content, to_inject)
945
+ patterns = [
946
+ %(@import "tailwindcss";\n),
947
+ %(@import "tailwindcss";),
948
+ %(@import "tailwindcss"\n),
949
+ %(@import "tailwindcss")
950
+ ]
951
+ patterns.each do |after_pattern|
952
+ next unless content.include?(after_pattern)
953
+
954
+ inject_into_file tailwind_css_path.to_s, after: after_pattern do
955
+ to_inject
956
+ end
957
+ return true
958
+ end
959
+ false
960
+ end
961
+
962
+ def inject_at_start(tailwind_css_path, to_inject)
963
+ inject_into_file tailwind_css_path.to_s, after: /\A/ do
964
+ to_inject
965
+ end
966
+ end
935
967
  end
936
968
 
937
969
  def run_migrate
@@ -100,8 +100,7 @@ module RubyCms
100
100
  # For importmap: ensure engine's importmap is loaded
101
101
  if app.config.respond_to?(:importmap)
102
102
  app.config.importmap.paths << config.root.join("config/importmap.rb")
103
- # Only sweep the engine's Stimulus tree (not the whole app/javascript tree)
104
- app.config.importmap.cache_sweepers << config.root.join("app/javascript/controllers/ruby_cms")
103
+ app.config.importmap.cache_sweepers << config.root.join("app/javascript")
105
104
  end
106
105
  end
107
106
 
@@ -263,18 +262,12 @@ module RubyCms
263
262
  end
264
263
  end
265
264
 
266
- # True during asset pipeline tasks so we skip DB-heavy initializers (permissions, settings import).
267
- # Detect by ARGV first: $PROGRAM_NAME is often "ruby" when using `ruby bin/rails`, which would
268
- # miss the old rake/rails basename check; tailwindcss:build runs as a prerequisite of
269
- # assets:precompile and keeps the same ARGV, but a standalone `rails tailwindcss:build` must match too.
270
265
  def self.assets_precompile_phase?
271
- argv = Array(ARGV).map(&:to_s)
272
- return true if argv.include?("assets:precompile")
273
- return true if argv.any? {|a| a.start_with?("tailwindcss:") }
274
- return true if argv.include?("propshaft:compile")
275
-
276
266
  command = File.basename($PROGRAM_NAME.to_s)
277
- (command == "rake" || command == "rails") && argv.include?("assets:precompile")
267
+ rake_assets_precompile = command == "rake" && ARGV.include?("assets:precompile")
268
+ rails_assets_precompile = command == "rails" && ARGV.include?("assets:precompile")
269
+
270
+ rake_assets_precompile || rails_assets_precompile
278
271
  end
279
272
  end
280
273
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyCms
4
- VERSION = "0.2.0.3"
4
+ VERSION = "0.2.0.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.3
4
+ version: 0.2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Codebyjob