frozen_rails 0.0.9 → 0.0.11

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: 0dbddd002441102ad2a74ae55e1b633f623e83a0abb322143b456152d79de316
4
- data.tar.gz: ab870d518d1c2f15eec2c9e572599e19121c1f1b9e4c7aa5fbe389d180d15d35
3
+ metadata.gz: 58772e38e8d884d37dadb93b5d17f1dfb1f1cdbbcfa61091bb933b5538229dd2
4
+ data.tar.gz: fd9c6d0fd9650da0e61b1aaf9271e49d67cb32017f3491dbe8fd5be5a41e8f73
5
5
  SHA512:
6
- metadata.gz: 27f832636f1bd87883ba1dec5ede4fb76c7de52f7304cb60177d55fd293bf6e4ded40a3edeefeb4368556cf8f6a07e0118a8a88eea658747335c9f888f0bb6c9
7
- data.tar.gz: bcc50684ee328cea03c251874882c1f80efe5e8b74fc377d1b8749371e6980b0bea344f22f62955b4ce0f0b55d6ec4d6a6073db3239af379705ed956a9be98c3
6
+ metadata.gz: e6341d4b1aa394418050513f9e91d770cebdf6943151b5f53c5a37256e55717e859f4eb5e3d674ba91a3f28811bedc5cefbea27c3fafaed1d1b01eaed4dd8e2b
7
+ data.tar.gz: 0b9481810c49f22d69b15aafc93f510a5d8341c25e9b9f7e11f0e6333b67868d363b453aa61b3b0b2c997c2a1f8b81c9097a63533509bd633198cf38526e386a
data/README.md CHANGED
@@ -16,7 +16,7 @@ bundle add frozen_rails
16
16
  ## Prerequisites
17
17
 
18
18
  - Ruby with `bundler` installed
19
- - nvm
19
+ - nvm (`node` and `yarn` must be on your `PATH`)
20
20
 
21
21
  ## Usage
22
22
 
@@ -2,6 +2,7 @@ require "rails/generators"
2
2
  require "frozen_rails/appendable"
3
3
  require "frozen_rails/bundleable"
4
4
  require "frozen_rails/copyable"
5
+ require "frozen_rails/nodeable"
5
6
  require "frozen_rails/taggable"
6
7
 
7
8
  module FrozenRails
@@ -9,6 +10,7 @@ module FrozenRails
9
10
  include Appendable
10
11
  include Bundleable
11
12
  include Copyable
13
+ include Nodeable
12
14
  include Taggable
13
15
  end
14
16
  end
@@ -0,0 +1,41 @@
1
+ module Nodeable
2
+ extend ActiveSupport::Concern
3
+
4
+ REQUIRED_EXECUTABLES = %w[ node yarn ].freeze
5
+
6
+ private
7
+
8
+ def require_js_toolchain!
9
+ missing = REQUIRED_EXECUTABLES.reject { |executable| available?(executable) }
10
+ return if missing.empty?
11
+
12
+ raise Thor::Error, <<~MSG
13
+ frozen_rails could not run #{missing.to_sentence}.
14
+
15
+ node and yarn are provided by nvm, which is only active in a shell that has
16
+ sourced it. Activate it, then run this generator again:
17
+
18
+ #{activation_hint(missing).indent(4)}
19
+ MSG
20
+ end
21
+
22
+ # `system` returns nil when the command does not exist and false when it exits non-zero
23
+ def available?(executable)
24
+ system(executable, "--version", out: File::NULL, err: File::NULL)
25
+ end
26
+
27
+ def activation_hint(missing)
28
+ commands = [ nvm_use_command ]
29
+ commands << "npm install -g yarn" if missing.include?("yarn")
30
+ commands << "bin/rails generate #{self.class.namespace}"
31
+ commands.join("\n")
32
+ end
33
+
34
+ def nvm_use_command
35
+ # nvm picks the version out of .nvmrc by itself
36
+ return "nvm use" if File.exist?(".nvmrc")
37
+
38
+ version = File.read(".node-version").strip if File.exist?(".node-version")
39
+ "nvm use #{version || '--lts'}"
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module FrozenRails # :nodoc:
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -15,9 +15,9 @@ module Frozen
15
15
  gem "friendly_id"
