superform 0.6.1 → 0.7.0

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -3
  3. data/CLAUDE.md +46 -0
  4. data/Gemfile.lock +6 -1
  5. data/README.md +208 -75
  6. data/examples/basic_form.rb +21 -0
  7. data/examples/checkbox_form.rb +28 -0
  8. data/examples/date_time_form.rb +18 -0
  9. data/examples/example_form.rb +10 -0
  10. data/examples/select_form.rb +26 -0
  11. data/examples/special_inputs_form.rb +23 -0
  12. data/examples/textarea_form.rb +15 -0
  13. data/lib/generators/superform/install/templates/base.rb +33 -7
  14. data/lib/superform/dom.rb +13 -1
  15. data/lib/superform/field.rb +14 -31
  16. data/lib/superform/rails/choices/choice.rb +39 -0
  17. data/lib/superform/rails/choices/mapper.rb +41 -0
  18. data/lib/superform/rails/choices.rb +6 -0
  19. data/lib/superform/rails/components/base.rb +9 -2
  20. data/lib/superform/rails/components/checkbox.rb +34 -7
  21. data/lib/superform/rails/components/checkboxes.rb +38 -0
  22. data/lib/superform/rails/components/datalist.rb +34 -0
  23. data/lib/superform/rails/components/input.rb +1 -1
  24. data/lib/superform/rails/components/label.rb +1 -1
  25. data/lib/superform/rails/components/radio.rb +21 -0
  26. data/lib/superform/rails/components/radios.rb +38 -0
  27. data/lib/superform/rails/components/select.rb +52 -8
  28. data/lib/superform/rails/field.rb +91 -44
  29. data/lib/superform/version.rb +1 -1
  30. data/server/components/breadcrumb.rb +11 -0
  31. data/server/components/form_card.rb +13 -0
  32. data/server/components/layout.rb +23 -0
  33. data/server/controllers/forms_controller.rb +94 -0
  34. data/server/models/example.rb +31 -0
  35. data/server/public/styles.css +282 -0
  36. data/server/rails.rb +56 -0
  37. data/superform.gemspec +37 -0
  38. metadata +26 -4
  39. data/lib/superform/rails/option_mapper.rb +0 -36
data/server/rails.rb ADDED
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+
5
+ require "active_model"
6
+ require "action_controller/railtie"
7
+ require "phlex-rails"
8
+
9
+ # Load superform from this repo
10
+ require_relative "../lib/superform"
11
+ require_relative "../lib/superform/rails"
12
+
13
+ # Directories
14
+ SERVER_DIR = Pathname.new(__dir__)
15
+ EXAMPLES_DIR = SERVER_DIR.join("../examples").expand_path
16
+
17
+ # Minimal Rails app
18
+ class SuperformApp < Rails::Application
19
+ config.root = SERVER_DIR
20
+ config.eager_load = false
21
+ config.consider_all_requests_local = true
22
+ config.secret_key_base = "superform-demo-secret-key-base-for-development-only"
23
+ config.hosts.clear
24
+ config.public_file_server.enabled = true
25
+
26
+ config.autoload_paths << root.join("components")
27
+ config.autoload_paths << root.join("models")
28
+ config.autoload_paths << root.join("controllers")
29
+
30
+ config.autoload_paths << EXAMPLES_DIR
31
+ end
32
+
33
+ # Collect form classes dynamically
34
+ def form_classes
35
+ EXAMPLES_DIR.glob("*.rb").sort.filter_map do |path|
36
+ next if path.basename.to_s == "example_form.rb"
37
+ cpath = Rails.autoloaders.main.cpath_expected_at(path)
38
+ Object.const_get(cpath)
39
+ end
40
+ end
41
+
42
+ SuperformApp.initialize!
43
+
44
+ SuperformApp.routes.draw do
45
+ root to: "forms#index"
46
+ get "/forms/:id" => "forms#show", as: :form
47
+ post "/forms/:id" => "forms#create"
48
+ end
49
+
50
+ def self.start(port: 3000)
51
+ require "rackup"
52
+ puts "Starting Superform Examples on http://localhost:#{port}"
53
+ puts "Press Ctrl+C to stop"
54
+ puts
55
+ Rackup::Handler::WEBrick.run(SuperformApp, Port: port)
56
+ end
data/superform.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/superform/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "superform"
7
+ spec.version = Superform::VERSION
8
+ spec.authors = ["Brad Gessler"]
9
+ spec.email = ["bradgessler@gmail.com"]
10
+
11
+ spec.summary = "Build forms in Rails"
12
+ spec.description = "A better way to customize and build forms for your Rails application"
13
+ spec.homepage = "https://github.com/rubymonolith/superform"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.7.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/rubymonolith/superform"
21
+ spec.metadata["changelog_uri"] = "https://github.com/rubymonolith/superform"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # 2.0 rcs, betas, etc.
35
+ spec.add_dependency "phlex-rails", "~> 2.0"
36
+ spec.add_dependency "zeitwerk", "~> 2.6"
37
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-08-29 00:00:00.000000000 Z
10
+ date: 2026-03-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: phlex-rails
@@ -46,6 +46,7 @@ extra_rdoc_files: []
46
46
  files:
