plutonium 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -2
  3. data/Rakefile +9 -0
  4. data/app/assets/build/plutonium.js +5122 -0
  5. data/app/assets/javascripts/controllers/index.js +34 -0
  6. data/app/assets/javascripts/plutonium-app.js +7 -0
  7. data/app/assets/javascripts/plutonium.js +1 -0
  8. data/css.manifest +3 -0
  9. data/esbuild.config.js +44 -0
  10. data/lib/generators/pu/gen/component/component_generator.rb +13 -4
  11. data/lib/generators/pu/lib/plutonium_generators/concerns/actions.rb +86 -72
  12. data/lib/generators/pu/lib/plutonium_generators/model_generator.rb +1 -1
  13. data/lib/generators/pu/rodauth/install_generator.rb +1 -2
  14. data/lib/plutonium/core/fields/renderers/factory.rb +0 -1
  15. data/lib/plutonium/pkg/base.rb +0 -4
  16. data/lib/plutonium/railtie.rb +10 -2
  17. data/lib/plutonium/version.rb +1 -1
  18. data/lib/plutonium.rb +17 -14
  19. data/package-lock.json +0 -7
  20. data/package.json +5 -5
  21. data/postcss.config.js +1 -1
  22. data/public/plutonium-assets/plutonium-app-36KN5FVJ.js +6 -0
  23. data/public/plutonium-assets/plutonium-app-36KN5FVJ.js.map +7 -0
  24. data/public/plutonium-assets/plutonium.50232e35b5495f5ad90d.css +3415 -0
  25. data/tailwind.config.js +11 -12
  26. data/templates/base.rb +1 -1
  27. metadata +19 -22
  28. data/app/assets/js/controllers/application.js +0 -7
  29. data/app/assets/js/controllers/index.js +0 -30
  30. data/app/assets/js/plutonium.js +0 -2
  31. data/build.js +0 -12
  32. data/lib/generators/pu/gem/pagy/pagy_generator.rb +0 -25
  33. data/lib/generators/pu/gem/pagy/templates/config/initializers/pagy.rb +0 -4
  34. data/lib/generators/pu/gem/rabl/rabl_generator.rb +0 -25
  35. data/lib/generators/pu/gem/rabl/templates/.keep +0 -0
  36. data/lib/generators/pu/gem/rabl/templates/config/initializers/rabl.rb +0 -60
  37. data/lib/generators/pu/gem/simple_form/simple_form_generator.rb +0 -25
  38. data/lib/generators/pu/gem/simple_form/templates/.keep +0 -0
  39. data/lib/plutonium/core/fields/renderers/map_renderer.rb +0 -19
  40. /data/{lib/generators/pu/gem/pagy/templates → app/assets/build}/.keep +0 -0
  41. /data/app/assets/{js → javascripts}/controllers/resource_dismiss_controller.js +0 -0
  42. /data/app/assets/{js → javascripts}/controllers/resource_drop_down_controller.js +0 -0
  43. /data/app/assets/{js → javascripts}/turbo/index.js +0 -0
  44. /data/app/assets/{js → javascripts}/turbo/turbo_actions.js +0 -0
  45. /data/app/assets/{js → javascripts}/turbo/turbo_debug.js +0 -0
  46. /data/app/assets/{js → javascripts}/turbo/turbo_frame_monkey_patch.js +0 -0
  47. /data/app/assets/{css → stylesheets}/plutonium.css +0 -0