16
16
  RUBY
17
17
 
18
- add_frozen_gems <<~RUBY, env: "development"
18
+ add_frozen_gems <<~RUBY, env: "local"
19
19
  # frozen:db
20
- gem "avo", ">= 3.2"
20
+ gem "avo", ">= 3.2", "< 4"
21
21
  RUBY
22
22
  end
23
23
 
@@ -28,7 +28,7 @@ module Frozen
28
28
  def add_routes
29
29
  append_to_routes <<~RUBY
30
30
  # frozen:db
31
- if Rails.env.development?
31
+ if defined?(Avo)
32
32
  mount_avo at: "/avo"
33
33
  end
34
34
  RUBY
@@ -38,6 +38,7 @@ module Frozen
38
38
  copy_file "database.yml", "config/database.yml", force: true
39
39
  copy_directory "initializers", "config/initializers"
40
40
  copy_directory "lib", "lib"
41
+ copy_file "avo_resource_test.rb", "test/models/avo_resource_test.rb"
41
42
  end
42
43
 
43
44
  def configure_application
@@ -96,7 +97,7 @@ module Frozen
96
97
  rails_command "g avo:install"
97
98
 
98
99
  prepend_to_file "config/initializers/avo.rb", <<~RUBY + "\n"
99
- if Rails.env.development?
100
+ if defined?(Avo)
100
101
  # Allow moving Avo controllers into `app/avo/controllers/`
