frozen_rails 0.0.3 → 0.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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -13
  3. data/lib/frozen_rails/appendable.rb +0 -1
  4. data/lib/frozen_rails/copyable.rb +14 -0
  5. data/lib/frozen_rails/generator.rb +2 -0
  6. data/lib/frozen_rails/taggable.rb +7 -8
  7. data/lib/frozen_rails/version.rb +1 -1
  8. data/lib/generators/frozen/db_generator.rb +88 -28
  9. data/lib/generators/frozen/md_generator.rb +10 -45
  10. data/lib/generators/frozen/ssg_generator.rb +17 -5
  11. data/lib/generators/frozen/templates/db/database.yml +18 -0
  12. data/lib/generators/frozen/templates/db/initializers/friendly_id.rb +13 -0
  13. data/lib/generators/frozen/templates/db/initializers/readonly_routes.rb +14 -0
  14. data/lib/generators/frozen/templates/db/{sqlite_uuid.rb → initializers/sqlite_uuid.rb} +0 -6
  15. data/lib/generators/frozen/templates/db/{static_db.rb → initializers/static_db.rb} +0 -3
  16. data/lib/generators/frozen/templates/db/lib/generators/avo/controller/controller_generator.rb +13 -0
  17. data/lib/generators/frozen/templates/db/lib/generators/avo/install/install_generator.rb +11 -0
  18. data/lib/generators/frozen/templates/db/lib/generators/avo/resource/resource_generator.rb +30 -0
  19. data/lib/generators/frozen/templates/db/lib/templates/active_record/model/model.rb.tt +26 -0
  20. data/lib/generators/frozen/templates/db/lib/templates/erb/scaffold/index.html.erb.tt +14 -0
  21. data/lib/generators/frozen/templates/db/lib/templates/erb/scaffold/partial.html.erb.tt +17 -0
  22. data/lib/generators/frozen/templates/db/lib/templates/erb/scaffold/show.html.erb.tt +10 -0
  23. data/lib/generators/frozen/templates/db/lib/templates/rails/scaffold_controller/controller.rb.tt +11 -0
  24. data/lib/generators/frozen/templates/md/controllers/categories_controller.rb +0 -2
  25. data/lib/generators/frozen/templates/md/controllers/pages_controller.rb +0 -2
  26. data/lib/generators/frozen/templates/md/helpers/markdown_helper.rb +0 -2
  27. data/lib/generators/frozen/templates/md/initializers/decant_extensions.rb +1 -3
  28. data/lib/generators/frozen/templates/md/models/category.rb +1 -2
  29. data/lib/generators/frozen/templates/md/models/concerns/linkable.rb +0 -1
  30. data/lib/generators/frozen/templates/md/models/page.rb +0 -1
  31. data/lib/generators/frozen/templates/ssg/storage.yml +12 -0
  32. metadata +16 -70
  33. data/lib/generators/frozen/dx_generator.rb +0 -41
  34. data/lib/generators/frozen/templates/db/avo.rb +0 -10
  35. data/lib/generators/frozen/templates/db/friendly_id.rb +0 -14
  36. data/lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/_form.html.erb.tt +0 -1
  37. data/lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/edit.html.erb.tt +0 -1
  38. data/lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/index.html.erb.tt +0 -14
  39. data/lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/new.html.erb.tt +0 -1
  40. data/lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/partial.html.erb.tt +0 -17
  41. data/lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/show.html.erb.tt +0 -7
  42. data/lib/generators/frozen/templates/dx/lib/templates/rails/scaffold_controller/api_controller.rb.tt +0 -22
  43. data/lib/generators/frozen/templates/dx/lib/templates/rails/scaffold_controller/controller.rb.tt +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a88e369b28d7f01071814ba007495f9a1d573d3b8c0b0c59b0e48decb22637d
4
- data.tar.gz: ea76d23b0fcedf87e504189e8019e39d21dc6ffe7b203cac5446a07d84cebe97
3
+ metadata.gz: 0d1e4038850bfbf0972c64d50c2de0ef854c1165cbef4f6fba5c63cc963d5e39
4
+ data.tar.gz: 47a78650b8de3d17aa463157c78c1242789389e4b0df03b56eeef9057efe9fbd
5
5
  SHA512:
6
- metadata.gz: b8d60e302866a07592e7f2b1c5605583cffa49f2084c31a390441eb3f69a50859565ec0e0c72211ad551bb0715bc754d45be654552cea32e162f0afb99bb99dd
7
- data.tar.gz: 2dd187e1d486d6b299fd731a7575d8e6560674ffe0e3e99479ff92fa0432c6c699c3d3085368d97a010bd63a8bf8527e79f37731d926ad03c92b697f2bd51679
6
+ metadata.gz: d33940e9f7a07bc38a4dcdcdb867396b137e5a2bb265207fb46e45c1b65a3593f30127bd63f23ed12c5aa5d01dde3aa924a83049178f3be71d34108b5aca67c7
7
+ data.tar.gz: 3a7a176184cf0b5d87b0a4727187e5ee89ee46e11fbf7a2a13d66a05efcb9a759f72f973c243bab36b962514e94303f1ecc00b3058fcde5a1dbdbf4893faa25d
data/README.md CHANGED
@@ -61,11 +61,13 @@ bin/rails g frozen:ssg
61
61
  ```
62
62
 
63
63
  ```bash
