template_form 0.4.7 → 0.4.9
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 +4 -4
- data/README.md +3 -3
- data/lib/template_form/base_input.rb +1 -1
- data/lib/template_form/date_select_input.rb +84 -0
- data/lib/template_form/form_builder.rb +3 -1
- data/lib/template_form/version.rb +1 -1
- data/lib/template_form.rb +8 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aff3e126bc47f495ad38d2bc5e5ac812383ab514122dc74512102404dd0c22f
|
4
|
+
data.tar.gz: 044c58d8cee13e9d154dff0f2ddceed9fcee9baeedd022e724de7c640d0cfee1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a45dd537b78ed56907aecea11bdad44d93bd4affbcfe4f70d3dd4cb4cb7949d8452047968195b782ea9a9cc9377eee4c4a80f21706cf1b444c56d1bcd582f04
|
7
|
+
data.tar.gz: 14af76a55463a878c94b91e162ffb573c8807fcf7a91dc0582a079a5db3379ff929f7ffd6768983aa41adfd58f9edb8ba748b7421f72da3c2146ad65766e739a
|
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
|
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/)
|
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
|
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
|
3
|
+
module TemplateForm
|
4
|
+
class DateSelectInput < BaseInput
|
5
|
+
|
6
|
+
OPTION_KEYS = %i[
|
7
|
+
use_month_numbers
|
8
|
+
use_two_digit_numbers
|
9
|
+
use_short_month
|
10
|
+
add_month_numbers
|
11
|
+
use_month_names
|
12
|
+
month_format_string
|
13
|
+
date_separator
|
14
|
+
time_separator
|
15
|
+
datetime_separator
|
16
|
+
start_year
|
17
|
+
end_year
|
18
|
+
year_format
|
19
|
+
day_format
|
20
|
+
discard_day
|
21
|
+
discard_month
|
22
|
+
discard_year
|
23
|
+
order
|
24
|
+
include_blank
|
25
|
+
default
|
26
|
+
selected
|
27
|
+
disabled
|
28
|
+
prompt
|
29
|
+
with_css_classes
|
30
|
+
use_hidden
|
31
|
+
]
|
32
|
+
|
33
|
+
def initialize(builder, attribute_name, options)
|
34
|
+
@builder = builder
|
35
|
+
@attribute_name = attribute_name
|
36
|
+
@view = options.delete(:view)
|
37
|
+
|
38
|
+
@form_type = options.delete(:form_type) || builder.form_type
|
39
|
+
|
40
|
+
# Use the `:label` option to override the default label text.
|
41
|
+
# Use `label: false` to indicate no label should be shown (check `has_label` in the template).
|
42
|
+
@has_label = !(options.has_key?(:label) && options[:label] == false)
|
43
|
+
@label_text = options.delete(:label) || ''
|
44
|
+
@label_options = Hash.new { |h,k| h[k] = '' }.update(options.delete(:label_options) || {})
|
45
|
+
|
46
|
+
@hint_text = options.delete(:hint) || ''
|
47
|
+
|
48
|
+
data_attributes = (options.delete(:data) || {}).transform_keys { |k| "data-#{k}" }
|
49
|
+
|
50
|
+
@options, @html_options = options.partition { |k,_| OPTION_KEYS.include? k }.map(&:to_h)
|
51
|
+
|
52
|
+
@html_options.merge! data_attributes
|
53
|
+
@html_options[:class] ||= ''
|
54
|
+
end
|
55
|
+
|
56
|
+
def render
|
57
|
+
template.render(
|
58
|
+
builder,
|
59
|
+
attribute_name: attribute_name,
|
60
|
+
view: view,
|
61
|
+
|
62
|
+
has_label: has_label,
|
63
|
+
label_text: label_text,
|
64
|
+
label_options: label_options,
|
65
|
+
|
66
|
+
hint_text: hint_text,
|
67
|
+
|
68
|
+
options: options,
|
69
|
+
html_options: html_options,
|
70
|
+
|
71
|
+
errors: errors,
|
72
|
+
).html_safe
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
attr_reader *%i[
|
78
|
+
view
|
79
|
+
html_options
|
80
|
+
options
|
81
|
+
]
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -8,6 +8,7 @@ require 'template_form/select_input'
|
|
8
8
|
require 'template_form/text_input'
|
9
9
|
require 'template_form/textarea_input'
|
10
10
|
require 'template_form/date_input'
|
11
|
+
require 'template_form/date_select_input'
|
11
12
|
require 'template_form/file_input'
|
12
13
|
|
13
14
|
module TemplateForm
|
@@ -32,7 +33,7 @@ module TemplateForm
|
|
32
33
|
|
33
34
|
options[:type] ||= 'password' if attribute_name.match(/password/)
|
34
35
|
|
35
|
-
options.merge! view: @view
|
36
|
+
options.merge! view: @view if @view
|
36
37
|
|
37
38
|
input_for(attribute_type).new(self, attribute_name, options).render
|
38
39
|
end
|
@@ -50,6 +51,7 @@ module TemplateForm
|
|
50
51
|
when :string then TextInput
|
51
52
|
when :text then TextareaInput
|
52
53
|
when :date then DateInput
|
54
|
+
when :date_select then DateSelectInput
|
53
55
|
when :boolean then CheckboxInput
|
54
56
|
when :file then FileInput
|
55
57
|
when :select then SelectInput
|
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.
|
4
|
+
version: 0.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/template_form/base_input.rb
|
100
100
|
- lib/template_form/checkbox_input.rb
|
101
101
|
- lib/template_form/date_input.rb
|
102
|
+
- lib/template_form/date_select_input.rb
|
102
103
|
- lib/template_form/errors.rb
|
103
104
|
- lib/template_form/file_input.rb
|
104
105
|
- lib/template_form/form_builder.rb
|
@@ -137,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
138
|
- !ruby/object:Gem::Version
|
138
139
|
version: '0'
|
139
140
|
requirements: []
|
140
|
-
rubygems_version: 3.
|
141
|
+
rubygems_version: 3.5.11
|
141
142
|
signing_key:
|
142
143
|
specification_version: 4
|
143
144
|
summary: A template-based form builder for Rails.
|