101
102
  Rails.autoloaders.main.collapse(
102
103
  Rails.root.join("app/avo/controllers")
@@ -5,9 +5,6 @@ module Frozen
5
5
  class MdGenerator < FrozenRails::Generator
6
6
  source_root File.expand_path("templates/md", __dir__)
7
7
 
8
- # When absent, the generator will prompt interactively (unless running non-interactively).
9
- class_option :rouge_theme, type: :string, desc: "Rouge theme to install (runs non-interactive if provided)"
10
-
11
8
  desc "Set up markdown-powered content with Decant, kramdown, ERB processing and Rouge highlighting"
12
9
 
13
10
  def add_gems
@@ -59,28 +56,7 @@ module Frozen
59
56
  end
60
57
 
61
58
  def generate_rouge_css_stylesheet
62
- theme = options[:rouge_theme]
63
-
64
- if theme.blank? && behavior == :invoke && $stdin.tty?
65
- # Run in subshell so we pick up newly installed gem without needing to require it in the current process.
66
- themes = `bundle exec ruby -e "require 'rouge'; puts Rouge::Theme.registry.keys.sort"`.split("\n")
67
-
68
- say_status :info, "Available Rouge themes (#{themes.size}):", :blue
69
- themes.each_with_index { |t, i| say " #{i + 1}. #{t}" }
70
-
71
- answer = ask("Choose a theme (name or number) [github]")
72
-
73
- theme = if /^\d+$/.match?(answer)
74
- themes[answer.to_i - 1]
75
- else
76
- answer.presence
77
- end
78
- end
79
-
80
- theme ||= "github"
81
-
82
- say_status :info, "Generating Rouge CSS for theme #{theme}", :blue
83
- run "rougify style #{theme} > app/assets/rouge/rouge.css"
59
+ run "rougify style gruvbox.dark > app/assets/rouge/rouge.css"
84
60
  end
85
61
  end
86
62
  end
@@ -4,10 +4,17 @@ require "frozen_rails/taggable"
4
4
  module Frozen
5
5
  module Generators
6
6
  class RailsGenerator < Rails::Generators::Base
7
+ include Nodeable
7
8
  include Taggable
8
9
 
9
10
  desc "Run all frozen setup generators (md, ssg, db, ui, seo)"
10
11
 
12
+ def check_prerequisites
13
+ in_root do
14
+ require_js_toolchain!
15
+ end
16
+ end
17
+
11
18
  def run_all
12
19
  say_status :info, "invoking frozen:md"
13
20
  invoke "frozen:md", [], cleanup_frozen_tags: false
@@ -0,0 +1,39 @@
1
+ require "frozen_rails/generator"
2
+
3
+ module Frozen
4
+ module Generators
5
+ class RougeGenerator < FrozenRails::Generator
6
+ source_root File.expand_path("templates/rouge", __dir__)
7
+
8
+ # When absent, the generator will prompt interactively (unless running non-interactively).
9
+ class_option :rouge_theme, type: :string, desc: "Rouge theme to install (runs non-interactive if provided)"
10
+
11
+ desc "Generate the chosen rouge theme in the correct location"
12
+
13
+ def generate_rouge_css_stylesheet
14
+ theme = options[:rouge_theme]
15
+
16
+ if theme.blank? && behavior == :invoke && $stdin.tty?
17
+ # Run in subshell so we pick up newly installed gem without needing to require it in the current process.
18
+ themes = `bundle exec ruby -e "require 'rouge'; puts Rouge::Theme.registry.keys.sort"`.split("\n")
19
+
20
+ say_status :info, "Available Rouge themes (#{themes.size}):", :blue
21
+ themes.each_with_index { |t, i| say " #{i + 1}. #{t}" }
22
+
23
+ answer = ask("Choose a theme (name or number) [github]")
24
+
25
+ theme = if /^\d+$/.match?(answer)
26
+ themes[answer.to_i - 1]
27
+ else
28
+ answer.presence
29
+ end
30
+ end
31
+
32
+ theme ||= "github"
33
+
34
+ say_status :info, "Generating Rouge CSS for theme #{theme}", :blue
35
+ run "rougify style #{theme} > app/assets/rouge/rouge.css"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -21,6 +21,12 @@ module Frozen
21
21
  def run_parklife_init
22
22
  run "bundle exec parklife init --rails --github-pages"
23
23
  append_to_file ".gitignore", "# frozen:ssg\n/build\n"
24
+
25
+ insert_into_file ".github/workflows/parklife.yml", <<YAML, before: "\n - uses: actions/checkout@v4"
26
+
27
+ - name: Install packages
28
+ run: sudo apt-get update && sudo apt-get install --no-install-recommends -y libvips
29
+ YAML
24
30
  end
25
31
 
26
32
  def setup_gitlab_pages
@@ -0,0 +1,18 @@
1
+ require "test_helper"
2
+
3
+ class AvoResourcesTest < ActiveSupport::TestCase
4
+ test "all fields exist" do
5
+ Rails.application.eager_load!
6
+
7
+ Avo::BaseResource.descendants.each do |resource|
8
+ model = resource.model_class
9
+ resource_instance = resource.new(view: :index).detect_fields
10
+
11
+ resource_instance.get_field_definitions.each do |field|
12
+ attr = field.id
13
+
14
+ assert(model.attribute_names.include?(attr.to_s) || model.method_defined?(attr), "Invalid field #{attr} on #{resource}")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,7 @@
1
1
  StaticDb.configure do |config|
2
- config.fixture_path = Rails.root.join("content", "data")
2
+ config.static_db_path = Rails.root.join("content", "data")
3
+
4
+ # Selectively activate loading and dumping. Active by default. Set to any other value to disable.
5
+ config.load = ENV["STATIC_DB"].in? [ "load", nil, "on", "true", "1" ]
6
+ config.dump = ENV["STATIC_DB"].in? [ "dump", nil, "on", "true", "1" ]
3
7
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  <h1><%= human_name.pluralize %></h1>
4
4
 
5
- <%% if Rails.env.development? %>
5
+ <%% if defined?(Avo) %>
6
6
  <p>
7
7
  <%%= link_to "✏️", avo.resources_<%= index_helper(type: :path) %>, "up-follow": false %>
8
8
  </p>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <%%= render @<%= singular_table_name %> %>
4
4
 
5
- <%% if Rails.env.development? %>
5
+ <%% if defined?(Avo) %>
6
6
  <p>
7
7
  <%%= link_to "✏️", avo.resources_<%= show_helper(type: :path) %>, "up-follow": false %>
8
8
  </p>
@@ -12,7 +12,7 @@ build:
12
12
  stage: build
13
13
  script:
14
14
  - apt-get update -yqqq
15
- - apt-get install -y nodejs
15
+ - apt-get install -y nodejs npm libvips
16
16
  - bundle config set path 'vendor'
17
17
  - bundle install
18
18
  - bin/static-build
@@ -17,12 +17,8 @@
17
17
  <link rel="icon" href="/icon.png" type="image/png">
18
18
  <link rel="icon" href="/icon.svg" type="image/svg+xml">
19
19
  <link rel="apple-touch-icon" href="/icon.png">
20
- <%# Use propshaft in development and precompiled_assets in production. Very brittle. %>
21
- <% if Rails.env.development? %>
22
- <%= stylesheet_link_tag :app %>
23
- <% else %>
24
- <%= stylesheet_link_tag "application" %>
25
- <% end %>
20
+
21
+ <%= stylesheet_link_tag "application" %>
26
22
  <%= javascript_include_tag "application", type: "module", defer: true %>
27
23
  </head>
28
24
 
@@ -24,14 +24,18 @@ async function handleErrors(errors) {
24
24
  }
25
25
  }