64
- # ✅ passes, works correctly, ❌ has test suite
64
+ # ✅ passes, works correctly, ❌ has test suite
65
65
 
66
- # - sqlite uuid patch
67
- # - static_db initializer
68
- # - friendly_id and Avo configuration
66
+ # - Adds `sqlite_extensions-uuid`
67
+ # - Adds `static_db`
68
+ # - Adds `friendly_id`
69
+ # - Adds `avo`
70
+ # - Adjusts Rails scaffold generator and migration generator to be more helpful
69
71
 
70
72
  bin/rails g frozen:db
71
73
  ```
@@ -79,6 +81,14 @@ bin/rails g frozen:db
79
81
  bin/rails g frozen:seo
80
82
  ```
81
83
 
84
+ ```bash
85
+ # FUTURE: frozen:erb
86
+
87
+ # - view_component
88
+ # - herb
89
+ # - lookbook
90
+ ```
91
+
82
92
  ```bash
83
93
  # ✅ passes, ❓ works correctly, ❌ has test suite
84
94
 
@@ -93,15 +103,6 @@ bin/rails g frozen:ui
93
103
  ```bash
94
104
  # ✅ passes, ❓ works correctly, ❌ has test suite
95
105
 
96
- # - copy custom lib templates
97
- # - add autoload/generator config to application.rb
98
-
99
- bin/rails g frozen:dx
100
- ```
101
-
102
- ```bash
103
- # ✅ passes, ❓ works correctly, ❌ has test suite
104
-
105
106
  # Full Rails setup (runs all frozen generators in order)
106
107
 
107
108
  bin/rails g frozen:rails
@@ -10,5 +10,4 @@ module Appendable
10
10
  def append_to_routes(content)
11
11
  inject_into_file "config/routes.rb", optimize_indentation("\n#{content}", 2), before: /end(?:\n)\z/, verbose: false
12
12
  end
13
-
14
13
  end
@@ -0,0 +1,14 @@
1
+ module Copyable
2
+ extend ActiveSupport::Concern
3
+
4
+ private
5
+
6
+ def copy_directory(source, target, **options)
7
+ base = File.join(self.class.source_root, source)
8
+ Dir.glob("#{base}/**/*").each do |path|
9
+ next if File.directory?(path)
10
+ rel = path.delete_prefix("#{base}/")
11
+ copy_file "#{source}/#{rel}", "#{target}/#{rel}", **options
12
+ end
13
+ end
14
+ end
@@ -3,12 +3,14 @@
3
3
  require "rails/generators"
4
4
  require "frozen_rails/appendable"
5
5
  require "frozen_rails/bundleable"
6
+ require "frozen_rails/copyable"
6
7
  require "frozen_rails/taggable"
7
8
 
8
9
  module FrozenRails
9
10
  class Generator < Rails::Generators::Base
10
11
  include Appendable
11
12
  include Bundleable
13
+ include Copyable
12
14
  include Taggable
13
15
  end
14
16
  end
@@ -19,7 +19,7 @@ module Taggable
19
19
  end
20
20
 
21
21
  def frozen_end_tag(env: nil)
22
- frozen_start_tag(env:).gsub('# <', '# </')
22
+ frozen_start_tag(env:).gsub("# <", "# </")
23
23
  end
24
24
 
25
25
  def add_frozen_gemfile_tags(env: nil)
@@ -34,9 +34,9 @@ module Taggable
34
34
  case env
35
35
  when nil
36
36
  /frozen_rails[^\n]*\n/
37
- when 'local'
37
+ when "local"
38
38
  "group :development, :test do\n"
39
- when 'development'
39
+ when "development"
40
40
  "group :development do\n"
41
41
  else
42
42
  raise "Unsupported env!"
@@ -45,15 +45,14 @@ module Taggable
45
45
 
46
46
  def cleanup_frozen_tags!(env: nil)
47
47
  if options[:cleanup_frozen_tags]
48
- gsub_file! "Gemfile", /[^\n]*#{frozen_start_tag(env:)}[^\n]*\n/, ''
49
- gsub_file! "Gemfile", /[^\n]*#{frozen_end_tag(env:)}[^\n]*\n/, ''
48
+ gsub_file! "Gemfile", /[^\n]*#{frozen_start_tag(env:)}[^\n]*\n/, ""
49
+ gsub_file! "Gemfile", /[^\n]*#{frozen_end_tag(env:)}[^\n]*\n/, ""
50
50
  end
51
51
  end
52
52
 
53
53
  def cleanup_all_frozen_tags!
54
54
  cleanup_frozen_tags!
55
- cleanup_frozen_tags!(env: 'local')
56
- cleanup_frozen_tags!(env: 'development')
55
+ cleanup_frozen_tags!(env: "local")
56
+ cleanup_frozen_tags!(env: "development")
57
57
  end
58
-
59
58
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FrozenRails # :nodoc:
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
@@ -5,19 +5,19 @@ require "frozen_rails/generator"
5
5
  module Frozen
6
6
  module Generators