@@ -0,0 +1,34 @@
1
+ // Import controllers here
2
+ import NestedResourceFormFieldsController from "../../../views/components/nested_resource_form_fields/nested_resource_form_fields_controller.js"
3
+ import TabBarController from "../../../views/components/tab_bar/tab_bar_controller.js"
4
+ import ToolbarController from "../../../views/components/toolbar/toolbar_controller.js"
5
+ import TableSearchInputController from "../../../views/components/table_search_input/table_search_input_controller.js"
6
+ import TableToolbarController from "../../../views/components/table_toolbar/table_toolbar_controller.js"
7
+ import TableController from "../../../views/components/table/table_controller.js"
8
+ import FormController from "../../../views/components/form/form_controller.js"
9
+ import ResourceDropDownController from "./resource_drop_down_controller.js"
10
+ import ResourceDismissController from "./resource_dismiss_controller.js"
11
+
12
+ export function registerControllers(application) {
13
+ // Register controllers here
14
+ application.register("nested-resource-form-fields", NestedResourceFormFieldsController)
15
+ application.register("tab-bar", TabBarController)
16
+ application.register("toolbar", ToolbarController)
17
+ application.register("table-search-input", TableSearchInputController)
18
+ application.register("table-toolbar", TableToolbarController)
19
+ application.register("table", TableController)
20
+ application.register("form", FormController)
21
+ application.register("resource-drop-down", ResourceDropDownController)
22
+ application.register("resource-dismiss", ResourceDismissController)
23
+ }
24
+
25
+ // Export controllers here
26
+ export { NestedResourceFormFieldsController };
27
+ export { TabBarController };
28
+ export { ToolbarController };
29
+ export { TableSearchInputController };
30
+ export { TableToolbarController };
31
+ export { TableController };
32
+ export { FormController };
33
+ export { ResourceDropDownController };
34
+ export { ResourceDismissController };
@@ -0,0 +1,7 @@
1
+ import { Application } from "@hotwired/stimulus"
2
+ const application = Application.start()
3
+
4
+ import { registerControllers } from "./plutonium"
5
+ registerControllers(application)
6
+
7
+ import "./turbo"
@@ -0,0 +1 @@
1
+ export * from "./controllers"
data/css.manifest ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "plutonium.css": "plutonium.50232e35b5495f5ad90d.css"
3
+ }
data/esbuild.config.js ADDED
@@ -0,0 +1,44 @@
1
+ const esbuild = require('esbuild');
2
+ const manifestPlugin = require('esbuild-plugin-manifest')
3
+
4
+
5
+ if (process.argv.includes("--prod")) {
6
+ esbuild.build({
7
+ outdir: "public/plutonium-assets",
8
+ entryPoints: [
9
+ "app/assets/javascripts/plutonium-app.js"
10
+ ],
11
+ plugins: [
12
+ manifestPlugin({
13
+ filename: `${__dirname}/js.manifest`,
14
+ shortNames: true,
15
+ })
16
+ ],
17
+ minify: true,
18
+ sourcemap: true,
19
+ bundle: true,
20
+ })
21
+
22
+ esbuild.build({
23
+ outdir: "app/assets/build",
24
+ entryPoints: [
25
+ "app/assets/javascripts/plutonium.js"
26
+ ],
27
+ bundle: true,
28
+ })
29
+ }
30
+ else {
31
+ esbuild.context({
32
+ outdir: "public/plutonium-assets/build",
33
+ entryPoints: [
34
+ "app/assets/javascripts/plutonium-app.js"
35
+ ],
36
+ plugins: [
37
+ manifestPlugin({
38
+ filename: `${__dirname}/js.dev.manifest`,
39
+ shortNames: true,
40
+ })
41
+ ],
42
+ bundle: true,
43
+ }).then((context) => context.watch().catch((e) => console.error(e.message)))
44
+ }
@@ -20,8 +20,10 @@ module Pu
20
20
  template "component.html.erb", "#{component_path}.html.erb"
21
21
  template "controller.js", controller_path
22
22
 
23
- controllers_file = File.join __dir__, "../../../../../app/assets/js/controllers/index.js"
24
- insert_into_file controllers_file, controller_registration, after: /.*Register controllers here.*\n\n/
23
+ controllers_index_file = File.join __dir__, "../../../../../app/assets/javascripts/controllers/index.js"
24
+ insert_into_file controllers_index_file, controller_import, after: /.*Import controllers here*\n/
25
+ insert_into_file controllers_index_file, controller_registration, after: /.*Register controllers here*\n/
26
+ insert_into_file controllers_index_file, controller_export, after: /.*Export controllers here*\n/
25
27
  end
