protos-protoform 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +9 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +245 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +8 -0
- data/lib/generators/protoform/install/USAGE +8 -0
- data/lib/generators/protoform/install/install_generator.rb +39 -0
- data/lib/generators/protoform/install/templates/application_form.rb +36 -0
- data/lib/protoform/dom.rb +60 -0
- data/lib/protoform/field.rb +38 -0
- data/lib/protoform/field_collection.rb +39 -0
- data/lib/protoform/namespace.rb +159 -0
- data/lib/protoform/namespace_collection.rb +77 -0
- data/lib/protoform/node.rb +14 -0
- data/lib/protoform/rails/components/button.rb +28 -0
- data/lib/protoform/rails/components/checkbox.rb +28 -0
- data/lib/protoform/rails/components/component.rb +15 -0
- data/lib/protoform/rails/components/field_component.rb +18 -0
- data/lib/protoform/rails/components/input.rb +42 -0
- data/lib/protoform/rails/components/label.rb +22 -0
- data/lib/protoform/rails/components/select.rb +72 -0
- data/lib/protoform/rails/components/textarea.rb +14 -0
- data/lib/protoform/rails/form/field.rb +62 -0
- data/lib/protoform/rails/form.rb +121 -0
- data/lib/protoform/rails/option_mapper.rb +40 -0
- data/lib/protoform/rails/strong_parameters.rb +19 -0
- data/lib/protoform/version.rb +5 -0
- data/lib/protoform.rb +22 -0
- data/protos-protoform.gemspec +49 -0
- metadata +122 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Protoform
|
4
|
+
module Rails
|
5
|
+
# Accept a collection of objects and map them to options suitable for form
|
6
|
+
# controls, like `select > options`
|
7
|
+
|
8
|
+
class OptionMapper
|
9
|
+
include Enumerable
|
10
|
+
|
11
|
+
def initialize(collection)
|
12
|
+
@collection = collection
|
13
|
+
end
|
14
|
+
|
15
|
+
def each(&options)
|
16
|
+
@collection.each do |object|
|
17
|
+
case object
|
18
|
+
in ActiveRecord::Relation => relation
|
19
|
+
active_record_relation_options_enumerable(relation).each(&options)
|
20
|
+
in id, value
|
21
|
+
yield id, value
|
22
|
+
in value
|
23
|
+
yield value, value.to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def active_record_relation_options_enumerable(relation)
|
29
|
+
Enumerator.new do |collection|
|
30
|
+
relation.each do |object|
|
31
|
+
attributes = object.attributes
|
32
|
+
id = attributes.delete(relation.primary_key)
|
33
|
+
value = attributes.values.join(" ")
|
34
|
+
collection << [id, value]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Protoform
|
4
|
+
module Rails
|
5
|
+
module StrongParameters
|
6
|
+
protected
|
7
|
+
|
8
|
+
# Assigns params to the form and returns the model.
|
9
|
+
def assign(params, to:)
|
10
|
+
form = to
|
11
|
+
# TODO: Figure out how to render this in a way that doesn't concat
|
12
|
+
# a string; just throw everything away.
|
13
|
+
render_to_string form
|
14
|
+
form.assign params
|
15
|
+
form.model
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/protoform.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zeitwerk"
|
4
|
+
require "protos"
|
5
|
+
|
6
|
+
module Protoform
|
7
|
+
Loader = Zeitwerk::Loader.for_gem.tap do |loader|
|
8
|
+
loader.ignore "#{__dir__}/generators"
|
9
|
+
loader.inflector.inflect(
|
10
|
+
# rubocop:disable Style/StringHashKeys
|
11
|
+
"dom" => "DOM"
|
12
|
+
# rubocop:enable Style/StringHashKeys
|
13
|
+
)
|
14
|
+
loader.setup
|
15
|
+
end
|
16
|
+
|
17
|
+
class Error < StandardError; end
|
18
|
+
end
|
19
|
+
|
20
|
+
def Protoform(...) # rubocop:disable Naming/MethodName, Style/TopLevelMethodDefinition
|
21
|
+
Protoform::Namespace.root(...)
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/protoform/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "protos-protoform"
|
7
|
+
spec.version = Protoform::VERSION
|
8
|
+
spec.authors = ["Nolan Tait"]
|
9
|
+
spec.email = ["nolanjtait@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Phlex based form builder for Rails"
|
12
|
+
spec.description = "Build phlex based forms using Rails conventions"
|
13
|
+
spec.homepage = "https://github.com/nolantait/protos-protoform"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.1.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"] = spec.homepage
|
21
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released. The
|
24
|
+
# `git ls-files -z` loads the files in the RubyGem that have been added into
|
25
|
+
# git.
|
26
|
+
spec.files = Dir.chdir(__dir__) do
|
27
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(
|
29
|
+
*%w[
|
30
|
+
bin/
|
31
|
+
test/
|
32
|
+
spec/
|
33
|
+
features/
|
34
|
+
.git
|
35
|
+
.circleci
|
36
|
+
appveyor
|
37
|
+
]
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
spec.bindir = "exe"
|
42
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
43
|
+
spec.require_paths = ["lib"]
|
44
|
+
|
45
|
+
spec.add_dependency "phlex-rails", "~> 1.0"
|
46
|
+
spec.add_dependency "protos", "~> 0.2"
|
47
|
+
spec.add_dependency "zeitwerk", "~> 2.6"
|
48
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: protos-protoform
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nolan Tait
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: phlex-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: protos
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: zeitwerk
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
description: Build phlex based forms using Rails conventions
|
56
|
+
email:
|
57
|
+
- nolanjtait@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".rspec"
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- CHANGELOG.md
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- lib/generators/protoform/install/USAGE
|
71
|
+
- lib/generators/protoform/install/install_generator.rb
|
72
|
+
- lib/generators/protoform/install/templates/application_form.rb
|
73
|
+
- lib/protoform.rb
|
74
|
+
- lib/protoform/dom.rb
|
75
|
+
- lib/protoform/field.rb
|
76
|
+
- lib/protoform/field_collection.rb
|
77
|
+
- lib/protoform/namespace.rb
|
78
|
+
- lib/protoform/namespace_collection.rb
|
79
|
+
- lib/protoform/node.rb
|
80
|
+
- lib/protoform/rails/components/button.rb
|
81
|
+
- lib/protoform/rails/components/checkbox.rb
|
82
|
+
- lib/protoform/rails/components/component.rb
|
83
|
+
- lib/protoform/rails/components/field_component.rb
|
84
|
+
- lib/protoform/rails/components/input.rb
|
85
|
+
- lib/protoform/rails/components/label.rb
|
86
|
+
- lib/protoform/rails/components/select.rb
|
87
|
+
- lib/protoform/rails/components/textarea.rb
|
88
|
+
- lib/protoform/rails/form.rb
|
89
|
+
- lib/protoform/rails/form/field.rb
|
90
|
+
- lib/protoform/rails/option_mapper.rb
|
91
|
+
- lib/protoform/rails/strong_parameters.rb
|
92
|
+
- lib/protoform/version.rb
|
93
|
+
- protos-protoform.gemspec
|
94
|
+
homepage: https://github.com/nolantait/protos-protoform
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata:
|
98
|
+
allowed_push_host: https://rubygems.org
|
99
|
+
homepage_uri: https://github.com/nolantait/protos-protoform
|
100
|
+
source_code_uri: https://github.com/nolantait/protos-protoform
|
101
|
+
changelog_uri: https://github.com/nolantait/protos-protoform
|
102
|
+
rubygems_mfa_required: 'true'
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 3.1.0
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubygems_version: 3.5.7
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Phlex based form builder for Rails
|
122
|
+
test_files: []
|