7
7
  class DbGenerator < FrozenRails::Generator
8
- source_root File.expand_path("templates", __dir__)
8
+ source_root File.expand_path("templates/db", __dir__)
9
9
 
10
- desc "Prepare a Rails app for SQLite UUIDs, static_db, Avo and FriendlyId"
10
+ desc "Prepare a Rails app for static_db with SQLite UUIDs, Avo and FriendlyId"
11
11
 
12
12
  def add_gems
13
13
  add_frozen_gems <<~RUBY
14
14
  # frozen:db
15
- gem "sqlite_extensions-uuid"
16
15
  gem "static_db"
16
+ gem "sqlite_extensions-uuid"
17
17
  gem "friendly_id"
18
18
  RUBY
19
19
 
20
- add_frozen_gems <<~RUBY, env: "local"
20
+ add_frozen_gems <<~RUBY, env: "development"
21
21
  # frozen:db
22
22
  gem "avo", ">= 3.2"
23
23
  RUBY
@@ -27,41 +27,101 @@ module Frozen
27
27
  bundle!
28
28
  end
29
29
 
30
- # configure database.yml for sqlite uuid extension
31
- def configure_database_yml
32
- return unless File.exist?("config/database.yml")
30
+ def add_routes
31
+ append_to_routes <<~RUBY
32
+ # frozen:db
33
+ if Rails.env.development?
34
+ mount_avo at: "/avo"
35
+ end
36
+ RUBY
37
+ end
38
+
39
+ def copy_files
40
+ copy_file "database.yml", "config/database.yml", force: true
41
+ copy_directory "initializers", "config/initializers"
42
+ copy_directory "lib", "lib"
43
+ end
44
+
45
+ def configure_application
46
+ gsub_file "config/application.rb", /(config\.autoload_lib\(ignore: %w\[).*(\]\))/, '\1assets generators tasks templates\2'
33
47
 
34
- inject_into_file "config/database.yml", after: "adapter: sqlite3\n" do
35
- <<~YML
36
- extensions:
37
- - <%= SqliteExtensions::UUID.to_path %>
38
- YML
39
- end
48
+ append_to_application_config <<~RUBY
49
+ # frozen:db
50
+ config.generators do |g|
51
+ g.orm :active_record, primary_key_type: :uuid
52
+ g.test_framework nil
53
+ g.helper nil
54
+ end
55
+ config.active_storage.draw_routes = true
56
+ RUBY
40
57
  end
41
58
 
42
- # create initializer for sqlite uuid generator patch
43
- def create_sqlite_uuid_initializer
44
- template "db/sqlite_uuid.rb", "config/initializers/sqlite_uuid.rb"
59
+ def prepare_db
60
+ rails_command "db:create"
61
+ rails_command "db:schema:load"
45
62
  end
46
63
 
47
- # create initializer for static_db configuration
48
- def create_static_db_initializer
49
- template "db/static_db.rb", "config/initializers/static_db.rb"
64
+ def setup_active_storage
65
+ rails_command "active_storage:install"
66
+
67
+ active_storage_migration = in_root { Dir.glob("db/migrate/*.active_storage.rb").first }
68
+
69
+ gsub_file active_storage_migration, /# Use.*\n.*primary_and_foreign_key_types/, <<~RUBY.chomp.lines.map(&:chomp).join("\n ")
70
+ # Use custom primary and foreign key types to support SQLite UUIDs.
71
+ primary_key_type = { id: :string, default: -> { "uuid()" }, limit: 36 }
72
+ foreign_key_type = { type: :string, limit: 36 }
73
+ RUBY
74
+ gsub_file active_storage_migration, "id: primary_key_type", "**primary_key_type"
75
+ gsub_file active_storage_migration, "type: foreign_key_type", "**foreign_key_type"
76
+ gsub_file active_storage_migration, /\n\s*private.*end(?=\nend)/m, ""
50
77
  end
51
78
 
52
- # create friendly_id initializer
53
- def create_friendly_id_initializer
54
- template "db/friendly_id.rb", "config/initializers/friendly_id.rb"
79
+ def setup_friendly_id
80
+ rails_command "g migration create_friendly_id_slugs"
81
+
82
+ friendly_id_migration = in_root { Dir.glob("db/migrate/*create_friendly_id_slugs.rb").first }
83
+
84
+ gsub_file friendly_id_migration, /create_table.*?end(?=\n)/m, <<~RUBY.chomp.lines.map(&:chomp).join("\n ")
85
+ create_table :friendly_id_slugs, id: :string, default: -> { "uuid()" }, limit: 36 do |t|
86
+ t.string :slug, null: false
87
+ t.string :sluggable_id, limit: 36, null: false
88
+ t.string :sluggable_type, limit: 50
89
+ t.string :scope
90
+ t.datetime :created_at
91
+ end
92
+ add_index :friendly_id_slugs, [ :sluggable_type, :sluggable_id ]
93
+ add_index :friendly_id_slugs, [ :slug, :sluggable_type ], length: { slug: 140, sluggable_type: 50 }
94
+ add_index :friendly_id_slugs, [ :slug, :sluggable_type, :scope ], length: { slug: 70, sluggable_type: 50, scope: 70 }, unique: true
95
+ RUBY
55
96
  end