47
47
  - ".rspec"
48
48
  - CHANGELOG.md
49
+ - CLAUDE.md
49
50
  - CODE_OF_CONDUCT.md
50
51
  - Gemfile
51
52
  - Gemfile.lock
@@ -54,6 +55,13 @@ files:
54
55
  - README.md
55
56
  - Rakefile
56
57
  - SPEC_STYLE_GUIDE.md
58
+ - examples/basic_form.rb
59
+ - examples/checkbox_form.rb
60
+ - examples/date_time_form.rb
61
+ - examples/example_form.rb
62
+ - examples/select_form.rb
63
+ - examples/special_inputs_form.rb
64
+ - examples/textarea_form.rb
57
65
  - lib/generators/superform/install/USAGE
58
66
  - lib/generators/superform/install/install_generator.rb
59
67
  - lib/generators/superform/install/templates/base.rb
@@ -66,20 +74,34 @@ files:
66
74
  - lib/superform/namespace_collection.rb
67
75
  - lib/superform/node.rb
68
76
  - lib/superform/rails.rb
77
+ - lib/superform/rails/choices.rb
78
+ - lib/superform/rails/choices/choice.rb
79
+ - lib/superform/rails/choices/mapper.rb
69
80
  - lib/superform/rails/components/base.rb
70
81
  - lib/superform/rails/components/button.rb
71
82
  - lib/superform/rails/components/checkbox.rb
83
+ - lib/superform/rails/components/checkboxes.rb
84
+ - lib/superform/rails/components/datalist.rb
72
85
  - lib/superform/rails/components/field.rb
73
86
  - lib/superform/rails/components/input.rb
74
87
  - lib/superform/rails/components/label.rb
88
+ - lib/superform/rails/components/radio.rb
89
+ - lib/superform/rails/components/radios.rb
75
90
  - lib/superform/rails/components/select.rb
76
91
  - lib/superform/rails/components/textarea.rb
77
92
  - lib/superform/rails/field.rb
78
93
  - lib/superform/rails/form.rb
79
- - lib/superform/rails/option_mapper.rb
80
94
  - lib/superform/rails/strong_parameters.rb
81
95
  - lib/superform/version.rb
96
+ - server/components/breadcrumb.rb
97
+ - server/components/form_card.rb
98
+ - server/components/layout.rb
99
+ - server/controllers/forms_controller.rb
100
+ - server/models/example.rb
101
+ - server/public/styles.css
102
+ - server/rails.rb
82
103
  - sig/superform.rbs
104
+ - superform.gemspec
83
105
  homepage: https://github.com/rubymonolith/superform
84
106
  licenses:
85
107
  - MIT
@@ -95,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
117
  requirements:
96
118
  - - ">="
97
119
  - !ruby/object:Gem::Version
98
- version: 2.6.0
120
+ version: 2.7.0
99
121
  required_rubygems_version: !ruby/object:Gem::Requirement
100
122
  requirements:
101
123
  - - ">="
@@ -1,36 +0,0 @@
1
- module Superform
2
- module Rails
3
- # Accept a collection of objects and map them to options suitable for form controls, like `select > options`
4
- class OptionMapper
5
- include Enumerable
6
-
7
- def initialize(collection)
8
- @collection = collection
9
- end
10
-
11
- def each(&options)
12
- @collection.each do |object|
13
- case object
14
- in ActiveRecord::Relation => relation
15
- active_record_relation_options_enumerable(relation).each(&options)
16
- in id, value
17
- options.call id, value
18
- in value
19
- options.call value, value.to_s
20
- end
21
- end
22
- end
23
-
24
- def active_record_relation_options_enumerable(relation)
25
- Enumerator.new do |collection|
26
- relation.each do |object|
27
- attributes = object.attributes
28
- id = attributes.delete(relation.primary_key)
29
- value = attributes.values.join(" ")
30
- collection << [ id, value ]
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end