template_form 0.4.6 → 0.4.8

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: a2dffdc1b897b10460d029723d7f286651388e59c7a637eded104e78898edbab
4
- data.tar.gz: bf8b340b369c8113fae4d5d6311a83383de8cb9bd832e10fbe41c2d7917cc960
3
+ metadata.gz: 408026155358aa91f7c4751f36424be1364a7e21962c93501eaafad752e469ef
4
+ data.tar.gz: 8193bbf3b0241df0956e2b4957fea34e33aa6030e997f705ddf063b65caba4a7
5
5
  SHA512:
6
- metadata.gz: 0ac600b29d24bb2d9bce1b63d7d1d75cd9b94b7c25c836ab3c23a734db71f2f22b361be6a49b7b16055585c7b3dc642e5f010d3846831ea0ed152cea5e26412f
7
- data.tar.gz: 1b2e8c6caf8c4fa2d897ae42941c6d4d6f234c9bee95422f307614dc69836146cb1f87a3e451321e033113bcce0e003f00b2b2acbf113c5eb85b0a3ecec47371
6
+ metadata.gz: 7e8e9c96f173d1ade04629e2f22457d2ea885c3a4262f8e2327b6ab13a172c992469f269922d907491fdd7668f93d43def8c1773a4ceb9cb293d57f922b7eaa4
7
+ data.tar.gz: ccf8c4be15bfa0d5e615a2ffa07125fcd58b55d9f2d0c71898d37d1678b2018dab187c48d014bcb1b6a2bbb647039c40a7a63b31a5c604f5feba8442399ed008
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Template Form makes defining the HTML your form inputs generate as simple as possible: you just write it out. Most other form builders, e.g. Simple Form, add a layer of indirection and make you use their own DSL.
4
4
 
5
- Templates are grouped so you can for example define both vertical and horizontal forms, or Bootstrap and Tailwind forms, in the same Rails app.
5
+ Templates are namespaced so you can define different HTML for different situations, e.g. stacked or horizontal, in the same Rails app.
6
6
 
7
- Right now Template Form includes templates for [Bulma](https://bulma.io/documentation/form/) but in time it will include templates for all the popular CSS frameworks.
7
+ Right now Template Form includes templates for [Bulma](https://bulma.io/documentation/form/) because those are defined by Bulma. For Tailwind, or Bootstrap, you define your inputs yourself.
8
8
 
9
9
  Template Form works with all template engines supported by [Tilt](https://github.com/rtomayko/tilt).
10
10
 
@@ -98,7 +98,7 @@ And then you will get this HTML instead:
98
98
 
99
99
  ### Defining your templates
100
100
 
101
- Your templates live at `/app/forms/<FORM TYPE>/` where `<FORM TYPE>` is a name that makes sense to you, and the value that you use with the `:form_type` option to `#template_form_with`.
101
+ Your templates live at `TemplateForm.template_path` which defaults to `/app/forms/<FORM TYPE>/` where `<FORM TYPE>` is a name that makes sense to you, and the value that you use with the `:form_type` option to `#template_form_with`.
102
102
 
103
103
  They should have these names:
104
104
 
@@ -111,6 +111,8 @@ They should have these names:
111
111
 
112
112
  Use whatever extension goes with your template engine.
113
113
 
114
+ You can have several variations of a template, for example a [text input with inline add-on](https://tailwindui.com/components/application-ui/forms/input-groups#component-3620fb44e0a49ebce229526254018508). First, write your template at `<BASE>_<VARIANT>.html.erb`; say, `text_input_inline_add_on.html.erb`. Then use a `with: <VARIANT>` option in your view, e.g. `<%= form.input :name, with: :inline_add_on %>`.
115
+
114
116
  Inside each template you can use the normal Rails form helpers. Here's the template for Bulma's [text input](https://github.com/airblade/template_form/blob/master/lib/template_form/templates/bulma/text_input.html.erb):
115
117
 
116
118
  ```erb
@@ -77,7 +77,10 @@ module TemplateForm
77
77
 
78
78
  # TemplateForm::TextInput -> text_input
79
79
  def template_name
80
- self.class.name.demodulize.underscore
80
+ @template_name ||= [
81
+ self.class.name.demodulize.underscore,
82
+ options.delete(:with)
83
+ ].compact.join('_')
81
84
  end
82
85
 
83
86
  def detect_template_path(name)
@@ -89,7 +92,7 @@ module TemplateForm
89
92
  end
90
93
 
91
94
  def locations
92
- [ Pathname.new("#{Rails.root}/app/forms"),
95
+ [ TemplateForm.template_path,
93
96
  Pathname.new("#{__dir__}/templates") ]
94
97
  end
95
98
 
@@ -32,7 +32,7 @@ module TemplateForm
32
32
 
33
33
  options[:type] ||= 'password' if attribute_name.match(/password/)
34
34
 
35
- options.merge! view: @view
35
+ options.merge! view: @view if @view
36
36
 
37
37
  input_for(attribute_type).new(self, attribute_name, options).render
38
38
  end
@@ -1,3 +1,3 @@
1
1
  module TemplateForm
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.8"
3
3
  end
data/lib/template_form.rb CHANGED
@@ -15,6 +15,14 @@ module TemplateForm
15
15
  @form_type = val
16
16
  end
17
17
 
18
+ def self.template_path
19
+ @template_path || Pathname.new("#{Rails.root}/app/forms")
20
+ end
21
+
22
+ def self.template_path=(val)
23
+ @template_path = Pathname.new(val)
24
+ end
25
+
18
26
  private
19
27
 
20
28
  def self.noop_field_error_proc
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: template_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Stewart
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-16 00:00:00.000000000 Z
11
+ date: 2023-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubygems_version: 3.2.33
140
+ rubygems_version: 3.4.10
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: A template-based form builder for Rails.