56
97
 
57
- # create a minimal avo initializer stub
58
- def create_avo_initializer
59
- template "db/avo.rb", "config/initializers/avo.rb"
98
+ def setup_avo
99
+ rails_command "g avo:install"
100
+
101
+ prepend_to_file "config/initializers/avo.rb", <<~RUBY + "\n"
102
+ if Rails.env.development?
103
+ # Allow moving Avo controllers into `app/avo/controllers/`
104
+ Rails.autoloaders.main.collapse(
105
+ Rails.root.join("app/avo/controllers")
106
+ )
107
+ else
108
+ # Don't load Avo
109
+ Rails.autoloaders.main.ignore(
110
+ Rails.root.join("app/avo"),
111
+ Rails.root.join("app/controllers/avo")
112
+ )
113
+
114
+ # Don't configure Avo
115
+ return
116
+ end
117
+ RUBY
118
+
119
+ run "b rubocop -a config/initializers/avo.rb"
60
120
  end
61
121
 
62
- # reminder to run generators
63
- def post_install_reminders
64
- say_status :info, "Run `rails generate friendly_id` to create slug migrations."
122
+ def migrate_and_cleanup_db
123
+ rails_command "db:migrate"
124
+ rails_command "db:drop"
65
125
  end
66
126
  end
67
127
  end
@@ -5,7 +5,7 @@ require "frozen_rails/generator"
5
5
  module Frozen
6
6
  module Generators
7
7
  class MdGenerator < FrozenRails::Generator
8
- source_root File.expand_path("templates", __dir__)
8
+ source_root File.expand_path("templates/md", __dir__)
9
9
 
10
10
  # When absent, the generator will prompt interactively (unless running non-interactively).
11
11
  class_option :rouge_theme, type: :string, desc: "Rouge theme to install (runs non-interactive if provided)"
@@ -26,44 +26,13 @@ module Frozen
26
26
  bundle!
27
27
  end
28
28
 
29
- def create_content_directory
30
- empty_directory "content/pages"
31
- end
32
-
33
29
  def copy_files
34
- app_files = [
35
- "controllers/categories_controller.rb",
36
- "controllers/pages_controller.rb",
37
- "helpers/markdown_helper.rb",
38
- "models/concerns/linkable.rb",
39
- "models/category.rb",
40
- "models/page.rb",
41
- "views/categories/index.html.erb",
42
- "views/categories/show.html.erb",
43
- "views/pages/show.html.erb",
44
- ]
45
-
46
- app_files.each do |app_file|
47
- copy_file "md/#{app_file}", "app/#{app_file}"
48
- end
49
-
50
- config_files = [
51
- "initializers/decant_extensions.rb",
52
- ]
53
-
54
- config_files.each do |config_file|
55
- copy_file "md/#{config_file}", "config/#{config_file}"
56
- end
57
-
58
- content_files = [
59
- "pages/frozen-rails.md",
60
- "pages/rails-static.md",
61
- "pages/rails-static/rails-static-logo.webp",
62
- ]
63
-
64
- content_files.each do |content_file|
65
- copy_file "md/#{content_file}", "content/#{content_file}"
66
- end
30
+ copy_directory "controllers", "app/controllers"
31
+ copy_directory "helpers", "app/helpers"
32
+ copy_directory "models", "app/models"
33
+ copy_directory "views", "app/views"
34
+ copy_directory "initializers", "config/initializers"
35
+ copy_directory "pages", "content/pages"
67
36
  end
68
37
 
69
38
  def add_config
@@ -74,19 +43,15 @@ module Frozen
74
43
  RUBY
75
44
  end
76
45
 
77
- # Add routes for pages
78
46
  def add_routes
79
47
  append_to_routes <<~RUBY
80
- # frozen:md
81
48
  root "categories#index"
82
49
 
83
- # Use `Regexp.union` instead of array for constraints!
84
- # https://github.com/rails/rails/issues/47726
50
+ # frozen:md
85
51
  constraints slug: Regexp.union(Category.all.map(&:slug)) do
86
- resources :categories, param: :slug, only: [:index, :show]
52
+ resources :categories, param: :slug, only: [ :index, :show ]
87
53
  end
88
-
89
- resources :pages, param: :slug, only: [:show]
54
+ resources :pages, param: :slug, only: [ :show ]
90
55
  RUBY
91
56
  end
92
57
 
@@ -5,7 +5,7 @@ require "frozen_rails/generator"
5
5
  module Frozen
6
6
  module Generators
7
7
  class SsgGenerator < FrozenRails::Generator
8
- source_root File.expand_path("templates", __dir__)
8
+ source_root File.expand_path("templates/ssg", __dir__)
9
9
 
10
10
  desc "Set up Parklife static site generation with CI workflows and helper scripts"
11
11
 
@@ -21,16 +21,28 @@ module Frozen
21
21
  end
22
22
 
23
23
  def run_parklife_init
24
- unless system("bundle exec parklife init --rails --github-pages")
25
- say_status :warn, "Unable to run parklife init. Please execute manually!"
26
- end
24
+ run "bundle exec parklife init --rails --github-pages"
25
+ append_to_file ".gitignore", "# frozen:ssg\n/build\n"
27
26
  end