26
26
 
27
+ let entryPoints
28
+
29
+ if (railsEnv === 'production') {
30
+ entryPoints = ['application.js', 'static.js']
31
+ } else {
32
+ entryPoints = ['application.js', 'static.js', 'jasmine.js']
33
+ }
34
+
27
35
  const config = {
28
- entryPoints: [
29
- 'application.js',
30
- 'jasmine.js',
31
- 'static.js'
32
- ],
36
+ entryPoints,
33
37
  bundle: true,
34
- sourcemap: true,
38
+ sourcemap: railsEnv !== 'production',
35
39
  format: 'esm',
36
40
  outdir,
37
41
  absWorkingDir: path.join(process.cwd(), 'app/assets'),
@@ -4,14 +4,14 @@
4
4
  <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0">
5
5
  <meta http-equiv="Pragma" content="no-cache">
6
6
  <meta http-equiv="Expires" content="0">
7
- <%= stylesheet_link_tag 'jasmine' %>
8
7
 
9
- <!-- Referencing npm assets from HTML is currently broken. -->
10
- <!-- <link href="<%#= asset_path('jasmine_favicon.png') %>" rel="icon" type="image/png"> -->
8
+ <link href="<%= asset_path("jasmine-core/images/jasmine_favicon.png") %>" rel="icon" type="image/png">
9
+
10
+ <%= stylesheet_link_tag "jasmine" %>
11
+ <%= javascript_include_tag "jasmine", defer: true %>
11
12
  </head>
12
13
 
13
14
  <body>
14
15
  <%= yield %>
15
- <%= javascript_include_tag 'jasmine' %>
16
16
  </body>
17
17
  </html>
@@ -47,10 +47,10 @@ class ComponentGenerator < Rails::Generators::NamedBase
47
47
  end
48
48
 
49
49
  def bem_selectors
50
- base = file_path.gsub("/", "---").dasherize
50
+ base = file_path.gsub("/", "---").dasherize.prepend(".")
51
51
  [
52
52
  base,
53
- *css_attributes.map { |attr| ".#{base}--#{attr}" }
53
+ *css_attributes.map { |attr| "#{base}--#{attr}" }
54
54
  ]
55
55
  end
56
56
 
@@ -4,12 +4,7 @@
4
4
  <title>Component Preview</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
 
7
- <%# Use propshaft in development and precompiled_assets in production. Very brittle. %>
8
- <% if Rails.env.development? %>
9
- <%= stylesheet_link_tag :app, media: 'all' %>
10
- <% else %>
11
- <%= stylesheet_link_tag "application", media: 'all' %>
12
- <% end %>
7
+ <%= stylesheet_link_tag "application" %>
13
8
  <%= javascript_include_tag 'application' %>
14
9
  </head>
15
10
 
@@ -7,6 +7,12 @@ module Frozen
7
7
 
8
8
  desc "Wire up UI helpers: classless CSS, importmap example, Hotwire Spark, Stimulus controller, and related configuration"
9
9
 
10
+ def check_prerequisites
11
+ in_root do
12
+ require_js_toolchain!
13
+ end
14
+ end
15
+
10
16
  def add_gems
11
17
  add_frozen_gems <<~RUBY
12
18
  # frozen:ui
@@ -19,7 +25,6 @@ module Frozen
19
25
  add_frozen_gems <<~RUBY, env: "development"
20
26
  # frozen:ui
21
27
  gem "listen"
22
- gem "propshaft"
23
28
  RUBY
24
29
 
25
30
  add_frozen_gems <<~RUBY, env: "local"
@@ -32,28 +37,25 @@ module Frozen
32
37
  bundle!
33
38
  end
34
39
 
35
- def prepare_js_environment
40
+ def symlink_node_version
36
41
  in_root do
37
- run "mv .node-version .nvmrc"
38
- run "nvm use"
39
- run "nvm install"
40
- run "npm install -g yarn"
42
+ create_link ".nvmrc", ".node-version" if File.exist?(".node-version")
41
43
  end
42
44
  end
43
45
 
44
46
  def configure_esbuild
45
47
  in_root do
46
- run "yarn add --dev esbuild-plugin-import-glob esbuild-plugin-text-replace esbuild-manifest-plugin"
48
+ run "yarn add --dev esbuild-plugin-import-glob esbuild-plugin-text-replace esbuild-manifest-plugin", abort_on_failure: true
47
49
  copy_file "esbuild.config.js"
48
- run 'npm pkg set type="module"'
49
- run 'npm pkg set scripts.build="node esbuild.config.js"'
50
+ run 'npm pkg set type="module"', abort_on_failure: true
51
+ run 'npm pkg set scripts.build="node esbuild.config.js"', abort_on_failure: true
50
52
  end
51
53
  end
52
54
 
53
55
  def add_js_dependencies
54
56
  in_root do
55
- run "yarn add unpoly"
56
- run "yarn add --dev jasmine jasmine_dom_matchers"
57
+ run "yarn add unpoly", abort_on_failure: true
58
+ run "yarn add --dev jasmine jasmine_dom_matchers", abort_on_failure: true
57
59
  end
58
60
  end
59
61
 
@@ -80,7 +82,8 @@ module Frozen
80
82
  FileUtils.move("content/pages/rails-static", "app/assets/images/pages/rails-static")
81
83
  end
82
84
  comment_lines "config/application.rb", /config\.assets\.paths/
83
- prepend_to_file "config/initializers/assets.rb", "return unless Rails.env.development?\n"
85
+ comment_lines "config/environments/development.rb", /config\.assets\.quiet/
86
+ remove_file "config/initializers/assets.rb"
84
87
 
85
88
  insert_into_file ".github/workflows/ci.yml", <<YAML1, before: "\n - name: Run tests", force: true
86
89
 
@@ -132,8 +135,6 @@ YAML4
132
135
  config.view_component.generate.locale = true
133
136
  config.view_component.previews.default_layout = "component_preview"
134
137
  config.asset_path = "/assets"
135
- # Use propshaft in development and precompiled_assets in production. Very brittle.
136
- config.assets.paths << Rails.root.join("app/assets") if Rails.env.development?
137
138
  RUBY
138
139
  end
139
140
 
@@ -172,8 +173,7 @@ YAML4
172
173
 
173
174
  def copy_demo_component
174
175
  copy_directory "demo_component", "app/components"
175
- empty_directory "test/components"
176
- copy_directory "demo_component_test", "test/components"
176
+ copy_directory "demo_component_tests", "test/components"
177
177
  end
178
178
  end
179
179
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frozen_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaus Weidinger
@@ -39,13 +39,16 @@ files:
39
39
  - lib/frozen_rails/bundleable.rb
40
40
  - lib/frozen_rails/copyable.rb
41
41
  - lib/frozen_rails/generator.rb
42
+ - lib/frozen_rails/nodeable.rb
42
43
  - lib/frozen_rails/taggable.rb
43
44
  - lib/frozen_rails/version.rb
44
45
  - lib/generators/frozen/db_generator.rb
45
46
  - lib/generators/frozen/md_generator.rb
46
47
  - lib/generators/frozen/rails_generator.rb
48
+ - lib/generators/frozen/rouge_generator.rb
47
49
  - lib/generators/frozen/seo_generator.rb
48
50
  - lib/generators/frozen/ssg_generator.rb
51
+ - lib/generators/frozen/templates/db/avo_resource_test.rb
49
52
  - lib/generators/frozen/templates/db/database.yml
50
53
  - lib/generators/frozen/templates/db/initializers/friendly_id.rb
51
54
  - lib/generators/frozen/templates/db/initializers/skip_controller_tests_and_helpers.rb