bulma_form_rails 0.9.1
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 +7 -0
- data/.idea/.gitignore +8 -0
- data/.idea/bulma_form_rails.iml +82 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/misc.xml +7 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rbenv-gemsets +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +203 -0
- data/LICENSE +29 -0
- data/README.md +163 -0
- data/Rakefile +11 -0
- data/doc/BulmaFormRails/Helpers.html +698 -0
- data/doc/BulmaFormRails.html +93 -0
- data/doc/created.rid +2 -0
- data/doc/css/fonts.css +167 -0
- data/doc/css/rdoc.css +639 -0
- data/doc/fonts/Lato-Light.ttf +0 -0
- data/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/doc/fonts/Lato-Regular.ttf +0 -0
- data/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/moderngeosystems_logo.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +82 -0
- data/doc/js/darkfish.js +84 -0
- data/doc/js/navigation.js +105 -0
- data/doc/js/navigation.js.gz +0 -0
- data/doc/js/search.js +110 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/search_index.js.gz +0 -0
- data/doc/js/searcher.js +229 -0
- data/doc/js/searcher.js.gz +0 -0
- data/doc/table_of_contents.html +125 -0
- data/lib/bulma_form_rails/field_helpers.rb +239 -0
- data/lib/bulma_form_rails/form_page_helpers.rb +36 -0
- data/lib/bulma_form_rails/header_and_footer_helpers.rb +36 -0
- data/lib/bulma_form_rails/javascript/controllers/child_objects_controller.js +66 -0
- data/lib/bulma_form_rails/message_box_helpers.rb +25 -0
- data/lib/bulma_form_rails/railtie.rb +62 -0
- data/lib/bulma_form_rails/subform_helpers.rb +33 -0
- data/lib/bulma_form_rails/version.rb +3 -0
- data/lib/bulma_form_rails.rb +3 -0
- data/lib/generators/bulma_form_rails/pagy_config_generator.rb +15 -0
- data/lib/generators/bulma_form_rails/views_generator.rb +19 -0
- data/lib/install/bulma_form_rails.rb +13 -0
- data/lib/tasks/bulma_form_rails_tasks.rake +30 -0
- data/lib/templates/app/views/_form.html.erb +0 -0
- data/lib/templates/app/views/bulma_form_rails/_child.html.erb +61 -0
- data/lib/templates/app/views/bulma_form_rails/_children.html.erb +61 -0
- data/lib/templates/app/views/bulma_form_rails/_datetime_select.html.erb +10 -0
- data/lib/templates/app/views/bulma_form_rails/_edit_form_page.html.erb +15 -0
- data/lib/templates/app/views/bulma_form_rails/_field.html.erb +10 -0
- data/lib/templates/app/views/bulma_form_rails/_form_footer.html.erb +17 -0
- data/lib/templates/app/views/bulma_form_rails/_index_header.html.erb +16 -0
- data/lib/templates/app/views/bulma_form_rails/_message_box.html.erb +35 -0
- data/lib/templates/app/views/bulma_form_rails/_new_form_page.html.erb +15 -0
- data/lib/templates/app/views/bulma_form_rails/_radio_group.html.erb +6 -0
- data/lib/templates/app/views/bulma_form_rails/_select.html.erb +7 -0
- data/lib/templates/app/views/bulma_form_rails/_time_select.html.erb +10 -0
- data/lib/templates/app/views/bulma_form_rails/_validation_box.html.erb +15 -0
- data/lib/templates/app/views/bulma_form_rails/_value.html.erb +6 -0
- data/lib/templates/config/initializers/pagy.rb +211 -0
- data/package.json +45 -0
- data/sig/bulma_form_helper.rbs +68 -0
- data/yarn.lock +53 -0
- metadata +291 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>Table of Contents - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "./";
|
11
|
+
var index_rel_prefix = "./";
|
12
|
+
</script>
|
13
|
+
|
14
|
+
<script src="./js/navigation.js" defer></script>
|
15
|
+
<script src="./js/search.js" defer></script>
|
16
|
+
<script src="./js/search_index.js" defer></script>
|
17
|
+
<script src="./js/searcher.js" defer></script>
|
18
|
+
<script src="./js/darkfish.js" defer></script>
|
19
|
+
|
20
|
+
<link href="./css/fonts.css" rel="stylesheet">
|
21
|
+
<link href="./css/rdoc.css" rel="stylesheet">
|
22
|
+
|
23
|
+
|
24
|
+
<body id="top" class="table-of-contents">
|
25
|
+
<main role="main">
|
26
|
+
<h1 class="class">Table of Contents - RDoc Documentation</h1>
|
27
|
+
|
28
|
+
|
29
|
+
<h2 id="classes">Classes and Modules</h2>
|
30
|
+
<ul>
|
31
|
+
<li class="module">
|
32
|
+
<a href="BulmaFormRails.html">BulmaFormRails</a>
|
33
|
+
</li>
|
34
|
+
<li class="module">
|
35
|
+
<a href="BulmaFormRails/Helpers.html">BulmaFormRails::Helpers</a>
|
36
|
+
</li>
|
37
|
+
</ul>
|
38
|
+
|
39
|
+
<h2 id="methods">Methods</h2>
|
40
|
+
<ul>
|
41
|
+
|
42
|
+
<li class="method">
|
43
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_check_box">#bulma_check_box</a>
|
44
|
+
—
|
45
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
46
|
+
|
47
|
+
<li class="method">
|
48
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_child_objects">#bulma_child_objects</a>
|
49
|
+
—
|
50
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
51
|
+
|
52
|
+
<li class="method">
|
53
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_custom_field">#bulma_custom_field</a>
|
54
|
+
—
|
55
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
56
|
+
|
57
|
+
<li class="method">
|
58
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_datetime_select">#bulma_datetime_select</a>
|
59
|
+
—
|
60
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
61
|
+
|
62
|
+
<li class="method">
|
63
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_edit_form_page">#bulma_edit_form_page</a>
|
64
|
+
—
|
65
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
66
|
+
|
67
|
+
<li class="method">
|
68
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_form_footer">#bulma_form_footer</a>
|
69
|
+
—
|
70
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
71
|
+
|
72
|
+
<li class="method">
|
73
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_index_header">#bulma_index_header</a>
|
74
|
+
—
|
75
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
76
|
+
|
77
|
+
<li class="method">
|
78
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_input">#bulma_input</a>
|
79
|
+
—
|
80
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
81
|
+
|
82
|
+
<li class="method">
|
83
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_message_box">#bulma_message_box</a>
|
84
|
+
—
|
85
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
86
|
+
|
87
|
+
<li class="method">
|
88
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_new_form_page">#bulma_new_form_page</a>
|
89
|
+
—
|
90
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
91
|
+
|
92
|
+
<li class="method">
|
93
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_radio_group">#bulma_radio_group</a>
|
94
|
+
—
|
95
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
96
|
+
|
97
|
+
<li class="method">
|
98
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_select">#bulma_select</a>
|
99
|
+
—
|
100
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
101
|
+
|
102
|
+
<li class="method">
|
103
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_text_area">#bulma_text_area</a>
|
104
|
+
—
|
105
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
106
|
+
|
107
|
+
<li class="method">
|
108
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_time_select">#bulma_time_select</a>
|
109
|
+
—
|
110
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
111
|
+
|
112
|
+
<li class="method">
|
113
|
+
<a href="BulmaFormRails/Helpers.html#method-i-bulma_validation_box">#bulma_validation_box</a>
|
114
|
+
—
|
115
|
+
<span class="container">BulmaFormRails::Helpers</span>
|
116
|
+
</ul>
|
117
|
+
</main>
|
118
|
+
|
119
|
+
|
120
|
+
<footer id="validator-badges" role="contentinfo">
|
121
|
+
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
122
|
+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.
|
123
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
124
|
+
</footer>
|
125
|
+
|
@@ -0,0 +1,239 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
# rdoc-image:images/moderngeosystems_logo.png
|
4
|
+
module BulmaFormRails
|
5
|
+
|
6
|
+
# rdoc-image:../images/moderngeosystems_logo.png
|
7
|
+
#
|
8
|
+
# This Ruby on Rails Helper module allows easy and efficient web form construction with labeled fields of different types.
|
9
|
+
# It also supports tabular editable multi-object subforms.
|
10
|
+
module FieldHelpers
|
11
|
+
|
12
|
+
# Render a labeled field with custom content.
|
13
|
+
# * +form_or_object+ - the form or object
|
14
|
+
# * +field_name+ - a symbol representing the name of the field as a whole, regardless of how many tags are in the specified ERb block
|
15
|
+
# * +options+ - a hash of additional options:
|
16
|
+
# * +label+ - custom field label text
|
17
|
+
# * +block+ - ERb to render the field value content
|
18
|
+
def bulma_custom_field(form_or_object, field_name, options = {}, &block)
|
19
|
+
# Prepare parameters.
|
20
|
+
raise ArgumentError.new('No block given for custom field') if !block_given?
|
21
|
+
render_parameters = prepare_common_parameters(field_name, form_or_object, options)
|
22
|
+
render_parameters.merge!(additional_field_label_classes: 'is-normal') unless options[:contains_check_box_or_radio_group]
|
23
|
+
|
24
|
+
# Render the labeled field.
|
25
|
+
render layout: 'bulma_form_rails/field', locals: render_parameters, &block
|
26
|
+
end
|
27
|
+
|
28
|
+
VALID_INPUT_TYPES = %i[color date datetime_local email file hidden month number password phone telephone text time url]
|
29
|
+
|
30
|
+
# Render a labeled input field.
|
31
|
+
# Mandatory parameters:
|
32
|
+
# * +form_or_object+ - the form or object
|
33
|
+
# * +field_name+ - a symbol representing the name of the field
|
34
|
+
# * +type+ - +:color+, +:date+, +:datetime_local+, +:email+, +:file+, +:hidden+, +:month+, +:number+, +:password+, +:phone+, +:telephone+, +:text+, +:time+, or +:url+ with optional +_field+ suffix
|
35
|
+
# * +options+ - a hash of additional options:
|
36
|
+
# * +class+ - additional input classes other than +input+
|
37
|
+
# * +label+ - custom field label text
|
38
|
+
def bulma_input(form_or_object, field_name, type = :text, options = {})
|
39
|
+
# Convert type to form method.
|
40
|
+
type = type.to_s
|
41
|
+
type.delete!('_field') if type.end_with?('_field')
|
42
|
+
raise ArgumentError.new("Invalid input type #{type.inspect}") unless VALID_INPUT_TYPES.any?(type.intern)
|
43
|
+
method = "#{type}_field".intern
|
44
|
+
|
45
|
+
# Prepare parameters.
|
46
|
+
prepare_value_class!(options, base_class: 'input')
|
47
|
+
render_parameters = prepare_common_parameters(field_name, form_or_object, options)
|
48
|
+
additional_render_parameters = %i[date_field datetime_local_field month_field time_field].any?(method) ? {additional_field_classes: 'is-narrow'} : {}
|
49
|
+
|
50
|
+
# Render the labeled field.
|
51
|
+
render layout: 'bulma_form_rails/field', locals: render_parameters.merge(additional_field_label_classes: 'is-normal') do
|
52
|
+
render partial: 'bulma_form_rails/value', locals: render_parameters.merge(method: method).merge(additional_render_parameters)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Render a labeled text area field.
|
57
|
+
# * +form_or_object+ - the form or object
|
58
|
+
# * +field_name+ - a symbol representing the name of the field
|
59
|
+
# * +options+ - a hash of additional options:
|
60
|
+
# * +class+ - additional textarea classes other than +textarea+
|
61
|
+
# * +label+ - custom field label text
|
62
|
+
# * +rows+ - number of text rows to be visible
|
63
|
+
# * +cols+ - number of text columns to be visible
|
64
|
+
def bulma_text_area(form_or_object, field_name, options = {})
|
65
|
+
# Prepare parameters.
|
66
|
+
prepare_value_class!(options, base_class: 'textarea')
|
67
|
+
render_parameters = prepare_common_parameters(field_name, form_or_object, options)
|
68
|
+
|
69
|
+
# Render the labeled field.
|
70
|
+
render layout: 'bulma_form_rails/field', locals: render_parameters.merge(additional_field_label_classes: 'is-normal') do
|
71
|
+
render partial: 'bulma_form_rails/value', locals: render_parameters.merge(method: :text_area)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Render a labeled checkbox field.
|
76
|
+
# * +form_or_object+ - the form or object
|
77
|
+
# * +field_name+ - a symbol representing the name of the field
|
78
|
+
# * +options+ - a hash of additional options:
|
79
|
+
# * +class+ - additional checkbox classes other than +checkbox+
|
80
|
+
# * +label+ - custom field label text
|
81
|
+
def bulma_check_box(form_or_object, field_name, options = {})
|
82
|
+
# Prepare parameters.
|
83
|
+
prepare_value_class!(options, base_class: 'checkbox')
|
84
|
+
render_parameters = prepare_common_parameters(field_name, form_or_object, options)
|
85
|
+
|
86
|
+
# Render the labeled field.
|
87
|
+
render layout: 'bulma_form_rails/field', locals: render_parameters do
|
88
|
+
render partial: 'bulma_form_rails/value', locals: render_parameters.merge(method: :check_box, additional_field_classes: 'is-narrow')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Render a labeled radio group field.
|
93
|
+
# * +form_or_object+ - the form or object
|
94
|
+
# * +field_name+ - a symbol representing the name of the field as a whole, regardless of how many radio buttons are generated by +choices+
|
95
|
+
# * +choices+ - an array of radio button choice options
|
96
|
+
# * +options+ - an array of additional options
|
97
|
+
# * +class+ - additional radio classes other than +radio+
|
98
|
+
# * +label+ - custom field label text
|
99
|
+
def bulma_radio_group(form_or_object, field_name, choices, options = {})
|
100
|
+
# Prepare parameters.
|
101
|
+
prepare_value_class!(options, base_class: 'radio')
|
102
|
+
render_parameters = prepare_common_parameters(field_name, form_or_object, options)
|
103
|
+
|
104
|
+
# Render the labeled field.
|
105
|
+
render layout: 'bulma_form_rails/field', locals: render_parameters do
|
106
|
+
render partial: 'bulma_form_rails/radio_group', locals: render_parameters.merge(choices: choices)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Render a labeled selection field.
|
111
|
+
# * +form_or_object+ - the form or object
|
112
|
+
# * +field_name+ - a symbol representing the name of the field
|
113
|
+
# * +choices+ - an array of select choice options
|
114
|
+
# * +options+ - a hash of additional options
|
115
|
+
# * +class+ - additional select classes other than +select+
|
116
|
+
# * +label+ - custom field label text
|
117
|
+
# * +html_options+ - a hash of additional options:
|
118
|
+
def bulma_select(form_or_object, field_name, choices, options = {}, html_options = {})
|
119
|
+
# Prepare parameters.
|
120
|
+
prepare_value_class!(options, base_class: 'select is-fullwidth')
|
121
|
+
render_parameters = prepare_common_parameters(field_name, form_or_object, options)
|
122
|
+
|
123
|
+
# Render the labeled field.
|
124
|
+
render layout: 'bulma_form_rails/field', locals: render_parameters.merge(additional_field_label_classes: 'is-normal') do
|
125
|
+
render partial: 'bulma_form_rails/select', locals: render_parameters.merge(choices: choices, html_options: html_options)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Render a labeled date+time selection field.
|
130
|
+
# * +form_or_object+ - the form or object
|
131
|
+
# * +field_name+ - a symbol representing the name of the field
|
132
|
+
# * +options+ - a hash of additional options
|
133
|
+
# * +html_options+ - a hash of additional options:
|
134
|
+
# * +class+ - additional select classes other than +select+
|
135
|
+
# * +label+ - custom field label text
|
136
|
+
def bulma_datetime_select(form_or_object, field_name, options = {}, html_options = {})
|
137
|
+
# Prepare parameters.
|
138
|
+
prepare_value_class!(options, base_class: 'select is-fullwidth')
|
139
|
+
render_parameters = prepare_common_parameters(field_name, form_or_object, options)
|
140
|
+
|
141
|
+
# Render the labeled field.
|
142
|
+
render layout: 'bulma_form_rails/field', locals: render_parameters.merge(additional_field_label_classes: 'is-normal') do
|
143
|
+
render partial: 'bulma_form_rails/datetime_select', locals: render_parameters.merge(html_options: html_options)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Render a labeled time selection field.
|
148
|
+
# * +form_or_object+ - the form or object
|
149
|
+
# * +field_name+ - a symbol representing the name of the field
|
150
|
+
# * +options+ - a hash of additional options
|
151
|
+
# * +html_options+ - a hash of additional options:
|
152
|
+
# * +class+ - additional select classes other than +select+
|
153
|
+
# * +label+ - custom field label text
|
154
|
+
def bulma_time_select(form_or_object, field_name, options = {}, html_options = {})
|
155
|
+
# Prepare parameters.
|
156
|
+
prepare_value_class!(options, base_class: 'select is-fullwidth')
|
157
|
+
render_parameters = prepare_common_parameters(field_name, form_or_object, options)
|
158
|
+
|
159
|
+
# Render the labeled field.
|
160
|
+
render layout: 'bulma_form_rails/field', locals: render_parameters.merge(additional_field_label_classes: 'is-normal') do
|
161
|
+
render partial: 'bulma_form_rails/time_select', locals: render_parameters.merge(html_options: html_options)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
private
|
166
|
+
|
167
|
+
# Render time selection tags modified for bulma compatibility.
|
168
|
+
def bulma_datetime_select_tags(html)
|
169
|
+
# Parse the template-generated HTML, wrapping it in a div to ensure a single root element.
|
170
|
+
source = if html =~ /\A\s*<div/
|
171
|
+
html
|
172
|
+
else
|
173
|
+
"<div>#{html}</div>"
|
174
|
+
end
|
175
|
+
document = REXML::Document.new(source)
|
176
|
+
root = document.root
|
177
|
+
|
178
|
+
# Remove all non-functional text nodes
|
179
|
+
root.delete_if {|child| child.instance_of?(REXML::Text)}
|
180
|
+
|
181
|
+
# Subsume all select elements under their own bulma span tags.
|
182
|
+
root.each_element do |element|
|
183
|
+
if element.name == "select"
|
184
|
+
# Create the span.
|
185
|
+
span = REXML::Element.new('span')
|
186
|
+
span.add_attribute('class', 'control')
|
187
|
+
span.add_attribute('style', 'display: inline-block')
|
188
|
+
|
189
|
+
# Reparent the select.
|
190
|
+
root.add_element(span)
|
191
|
+
span.add_element(element)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Emit the modified HTML.
|
196
|
+
output = ""
|
197
|
+
document.write(output)
|
198
|
+
output
|
199
|
+
end
|
200
|
+
|
201
|
+
# Render any form element, regardless of whether a form builder or object name is provided.
|
202
|
+
def bulma_form_or_object_component(form_or_object, method, *params)
|
203
|
+
if form_or_object.kind_of?(ActionView::Helpers::FormBuilder)
|
204
|
+
form_or_object.public_send(method, *params)
|
205
|
+
else
|
206
|
+
self.public_send(method, *([form_or_object] + params))
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def prepare_common_parameters(field_name, form_or_object, options)
|
211
|
+
{ form_or_object: form_or_object, field_name: field_name, label_parameters: prepare_label_parameters(field_name, options), options: options }
|
212
|
+
end
|
213
|
+
|
214
|
+
# Grab and purge the textual field label from options if specified.
|
215
|
+
def prepare_label_parameters(field_name, options)
|
216
|
+
label_parameters = [field_name]
|
217
|
+
field_label = options[:label]
|
218
|
+
if field_label
|
219
|
+
label_parameters << field_label
|
220
|
+
options.delete(:label)
|
221
|
+
end
|
222
|
+
label_parameters << { class: 'label' }
|
223
|
+
end
|
224
|
+
|
225
|
+
# Grab and purge value CSS classes from options if specified.
|
226
|
+
def prepare_value_class!(options, base_class: String)
|
227
|
+
additional_classes = options[:class]
|
228
|
+
if additional_classes
|
229
|
+
additional_classes = " #{additional_classes}"
|
230
|
+
options.delete(:class)
|
231
|
+
else
|
232
|
+
additional_classes = ''
|
233
|
+
end
|
234
|
+
options[:class] = base_class + additional_classes
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
# rdoc-image:images/moderngeosystems_logo.png
|
4
|
+
module BulmaFormRails
|
5
|
+
|
6
|
+
# rdoc-image:../images/moderngeosystems_logo.png
|
7
|
+
#
|
8
|
+
# This Ruby on Rails Helper module allows easy and efficient web form construction with labeled fields of different types.
|
9
|
+
# It also supports tabular editable multi-object subforms.
|
10
|
+
module FormPageHelpers
|
11
|
+
|
12
|
+
# Render a standard model creation form page.
|
13
|
+
# * +name+ - a symbol representing the model name
|
14
|
+
# * +model+ - the model object
|
15
|
+
# * +models_path+ - the controller URL path for the action that renders the model collection
|
16
|
+
def bulma_new_form_page(name, model, models_path)
|
17
|
+
render partial: 'bulma_form_rails/new_form_page', locals: {name: name, model: model, models_path: models_path}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Render a standard model edit form page.
|
21
|
+
# * +name+ - a symbol representing the model name
|
22
|
+
# * +model+ - the model object
|
23
|
+
# * +models_path+ - the controller URL path for the action that renders the model collection
|
24
|
+
# * +model_path+ - the controller URL path for the action that renders this individual model
|
25
|
+
def bulma_edit_form_page(name, model, models_path, model_path)
|
26
|
+
render partial: 'bulma_form_rails/edit_form_page', locals: {name: name, model: model, models_path: models_path, model_path: model_path}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Render a standard flash messages box. Automatically included with +bulma_validation_box+ and +bulma_index_header+ output.
|
30
|
+
def bulma_message_box
|
31
|
+
render partial: 'bulma_form_rails/message_box'
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
# rdoc-image:images/moderngeosystems_logo.png
|
4
|
+
module BulmaFormRails
|
5
|
+
|
6
|
+
# rdoc-image:../images/moderngeosystems_logo.png
|
7
|
+
#
|
8
|
+
# This Ruby on Rails Helper module allows easy and efficient web form construction with labeled fields of different types.
|
9
|
+
# It also supports tabular editable multi-object subforms.
|
10
|
+
module HeaderAndFooterHelpers
|
11
|
+
|
12
|
+
# Render the header for a standard index page. Automatically calls +bulma_message_box+.
|
13
|
+
# * +name+ - a symbol representing the model name
|
14
|
+
# * +models_path+ - the controller URL path for the action that renders the model collection
|
15
|
+
def bulma_index_header(name, models_path)
|
16
|
+
render partial: 'bulma_form_rails/index_header', locals: {name: name, models_path: models_path}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Render a standard model form page footer.
|
20
|
+
# * +form+ - the form object
|
21
|
+
# * +models_path+ - the controller URL path for the action that renders the model collection
|
22
|
+
# * +options+ - a hash of additional options:
|
23
|
+
# * +exclude_submit_button+ - don't include a submit button if true
|
24
|
+
# * +block+ - optional ERb to render any additional content for the footer, such as additional buttons
|
25
|
+
def bulma_form_footer(form, models_path, options = {}, &block)
|
26
|
+
if block_given?
|
27
|
+
render layout: 'bulma_form_rails/form_footer', locals: {form: form, url: models_path, options: options}, &block
|
28
|
+
else
|
29
|
+
render partial: 'bulma_form_rails/form_footer', locals: {form: form, url: models_path, options: options}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
import { put } from "@rails/request.js"
|
3
|
+
|
4
|
+
// Connects to data-controller="child-objects"
|
5
|
+
export default class extends Controller
|
6
|
+
{
|
7
|
+
static targets = ["table"]
|
8
|
+
static values =
|
9
|
+
{
|
10
|
+
name: String,
|
11
|
+
attributesKey: String,
|
12
|
+
url: String
|
13
|
+
}
|
14
|
+
|
15
|
+
addRow(event)
|
16
|
+
{
|
17
|
+
// Remove existing adder bar.
|
18
|
+
const adderBarId = `${this.nameValue}-adder-bar`
|
19
|
+
document.getElementById(adderBarId).remove()
|
20
|
+
|
21
|
+
// Append new adder bar.
|
22
|
+
const tbody = this.tableTarget
|
23
|
+
|
24
|
+
let params = new URLSearchParams()
|
25
|
+
params.append("name", this.nameValue)
|
26
|
+
params.append("attributes_key", this.attributesKeyValue)
|
27
|
+
params.append("size", tbody.childElementCount - 2)
|
28
|
+
|
29
|
+
const new_row_url = `${this.urlValue}?${params}`
|
30
|
+
put(new_row_url, {responseKind: "turbo_stream"})
|
31
|
+
}
|
32
|
+
|
33
|
+
deleteRow(event)
|
34
|
+
{
|
35
|
+
const tbody = this.tableTarget
|
36
|
+
|
37
|
+
if (tbody.childElementCount > 3)
|
38
|
+
{
|
39
|
+
// Remove the specified row.
|
40
|
+
const targetRowId = event.target.parentNode.parentNode.id;
|
41
|
+
const rowIdName = this.nameFromId(targetRowId)
|
42
|
+
const targetRowIndex = this.indexFromId(targetRowId)
|
43
|
+
const targetRow = document.getElementById(targetRowId)
|
44
|
+
targetRow.remove()
|
45
|
+
|
46
|
+
// Renumber the remaining rows.
|
47
|
+
for (let i = targetRowIndex + 1; i < tbody.children.length - 1; i++)
|
48
|
+
{
|
49
|
+
let row = tbody.children[i]
|
50
|
+
let newRowIndex = i - 1
|
51
|
+
row.id = `${rowIdName}[${newRowIndex}]`
|
52
|
+
for (let cell of row.children)
|
53
|
+
{
|
54
|
+
for (let field of cell.children)
|
55
|
+
{
|
56
|
+
field.id = field.id.replace(`_${i}_`, `_${newRowIndex}_`)
|
57
|
+
field.name = field.name.replace(`[${i}]`, `[${newRowIndex}]`)
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
nameFromId(id) { return id.substring(0, id.indexOf("[")) }
|
65
|
+
indexFromId(id) { return parseInt(id.slice(id.search(/\[\d+\]$/) + 1, -1)) }
|
66
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
# rdoc-image:images/moderngeosystems_logo.png
|
4
|
+
module BulmaFormRails
|
5
|
+
|
6
|
+
# rdoc-image:../images/moderngeosystems_logo.png
|
7
|
+
#
|
8
|
+
# This Ruby on Rails Helper module allows easy and efficient web form construction with labeled fields of different types.
|
9
|
+
# It also supports tabular editable multi-object subforms.
|
10
|
+
module MessageBoxHelpers
|
11
|
+
|
12
|
+
# Render a standard flash messages box. Automatically included with +bulma_validation_box+ and +bulma_index_header+ output.
|
13
|
+
def bulma_message_box
|
14
|
+
render partial: 'bulma_form_rails/message_box'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Render a standard model validation messages box. Automatically calls +bulma_message_box+.
|
18
|
+
# * +model+ - the model object
|
19
|
+
def bulma_validation_box(model)
|
20
|
+
render partial: 'bulma_form_rails/validation_box', locals: {model: model}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'bulma_form_rails/field_helpers'
|
2
|
+
require 'bulma_form_rails/form_page_helpers'
|
3
|
+
require 'bulma_form_rails/header_and_footer_helpers'
|
4
|
+
require 'bulma_form_rails/message_box_helpers'
|
5
|
+
require 'bulma_form_rails/subform_helpers'
|
6
|
+
|
7
|
+
module BulmaFormRails
|
8
|
+
class Railtie < Rails::Railtie
|
9
|
+
railtie_name :bulma_form_rails
|
10
|
+
|
11
|
+
rake_tasks do
|
12
|
+
path = File.expand_path(__dir__)
|
13
|
+
Dir.glob("#{path}/../tasks/**/*.rake").each {|filename| load filename}
|
14
|
+
end
|
15
|
+
|
16
|
+
VIEW_PATH = 'lib/templates/app/views'
|
17
|
+
|
18
|
+
@@bulma_form_initializer = Proc.new do
|
19
|
+
ActionView::Helpers.send :include, FieldHelpers
|
20
|
+
ActionView::Helpers.send :include, FormPageHelpers
|
21
|
+
ActionView::Helpers.send :include, HeaderAndFooterHelpers
|
22
|
+
ActionView::Helpers.send :include, MessageBoxHelpers
|
23
|
+
ActionView::Helpers.send :include, SubformHelpers
|
24
|
+
|
25
|
+
ActionController::Base.class_eval do
|
26
|
+
append_view_path VIEW_PATH
|
27
|
+
helper_method :lookup_attributes
|
28
|
+
|
29
|
+
def self.bulma_child_forms(attributes)
|
30
|
+
class_eval do
|
31
|
+
def add_child
|
32
|
+
# Protect against code injection
|
33
|
+
if not %r|\A[a-zA-Z_]+\Z|.match(params[:name])
|
34
|
+
raise ActiveRecord::RecordNotFound
|
35
|
+
end
|
36
|
+
@name = params[:name]
|
37
|
+
@attributes_key = params[:attributes_key]
|
38
|
+
@attributes = lookup_attributes(params[:attributes_key]) unless @attributes_key.blank?
|
39
|
+
@size = params[:size].to_i + 1
|
40
|
+
respond_to do |format|
|
41
|
+
format.turbo_stream do
|
42
|
+
render turbo_stream: turbo_stream.append("#{@name}-table",
|
43
|
+
partial: 'bulma_form_rails/child',
|
44
|
+
locals: {child: eval("#{@name.capitalize.gsub(/_(.)/) {|s| $1.capitalize }}.new"), child_counter: @size, name: @name, attributes: @attributes, attributes_key: @attributes_key, last: true, container: '', system_controlled: false})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
@@child_attributes = attributes
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def lookup_attributes(key)
|
55
|
+
@@child_attributes[key.to_sym]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
ActiveSupport.on_load(:action_controller, &@@bulma_form_initializer)
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
# rdoc-image:images/moderngeosystems_logo.png
|
4
|
+
module BulmaFormRails
|
5
|
+
|
6
|
+
# rdoc-image:../images/moderngeosystems_logo.png
|
7
|
+
#
|
8
|
+
# This Ruby on Rails Helper module allows easy and efficient web form construction with labeled fields of different types.
|
9
|
+
# It also supports tabular editable multi-object subforms.
|
10
|
+
module SubformHelpers
|
11
|
+
|
12
|
+
# Renders a child objects collection management UI subform, including row addition and deletion buttons by default.
|
13
|
+
# * +collection+ - an array of serializable objects
|
14
|
+
# * +name+ - the lower-case singular name of the object for display purposes
|
15
|
+
# * +attributes_key+ - a symbolic key into the attribute reference hash retrievable via the <tt>lookup_attributes(key)</tt> method defined on the controller as a +helper_method+, eg +:object+ for:
|
16
|
+
# {object: ["attribute_1", "attribute_2"]}
|
17
|
+
# * +add_child_path+ - the controller URL path for the action to add a child object to the collection
|
18
|
+
# * +options+ - a hash of additional options to pass to the partials
|
19
|
+
# * +system_controlled+ - +true+ if you want no row add or delete buttons, +false+ or unspecified if you do want add and delete buttons
|
20
|
+
# * +total_columns+ - an array of integers representing column numbers requiring arithmetic totals at the bottom of the subform, eg:
|
21
|
+
# [3, 4]
|
22
|
+
# * +container+ - a string representing an array index expression for a row if not a single index, eg:
|
23
|
+
# "[related_reservations][#{related_reservation_counter}]"
|
24
|
+
# To use this helper method, you will first need to do the following:
|
25
|
+
# 1. Call <tt>bulma_child_forms</tt> from the specific controller (but outside any existing method definitions) for your view, passing in a hash of the object collections to be managed along with their attributes, for example, <tt>{object1: %w[attr1 attr2], object2: %w[attr3 attr4]}</tt>.
|
26
|
+
# 2. Add a route to the <tt>add_child</tt> action for the same controller, for example, <tt>put 'users/add_child', to: 'users#add_child'</tt>.
|
27
|
+
def bulma_child_objects(collection, name, attributes_key, add_child_path, options = {})
|
28
|
+
render partial: 'bulma_form_rails/children', object: collection, locals: {url: add_child_path, name: name, attributes_key: attributes_key}.merge(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module BulmaFormRails
|
6
|
+
module Generators
|
7
|
+
class PagyConfigGenerator < Rails::Generators::Base
|
8
|
+
source_root File.expand_path('../../templates', __FILE__)
|
9
|
+
|
10
|
+
def copy_pagy_config
|
11
|
+
copy_file File.join(Gem.loaded_specs['bulma_form_rails'].full_gem_path, 'lib', 'templates', 'config', 'initializers', 'pagy.rb'), File.join('config', 'initializers', 'pagy.rb')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module BulmaFormRails
|
6
|
+
module Generators
|
7
|
+
class ViewsGenerator < Rails::Generators::Base
|
8
|
+
source_root File.expand_path('../../templates', __FILE__)
|
9
|
+
|
10
|
+
def copy_views
|
11
|
+
gem_directory = File.join(Gem.loaded_specs['bulma_form_rails'].full_gem_path, 'lib', 'templates', 'app', 'views', 'bulma_form_rails')
|
12
|
+
app_directory = File.join('app', 'views', 'bulma_form_rails')
|
13
|
+
Dir.each_child(gem_directory) do |template_file|
|
14
|
+
copy_file File.join(gem_directory, template_file), File.join(app_directory, template_file)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|