28
27
 
29
28
  def setup_gitlab_pages
30
- copy_file "ssg/.gitlab-ci.yml", ".gitlab-ci.yml"
29
+ copy_file ".gitlab-ci.yml"
31
30
  comment_lines "Parkfile", /config\.nested_index = false/
32
31
  end
33
32
 
33
+ def configure_parklife_active_storage_integration
34
+ copy_file "storage.yml", "config/storage.yml", force: true
35
+
36
+ uncomment_lines "config/environments/production.rb", /config\.assume_ssl = true/
37
+ gsub_file "config/environments/production.rb", /config\.active_storage\.service = :\w+/, "config.active_storage.service = :parklife"
38
+
39
+ insert_into_file "config/application.rb", "\n" + <<~RUBY, before: /(\n#.*)?\n#.*\nBundler\.require/
40
+ # frozen:ssg
41
+ if ARGV.first == "build"
42
+ require "parklife-rails/activestorage"
43
+ end
44
+ RUBY
45
+ end
34
46
  end
35
47
  end
36
48
  end
@@ -0,0 +1,18 @@
1
+ default: &default
2
+ adapter: sqlite3
3
+ extensions:
4
+ - <%= SqliteExtensions::UUID.to_path %>
5
+ max_connections: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
6
+ timeout: 5000
7
+
8
+ development:
9
+ <<: *default
10
+ database: storage/development.sqlite3
11
+
12
+ test:
13
+ <<: *default
14
+ database: storage/test.sqlite3
15
+
16
+ production:
17
+ <<: *default
18
+ database: storage/production.sqlite3
@@ -0,0 +1,13 @@
1
+ FriendlyId.defaults do |config|
2
+ config.use :slugged
3
+ config.use :finders
4
+ config.use :history
5
+ config.use :reserved
6
+
7
+ config.reserved_words = %w[
8
+ new edit index
9
+ session login logout users admin
10
+ stylesheets assets javascripts images
11
+ avo pages
12
+ ]
13
+ end
@@ -0,0 +1,14 @@
1
+ ActiveSupport.on_load(:active_record) do
2
+ require "rails/generators"
3
+ require "rails/generators/erb/scaffold/scaffold_generator"
4
+
5
+ Erb::Generators::ScaffoldGenerator.prepend(
6
+ Module.new do
7
+ private
8
+
9
+ def available_views
10
+ [ "index", "show" ]
11
+ end
12
+ end
13
+ )
14
+ end
@@ -1,9 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- # generated by frozen:db
4
- # Monkey-patch ActiveRecord generators to produce string primary keys with
5
- # uuid defaults when using SQLite.
6
-
7
1
  ActiveSupport.on_load(:active_record) do
8
2
  require "rails/generators"
9
3
  require "rails/generators/active_record/model/model_generator"
@@ -1,6 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- # generated by frozen:db
4
1
  StaticDb.configure do |config|
5
2
  config.fixture_path = Rails.root.join("content", "data")
6
3
  end
@@ -0,0 +1,13 @@
1
+ require "generators/avo/controller_generator"
2
+
3
+ module Generators
4
+ module Avo
5
+ class ControllerGenerator
6
+ def create
7
+ return if override_controller?
8
+
9
+ template "resource/controller.tt", "app/avo/controllers/#{controller_name}.rb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require "generators/avo/install_generator"
2
+
3
+ module Generators
4
+ module Avo
5
+ class InstallGenerator
6
+ def create_initializer_file
7
+ template "initializer/avo.tt", "config/initializers/avo.rb"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ require "generators/avo/resource_generator"
2
+
3
+ module Generators
4
+ module Avo
5
+ class ResourceGenerator
6
+ no_tasks do
7
+ def field_string(name, type, options)
8
+ return "field :slug, as: :id, format_using: -> { link_to value, main_app.polymorphic_path(record) }" if name.to_sym == :slug
9
+ "field :#{name}, as: :#{type}#{options}"
10
+ end
11
+
12
+ def generate_fields_from_args
13
+ @args.each do |arg|
14
+ name, type = arg.split(":")
15
+ type = "string" if type.blank?
16
+ fields[name] = field(name, type.to_sym)
17
+ end
18
+
19
+ ", format_index_using: -> { content_tag(:span, \"#\", title: value) }#{generated_fields_template}"
20
+ end
21
+
22
+ def field(name, type)
23
+ return { field: "id" } if name.to_sym == :id
24
+ return { field: "id" } if name.to_sym == :slug
25
+ ::Avo::Mappings::NAMES_MAPPING[name.to_sym] || ::Avo::Mappings::FIELDS_MAPPING[type&.to_sym] || { field: "text" }
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %> < <%= parent_class_name.classify %>
3
+ <% if attributes.any? { |a| a.name.to_s == "slug" } -%>
4
+ include FriendlyId
5
+ friendly_id :<%= attributes.reject { |a| a.name.to_s == "slug" }.select { |a| a.type.to_s == "string" }.first.name %>
6
+ <% end -%>
7
+ <% attributes.select(&:reference?).each do |attribute| -%>
8
+ belongs_to :<%= attribute.name %><%= ", polymorphic: true" if attribute.polymorphic? %>
9
+ <% end -%>
10
+ <% attributes.select(&:rich_text?).each do |attribute| -%>
11
+ has_rich_text :<%= attribute.name %>
12
+ <% end -%>
13
+ <% attributes.select(&:attachment?).each do |attribute| -%>
14
+ has_one_attached :<%= attribute.name %>
15
+ <% end -%>
16
+ <% attributes.select(&:attachments?).each do |attribute| -%>
17
+ has_many_attached :<%= attribute.name %>
18
+ <% end -%>
19
+ <% attributes.select(&:token?).each do |attribute| -%>
20
+ has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
21
+ <% end -%>
22
+ <% if attributes.any?(&:password_digest?) -%>
23
+ has_secure_password
24
+ <% end -%>
25
+ end
26
+ <% end -%>
@@ -0,0 +1,14 @@
1
+ <p style="color: green"><%%= notice %></p>
2
+
3
+ <%% content_for :title, "<%= human_name.pluralize %>" %>
4
+
5
+ <h1><%= human_name.pluralize %></h1>
6
+
7
+ <div id="<%= plural_table_name %>">
8
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
9
+ <%%= render <%= singular_table_name %> %>
10
+ <p>
11
+ <%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(singular_table_name) %> %>
12
+ </p>
13
+ <%% end %>
14
+ </div>
@@ -0,0 +1,17 @@
1
+ <div id="<%%= dom_id <%= singular_name %> %>">
2
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
3
+ <p>
4
+ <strong><%= attribute.human_name %>:</strong>
5
+ <% if attribute.attachment? -%>
6
+ <%%= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached? %>
7
+ <% elsif attribute.attachments? -%>
8
+ <%% <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
9
+ <div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
10
+ <%% end %>
11
+ <% else -%>
12
+ <%%= <%= singular_name %>.<%= attribute.column_name %> %>
13
+ <% end -%>
14
+ </p>
15
+
16
+ <% end -%>
17
+ </div>
@@ -0,0 +1,10 @@
1
+ <p style="color: green"><%%= notice %></p>
2
+
3
+ <%%= render @<%= singular_table_name %> %>
4
+
5
+ <div>
6
+ <%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper(type: :path) %> %>
7
+ <%% if Rails.env.development? %>
8
+ <%%= link_to "Edit", avo.resources_<%= show_helper(type: :path) %> %>
9
+ <%% end %>
10
+ </div>
@@ -0,0 +1,11 @@
1
+ <% module_namespacing do -%>
2
+ class <%= controller_class_name %>Controller < ApplicationController
3
+ def index
4
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
5
+ end
6
+
7
+ def show
8
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params.expect(:id)") %>
9
+ end
10
+ end
11
+ <% end -%>
@@ -1,5 +1,4 @@
1
1
  class CategoriesController < ApplicationController
2
-
3
2
  def index
4
3
  @categories = Category.all
5
4
  end
@@ -7,5 +6,4 @@ class CategoriesController < ApplicationController
7
6
  def show
8
7
  @category = Category.find(params[:slug])
9
8
  end
10
-
11
9
  end
@@ -1,7 +1,5 @@
1
1
  class PagesController < ApplicationController
2
-
3
2
  def show
4
3
  @page = Page.find(params[:slug])
5
4
  end
6
-
7
5
  end
@@ -1,5 +1,4 @@
1
1
  module MarkdownHelper
2
-
3
2
  def render_content_from(page)
4
3
  erb_processed_content = render(inline: page.content, layout: false)
5
4
  Kramdown::Document.new(
@@ -12,5 +11,4 @@ module MarkdownHelper
12
11
  def pages_image_tag(path, **kwargs)
13
12
  image_tag "pages/#{@page.slug}/#{path}", **kwargs
14
13
  end
15
-
16
14
  end
@@ -1,8 +1,7 @@
1
- require 'decant/content'
1
+ require "decant/content"
2
2
 
3
3
  module Decant
4
4
  class Content
5
-
6
5
  def self.where(**kwargs)
7
6
  scope = all
8
7
  kwargs.each do |key, value|
@@ -12,6 +11,5 @@ module Decant
12
11
  end
13
12
  scope
14
13
  end
15
-
16
14
  end
17
15
  end
@@ -11,7 +11,7 @@ Category = Data.define(:slug, :title) do
11
11
  def self.all
12
12
  [
13
13
  new(slug: "intro", title: "How it began"),
14
- new(slug: "outro", title: "How it ended"),
14
+ new(slug: "outro", title: "How it ended")
15
15
  ]
16
16
  end
17
17
 
@@ -32,5 +32,4 @@ Category = Data.define(:slug, :title) do
32
32
  def pages
33
33
  Page.where(category_slugs: slug)
34
34
  end
35
-
36
35
  end
@@ -38,5 +38,4 @@ module Linkable
38
38
  def persisted?
39
39
  true
40
40
  end
41
-
42
41
  end
@@ -10,5 +10,4 @@ Page = Decant.define(dir: "content/pages", ext: "md") do
10
10
  def categories
11
11
  Category.where(slug: category_slugs)
12
12
  end
13
-
14
13
  end
@@ -0,0 +1,12 @@
1
+ # Intentionally use same storage location for local and parklife!!!
2
+ local: &default
3
+ service: Disk
4
+ root: <%= Rails.root.join("content/storage") %>
5
+
6
+ parklife:
7
+ <<: *default
8
+ service: Parklife
9
+
10
+ test:
11
+ service: Disk
12
+ root: <%= Rails.root.join("tmp/storage") %>
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaus Weidinger
@@ -23,62 +23,6 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '7.2'
26
- - !ruby/object:Gem::Dependency
27
- name: bundler
28
- requirement: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: '1.15'
33
- type: :development
34
- prerelease: false
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '1.15'
40
- - !ruby/object:Gem::Dependency
41
- name: combustion
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: '1.1'
47
- type: :development
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: '1.1'
54
- - !ruby/object:Gem::Dependency
55
- name: rake
56
- requirement: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '13.0'
61
- type: :development
62
- prerelease: false
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '13.0'
68
- - !ruby/object:Gem::Dependency
69
- name: rspec
70
- requirement: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: '3.9'
75
- type: :development
76
- prerelease: false
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: '3.9'
82
26
  description: Generators for turning Rails into an SSG
83
27
  email:
84
28
  - Klaus Weidinger
@@ -92,27 +36,28 @@ files:
92
36
  - lib/frozen_rails.rb
93
37
  - lib/frozen_rails/appendable.rb
94
38
  - lib/frozen_rails/bundleable.rb
39
+ - lib/frozen_rails/copyable.rb
95
40
  - lib/frozen_rails/generator.rb
96
41
  - lib/frozen_rails/taggable.rb
97
42
  - lib/frozen_rails/version.rb
98
43
  - lib/generators/frozen/db_generator.rb
99
- - lib/generators/frozen/dx_generator.rb
100
44
  - lib/generators/frozen/md_generator.rb
101
45
  - lib/generators/frozen/rails_generator.rb
102
46
  - lib/generators/frozen/seo_generator.rb
103
47
  - lib/generators/frozen/ssg_generator.rb
104
- - lib/generators/frozen/templates/db/avo.rb
105
- - lib/generators/frozen/templates/db/friendly_id.rb
106
- - lib/generators/frozen/templates/db/sqlite_uuid.rb
107
- - lib/generators/frozen/templates/db/static_db.rb
108
- - lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/_form.html.erb.tt
109
- - lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/edit.html.erb.tt
110
- - lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/index.html.erb.tt
111
- - lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/new.html.erb.tt
112
- - lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/partial.html.erb.tt
113
- - lib/generators/frozen/templates/dx/lib/templates/erb/scaffold/show.html.erb.tt
114
- - lib/generators/frozen/templates/dx/lib/templates/rails/scaffold_controller/api_controller.rb.tt
115
- - lib/generators/frozen/templates/dx/lib/templates/rails/scaffold_controller/controller.rb.tt
48
+ - lib/generators/frozen/templates/db/database.yml
49
+ - lib/generators/frozen/templates/db/initializers/friendly_id.rb
50
+ - lib/generators/frozen/templates/db/initializers/readonly_routes.rb
51
+ - lib/generators/frozen/templates/db/initializers/sqlite_uuid.rb
52
+ - lib/generators/frozen/templates/db/initializers/static_db.rb
53
+ - lib/generators/frozen/templates/db/lib/generators/avo/controller/controller_generator.rb
54
+ - lib/generators/frozen/templates/db/lib/generators/avo/install/install_generator.rb
55
+ - lib/generators/frozen/templates/db/lib/generators/avo/resource/resource_generator.rb
56
+ - lib/generators/frozen/templates/db/lib/templates/active_record/model/model.rb.tt
57
+ - lib/generators/frozen/templates/db/lib/templates/erb/scaffold/index.html.erb.tt
58
+ - lib/generators/frozen/templates/db/lib/templates/erb/scaffold/partial.html.erb.tt
59
+ - lib/generators/frozen/templates/db/lib/templates/erb/scaffold/show.html.erb.tt
60
+ - lib/generators/frozen/templates/db/lib/templates/rails/scaffold_controller/controller.rb.tt
116
61
  - lib/generators/frozen/templates/md/controllers/categories_controller.rb
117
62
  - lib/generators/frozen/templates/md/controllers/pages_controller.rb
118
63
  - lib/generators/frozen/templates/md/helpers/markdown_helper.rb
@@ -130,6 +75,7 @@ files:
130
75
  - lib/generators/frozen/templates/seo/robots_generatable.rb
131
76
  - lib/generators/frozen/templates/seo/sitemap.rb
132
77
  - lib/generators/frozen/templates/seo/sitemap_entry.rb
78
+ - lib/generators/frozen/templates/ssg/storage.yml
133
79
  - lib/generators/frozen/templates/ui/cable.yml
134
80
  - lib/generators/frozen/templates/ui/hotkey_controller.js
135
81
  - lib/generators/frozen/ui_generator.rb
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "frozen_rails/generator"
4
-
5
- module Frozen
6
- module Generators
7
- class DxGenerator < FrozenRails::Generator
8
- source_root File.expand_path("templates", __dir__)
9
-
10
- desc "Install developer experience helpers: custom lib templates and generator config"
11
-
12
- # copy over the lib folder content from static example
13
- def copy_lib_templates
14
- directory "dx/lib", "lib"
15
- end
16
-
17
- # inject configuration into config/application.rb
18
- def configure_application
19
- return unless File.exist?("config/application.rb")
20
-
21
- inject_into_file "config/application.rb",
22
- after: "class Application < Rails::Application\n" do
23
- <<~RUBY
24
- # Please, add to the `ignore` list any other `lib` subdirectories that do
25
- # not contain `.rb` files, or that should not be reloaded or eager loaded.
26
- # Common ones are `templates`, `generators`, or `middleware`, for example.
27
- config.autoload_lib(ignore: %w[assets tasks])
28
-
29
- config.generators do |g|
30
- g.orm :active_record, primary_key_type: :uuid
31
- g.test_framework false
32
- end
33
-
34
- config.active_storage.draw_routes = true
35
-
36
- RUBY
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # generated by frozen:db
4
- # Minimal Avo configuration; adjust as needed.
5
- Avo.configure do |config|
6
- config.root_path = "/avo"
7
- config.authorization_client = nil
8
- config.explicit_authorization = true
9
- config.click_row_to_view_record = true
10
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # generated by frozen:db
4
- FriendlyId.defaults do |config|
5
- # enable the most common modules
6
- config.use :reserved
7
- config.use :slugged
8
- config.use :finders
9
- config.use :history
10
-
11
- # a UUID will be appended automatically when a unique slug cannot be generated
12
- # suitable reserved words to avoid can be declared here.
13
- config.reserved_words = %w[new edit index session login logout users admin]
14
- end
@@ -1,14 +0,0 @@
1
- <p style="color: green"><%%= notice %></p>
2
-
3
- <%% content_for :title, "<%%= human_name.pluralize %>" %>
4
-
5
- <h1><%%= human_name.pluralize %></h1>
6
-
7
- <div id="<%%= plural_table_name %>">
8
- <%% @<%%= plural_table_name %>.each do |<%%= singular_table_name %>| %>
9
- <%%= render <%%= singular_table_name %> %>
10
- <p>
11
- <%%= link_to "Show this <%%= human_name.downcase %>", <%%= model_resource_name(singular_table_name) %> %>
12
- </p>
13
- <%% end %>
14
- </div>
@@ -1,17 +0,0 @@
1
- <div id="<%%= dom_id <%%= singular_name %> %>">
2
- <%% attributes.reject(&:password_digest?).each do |attribute| -%>
3
- <p>
4
- <strong><%%= attribute.human_name %>:</strong>
5
- <%% if attribute.attachment? -%>
6
- <%%= link_to <%%= singular_name %>.<%%= attribute.column_name %>.filename, <%%= singular_name %>.<%%= attribute.column_name %> if <%%= singular_name %>.<%%= attribute.column_name %>.attached? %>
7
- <%% elsif attribute.attachments? -%>
8
- <%% <%%= singular_name %>.<%%= attribute.column_name %>.each do |<%%= attribute.singular_name %>| %>
9
- <div><%%= link_to <%%= attribute.singular_name %>.filename, <%%= attribute.singular_name %> %></div>
10
- <%% end %>
11
- <%% else -%>
12
- <%%= <%%= singular_name %>.<%%= attribute.column_name %> %>
13
- <%% end -%>
14
- </p>
15
-
16
- <%% end -%>
17
- </div>
@@ -1,7 +0,0 @@
1
- <p style="color: green"><%%= notice %></p>
2
-
3
- <%%= render @<%%= singular_table_name %> %>
4
-
5
- <div>
6
- <%%= link_to "Back to <%%= human_name.pluralize.downcase %>", <%%= index_helper(type: :path) %> %>
7
- </div>
@@ -1,22 +0,0 @@
1
- <%% module_namespacing do -%>
2
- class <%%= controller_class_name %>Controller < ApplicationController
3
- before_action :set_<%%= singular_table_name %>, only: :show
4
-
5
- def index
6
- @<%%= plural_table_name %> = <%%= orm_class.all(class_name) %>
7
-
8
- render json: <%%= "@#{plural_table_name}" %>
9
- end
10
-
11
- def show
12
- render json: <%%= "@#{singular_table_name}" %>
13
- end
14
-
15
- private
16
-
17
- def set_<%%= singular_table_name %>
18
- @<%%= singular_table_name %> = <%%= orm_class.find(class_name, "params.expect(:id)") %>
19
- end
20
-
21
- end
22
- <%% end -%>
@@ -1,19 +0,0 @@
1
- <%% module_namespacing do -%>
2
- class <%%= controller_class_name %>Controller < ApplicationController
3
- before_action :set_<%%= singular_table_name %>, only: :show
4
-
5
- def index
6
- @<%%= plural_table_name %> = <%%= orm_class.all(class_name) %>
7
- end
8
-
9
- def show
10
- end
11
-
12
- private
13
-
14
- def set_<%%= singular_table_name %>
15
- @<%%= singular_table_name %> = <%%= orm_class.find(class_name, "params.expect(:id)") %>
16
- end
17
-
18
- end
19
- <%% end -%>