26
28
 
27
29
  protected
@@ -78,9 +80,16 @@ module Pu
78
80
  [component_module, "#{component_name}Controller"].compact.join("::").gsub("::", "_")
79
81
  end
80
82
 
83
+ def controller_import
84
+ "import #{controller_reference} from \"../../../../#{controller_path}\"\n"
85
+ end
86
+
81
87
  def controller_registration
82
- %(import #{controller_reference} from "../../../../#{controller_path}"\n) +
83
- %(application.register("#{controller_identifier}", #{controller_reference})\n\n)
88
+ " application.register(\"#{controller_identifier}\", #{controller_reference})\n"
89
+ end
90
+
91
+ def controller_export
92
+ "export { #{controller_reference} }\n"
84
93
  end
85
94
  end
86
95
  end
@@ -11,87 +11,89 @@ module PlutoniumGenerators
11
11
  protected
12
12
 
13
13
  #
14
- # Sets the ruby version for the project in .ruby-version and Gemfile to `PlutoniumGenerators::RUBY_VERSION`
14
+ # Sets the ruby version for the project in .ruby-version and Gemfile to `version`
15
15
  #
16
- # @return [void]
17
- #
18
- def set_ruby_version!
19
- log :set_ruby_version!, PlutoniumGenerators::RUBY_VERSION
20
-
21
- in_root do
22
- create_file ".ruby-version", PlutoniumGenerators::RUBY_VERSION, force: true, verbose: false
23
- gsub_file "Gemfile", /^ruby ["'].*["']/, "ruby '~> #{PlutoniumGenerators::RUBY_VERSION}'", verbose: false
24
- end
25
- end
26
-
27
- #
28
- # Adds a new gem into the Gemfile
29
- # Existing directives are updated if they do not match
30
- # When `:group` is specified, the gem is inserted into the approriate gem group.
31
- #
32
- # @param [String] name the name of the gem
33
- # @param [Hash] **kwargs set of options to append see #super
16
+ # @param [string] version semantic ruby version you want to use e.g. 3.3.0
34
17
  #
35
18
  # @return [void]
36
19
  #
37
- def gem(name, **kwargs)
38
- groups = Array(kwargs.delete(:group))
20
+ def set_ruby_version!(version)
21
+ log :set_ruby_version!, version
39
22
 
40
23
  in_root do
41
- begin
42
- # Create a temp gemfile
43
- File.rename("Gemfile", "Gemfile.bak")
44
- File.write("Gemfile", "")
45
- # Generate the directive
46
- super
47
- # Get the generated directive
48
- directive = gemfile.strip
49
- ensure
50
- # Restore our gemfile
51
- File.delete "Gemfile"
52
- File.rename "Gemfile.bak", "Gemfile"
53
- end
54
-
55
- pattern = /^# gem ['"]#{name}['"].*/
56
- if gemfile.match(pattern)
57
- # Replace commented out directive
58
- gsub_file("Gemfile", pattern, directive)
59
- break
60
- end
61
-
62
- # Remove existing directive
63
- remove_gem name
64
-
65
- # Insert the new directive
66
- if groups != []
67
- str = groups.sort.map(&:inspect).join(", ")
68
- after_sentinel = "group #{str} do\n"
69
-
70
- unless File.read("Gemfile").match?(/^#{after_sentinel}/)
71
- inject_into_file "Gemfile", "\n#{after_sentinel}end\n"
72
- end
73
- else
74
- after_sentinel = "# Project gems\n\n"
75
- unless File.read("Gemfile").match?(/^#{after_sentinel}/)
76
- inject_into_file "Gemfile", "\n#{after_sentinel}", after: /^ruby .*\n/
77
- end
78
- end
79
-
80
- inject_into_file "Gemfile", "#{directive}\n", after: /^#{after_sentinel}/
24
+ create_file ".ruby-version", version, force: true, verbose: false
25
+ gsub_file "Gemfile", /^ruby ["'].*["']/, "ruby '~> #{version}'", verbose: false
81
26
  end
82
27
  end
83
28
 
84
- #
85
- # Removes a gem and any preceeding comments from the Gemfile
86
- #
87
- # @param gem [String] the name of the gem to remove
88
- #
89
- # @return [void]
90
- #
91
- def remove_gem(gem)
92
- log :remove_gem, gem
93
- gsub_file "Gemfile", /(:?^.*#.*\n)*.*gem ['"]#{gem}['"].*\n/, "", verbose: false
94
- end
29
+ # #
30
+ # # Adds a new gem into the Gemfile
31
+ # # Existing directives are updated if they do not match
32
+ # # When `:group` is specified, the gem is inserted into the approriate gem group.
33
+ # #
34
+ # # @param [String] name the name of the gem
35
+ # # @param [Hash] **kwargs set of options to append see #super
36
+ # #
37
+ # # @return [void]
38
+ # #
39
+ # def gem(name, **kwargs)
40
+ # groups = Array(kwargs.delete(:group))
41
+
42
+ # in_root do
43
+ # begin
44
+ # # Create a temp gemfile
45
+ # File.rename("Gemfile", "Gemfile.bak")
46
+ # File.write("Gemfile", "")
47
+ # # Generate the directive
48
+ # super
49
+ # # Get the generated directive
50
+ # directive = gemfile.strip
51
+ # ensure
52
+ # # Restore our gemfile
53
+ # File.delete "Gemfile"
54
+ # File.rename "Gemfile.bak", "Gemfile"
55
+ # end
56
+
57
+ # pattern = /^# gem ['"]#{name}['"].*/
58
+ # if gemfile.match(pattern)
59
+ # # Replace commented out directive
60
+ # gsub_file("Gemfile", pattern, directive)
61
+ # break
62
+ # end
63
+
64
+ # # Remove existing directive
65
+ # remove_gem name
66
+
67
+ # # Insert the new directive
68
+ # if groups != []
69
+ # str = groups.sort.map(&:inspect).join(", ")
70
+ # after_sentinel = "group #{str} do\n"
71
+
72
+ # unless File.read("Gemfile").match?(/^#{after_sentinel}/)
73
+ # inject_into_file "Gemfile", "\n#{after_sentinel}end\n"
74
+ # end
75
+ # else
76
+ # after_sentinel = "# Project gems\n\n"
77
+ # unless File.read("Gemfile").match?(/^#{after_sentinel}/)
78
+ # inject_into_file "Gemfile", "\n#{after_sentinel}", after: /^ruby .*\n/
79
+ # end
80
+ # end
81
+
82
+ # inject_into_file "Gemfile", "#{directive}\n", after: /^#{after_sentinel}/
83
+ # end
84
+ # end
85
+
86
+ # #
87
+ # # Removes a gem and any preceeding comments from the Gemfile
88
+ # #
89
+ # # @param gem [String] the name of the gem to remove
90
+ # #
91
+ # # @return [void]
92
+ # #
93
+ # def remove_gem(gem)
94
+ # log :remove_gem, gem
95
+ # gsub_file "Gemfile", /(:?^.*#.*\n)*.*gem ['"]#{gem}['"].*\n/, "", verbose: false
96
+ # end
95
97
 
96
98
  #
97
99
  # Evaluates the given template and merges it with the project's docker-compose.yml
@@ -348,6 +350,18 @@ module PlutoniumGenerators
348
350
  File.read("Gemfile")
349
351
  end
350
352
  end
353
+
354
+ def bundle(*gems)
355
+ Bundler.with_unbundled_env do
356
+ run "bundle add #{Array(gems).join " "}"
357
+ end
358
+ end
359
+
360
+ def unbundle(*gems)
361
+ Bundler.with_unbundled_env do
362
+ run "bundle remove #{Array(gems).join " "}"
363
+ end
364
+ end
351
365
  end
352
366
  end
353
367
  end
@@ -7,7 +7,7 @@ module PlutoniumGenerators
7
7
  class ModelGenerator < ActiveRecord::Generators::ModelGenerator
8
8
  include PlutoniumGenerators::Generator
9
9
 
10
- # remove_hook_for :test_framework
10
+ remove_hook_for :test_framework
11
11
  remove_task :create_migration_file
12
12
  remove_task :create_model_file
13
13
  remove_task :create_module_file
@@ -18,8 +18,7 @@ module Pu
18
18
 
19
19
  def add_rodauth
20
20
  Bundler.with_unbundled_env do
21
- run "bundle add bcrypt"
22
- run "bundle add rodauth-rails"
21
+ run "bundle add bcrypt rodauth-rails"
23
22
  end
24
23
  end
25
24
 
@@ -9,7 +9,6 @@ module Plutonium
9
9
 
10
10
  map_type :belongs_to, :has_one, :has_many, to: Plutonium::Core::Fields::Renderers::AssociationRenderer
11
11
  map_type :attachment, to: Plutonium::Core::Fields::Renderers::AttachmentRenderer
12
- map_type :map, to: Plutonium::Core::Fields::Renderers::MapRenderer
13
12
 
14
13
  def self.build(name, type:, **)
15
14
  mapping = mappings[type] || Plutonium::Core::Fields::Renderers::BasicRenderer
@@ -17,10 +17,6 @@ module Plutonium
17
17
  add_view_paths_initializer.instance_variable_set(:@block, ->(app) {})
18
18
  end
19
19
  end
20
-
21
- def scoped_to_entity?
22
- raise NotImplementedError, "scoped_to_entity?"
23
- end
24
20
  end
25
21
  end
26
22
  end
@@ -2,7 +2,15 @@ require "view_component"
2
2
 
3
3
  module Plutonium
4
4
  class Railtie < Rails::Railtie
5
- initializer "plutonium.assets_server" do
5
+ config.plutonium = ActiveSupport::OrderedOptions.new
6
+
7
+ initializer "plutonium.append_assets_path" do |app|
8
+ config.to_prepare do
9
+ Rails.application.config.assets.paths << Plutonium.root.join("app/assets/build").to_s
10
+ end
11
+ end
12
+
13
+ initializer "plutonium.asset_server" do
6
14
  # setup a middleware to serve our assets
7
15
  config.app_middleware.insert_before(
8
16
  ActionDispatch::Static,
@@ -17,7 +25,7 @@ module Plutonium
17
25
  )
18
26
  end
19
27
 
20
- initializer "plutonium.view_components" do
28
+ initializer "plutonium.view_components_capture_compat" do
21
29
  config.view_component.capture_compatibility_patch_enabled = true
22
30
  end
23
31
  end
@@ -1,3 +1,3 @@
1
1
  module Plutonium
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.2"
3
3
  end
data/lib/plutonium.rb CHANGED
@@ -21,28 +21,31 @@ module Plutonium
21
21
 
22
22
  def self.stylesheet_link
23
23
  if Plutonium::Config.development
24
- file = JSON.parse(File.read(root.join("css.manifest")))["plutonium-dev.css"]
25
- "/plutonium-assets/build/#{file}"
24
+ base_dir = "/plutonium-assets/build"
25
+ manifest = "css.dev.manifest"
26
+ filename = "plutonium-dev.css"
26
27
  else
27
- raise NotImplementedError, "TODO: implement asset resolution for prod"
28
- # @stylesheet ||= begin
29
- # file = JSON.parse(File.read(root.join("css.manifest")))["plutonium.css"]
30
- # "/plutonium-assets/#{file}"
31
- # end
28
+ base_dir = "/plutonium-assets"
29
+ manifest = "css.manifest"
30
+ filename = "plutonium.css"
32
31
  end
32
+
33
+ file = JSON.parse(File.read(root.join(manifest)))[filename]
34
+ "#{base_dir}/#{file}"
33
35
  end
34
36
 
35
37
  def self.script_link
38
+ filename = "plutonium-app.js"
36
39
  if Plutonium::Config.development
37
- file = JSON.parse(File.read(root.join("js.manifest")))["plutonium.js"]
38
- "/plutonium-assets/build/#{file}"
40
+ base_dir = "/plutonium-assets/build"
41
+ manifest = "js.dev.manifest"
39
42
  else
40
- raise NotImplementedError, "TODO: implement asset resolution for prod"
41
- # @stylesheet ||= begin
42
- # file = JSON.parse(File.read(root.join("css.manifest")))["plutonium.css"]
43
- # "/plutonium-assets/#{file}"
44
- # end
43
+ base_dir = "/plutonium-assets"
44
+ manifest = "js.manifest"
45
45
  end
46
+
47
+ file = JSON.parse(File.read(root.join(manifest)))[filename]
48
+ "#{base_dir}/#{file}"
46
49
  end
47
50
  end
48
51
 
data/package-lock.json CHANGED
@@ -13,7 +13,6 @@
13
13
  "esbuild-plugin-manifest": "^1.0.3",
14
14
  "flowbite": "^2.3.0",
15
15
  "lodash.debounce": "^4.0.8",
16
- "mapkick": "^0.2.6",
17
16
  "postcss": "^8.4.35",
18
17
  "postcss-cli": "^11.0.0",
19
18
  "postcss-hash": "^3.0.0",
@@ -1381,12 +1380,6 @@
1381
1380
  "node": "14 || >=16.14"
1382
1381
  }
1383
1382
  },
1384
- "node_modules/mapkick": {
1385
- "version": "0.2.6",
1386
- "resolved": "https://registry.npmjs.org/mapkick/-/mapkick-0.2.6.tgz",
1387
- "integrity": "sha512-sDfPCOhTpQrzJc3Yzwg5XOBy5o2TTNEfH2dG2QZM7RUtfQzhY+xErfhQHrQvSOaWbf4zOegPq/dhaWuv2fo4CA==",
1388
- "dev": true
1389
- },
1390
1383
  "node_modules/merge2": {
1391
1384
  "version": "1.4.1",
1392
1385
  "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",
data/package.json CHANGED
@@ -11,12 +11,12 @@
11
11
  "postcss": "^8.4.35",
12
12
  "postcss-cli": "^11.0.0",
13
13
  "postcss-hash": "^3.0.0",
14
- "tailwindcss": "^3.4.1",
15
- "mapkick": "^0.2.6"
14
+ "tailwindcss": "^3.4.1"
16
15
  },
17
16
  "scripts": {
18
- "watch-css": "postcss app/assets/css/plutonium.css -o public/plutonium-assets/build/plutonium-dev.css --watch",
19
- "watch-js": "node build.js",
20
- "build-css": "postcss app/assets/css/plutonium.css -o public/plutonium-assets/build/plutonium.css --watch"
17
+ "css:dev": "postcss app/assets/stylesheets/plutonium.css -o public/plutonium-assets/build/plutonium-dev.css --watch",
18
+ "js:dev": "node esbuild.config.js",
19
+ "css:prod": "postcss app/assets/stylesheets/plutonium.css -o public/plutonium-assets/plutonium.css --prod",
20
+ "js:prod": "node esbuild.config.js --prod"
21
21
  }
22
22
  }
data/postcss.config.js CHANGED
@@ -5,7 +5,7 @@ module.exports = {
5
5
  'postcss-hash': {
6
6
  algorithm: 'sha256',
7
7
  trim: 20,
8
- manifest: './css.manifest'
8
+ manifest: process.argv.includes("--prod") ? './css.manifest' : './css.dev.manifest'
9
9
  },
10
10
  }
11
11
  }