mega-safe-tool 0.0.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.
Files changed (171) hide show
  1. checksums.yaml +7 -0
  2. data/formtastic-6.0.0/Appraisals +23 -0
  3. data/formtastic-6.0.0/CONTRIBUTING.md +27 -0
  4. data/formtastic-6.0.0/Gemfile +8 -0
  5. data/formtastic-6.0.0/MIT-LICENSE +20 -0
  6. data/formtastic-6.0.0/README.md +600 -0
  7. data/formtastic-6.0.0/RELEASE_PROCESS +7 -0
  8. data/formtastic-6.0.0/Rakefile +54 -0
  9. data/formtastic-6.0.0/bin/appraisal +8 -0
  10. data/formtastic-6.0.0/formtastic.gemspec +45 -0
  11. data/formtastic-6.0.0/gemfiles/rails_72.gemfile +9 -0
  12. data/formtastic-6.0.0/gemfiles/rails_80.gemfile +9 -0
  13. data/formtastic-6.0.0/gemfiles/rails_81.gemfile +9 -0
  14. data/formtastic-6.0.0/gemfiles/rails_edge.gemfile +9 -0
  15. data/formtastic-6.0.0/lib/formtastic/action_class_finder.rb +19 -0
  16. data/formtastic-6.0.0/lib/formtastic/actions/base.rb +157 -0
  17. data/formtastic-6.0.0/lib/formtastic/actions/button_action.rb +68 -0
  18. data/formtastic-6.0.0/lib/formtastic/actions/buttonish.rb +18 -0
  19. data/formtastic-6.0.0/lib/formtastic/actions/input_action.rb +71 -0
  20. data/formtastic-6.0.0/lib/formtastic/actions/link_action.rb +89 -0
  21. data/formtastic-6.0.0/lib/formtastic/actions.rb +15 -0
  22. data/formtastic-6.0.0/lib/formtastic/deprecation.rb +6 -0
  23. data/formtastic-6.0.0/lib/formtastic/form_builder.rb +109 -0
  24. data/formtastic-6.0.0/lib/formtastic/helpers/action_helper.rb +115 -0
  25. data/formtastic-6.0.0/lib/formtastic/helpers/actions_helper.rb +169 -0
  26. data/formtastic-6.0.0/lib/formtastic/helpers/enum.rb +14 -0
  27. data/formtastic-6.0.0/lib/formtastic/helpers/errors_helper.rb +139 -0
  28. data/formtastic-6.0.0/lib/formtastic/helpers/fieldset_wrapper.rb +85 -0
  29. data/formtastic-6.0.0/lib/formtastic/helpers/file_column_detection.rb +17 -0
  30. data/formtastic-6.0.0/lib/formtastic/helpers/form_helper.rb +204 -0
  31. data/formtastic-6.0.0/lib/formtastic/helpers/input_helper.rb +349 -0
  32. data/formtastic-6.0.0/lib/formtastic/helpers/inputs_helper.rb +421 -0
  33. data/formtastic-6.0.0/lib/formtastic/helpers/reflection.rb +38 -0
  34. data/formtastic-6.0.0/lib/formtastic/helpers.rb +16 -0
  35. data/formtastic-6.0.0/lib/formtastic/html_attributes.rb +33 -0
  36. data/formtastic-6.0.0/lib/formtastic/i18n.rb +33 -0
  37. data/formtastic-6.0.0/lib/formtastic/input_class_finder.rb +19 -0
  38. data/formtastic-6.0.0/lib/formtastic/inputs/base/aria.rb +26 -0
  39. data/formtastic-6.0.0/lib/formtastic/inputs/base/associations.rb +32 -0
  40. data/formtastic-6.0.0/lib/formtastic/inputs/base/choices.rb +109 -0
  41. data/formtastic-6.0.0/lib/formtastic/inputs/base/collections.rb +158 -0
  42. data/formtastic-6.0.0/lib/formtastic/inputs/base/database.rb +20 -0
  43. data/formtastic-6.0.0/lib/formtastic/inputs/base/datetime_pickerish.rb +86 -0
  44. data/formtastic-6.0.0/lib/formtastic/inputs/base/errors.rb +59 -0
  45. data/formtastic-6.0.0/lib/formtastic/inputs/base/fileish.rb +24 -0
  46. data/formtastic-6.0.0/lib/formtastic/inputs/base/hints.rb +32 -0
  47. data/formtastic-6.0.0/lib/formtastic/inputs/base/html.rb +54 -0
  48. data/formtastic-6.0.0/lib/formtastic/inputs/base/labelling.rb +53 -0
  49. data/formtastic-6.0.0/lib/formtastic/inputs/base/naming.rb +43 -0
  50. data/formtastic-6.0.0/lib/formtastic/inputs/base/numeric.rb +51 -0
  51. data/formtastic-6.0.0/lib/formtastic/inputs/base/options.rb +18 -0
  52. data/formtastic-6.0.0/lib/formtastic/inputs/base/placeholder.rb +18 -0
  53. data/formtastic-6.0.0/lib/formtastic/inputs/base/stringish.rb +39 -0
  54. data/formtastic-6.0.0/lib/formtastic/inputs/base/timeish.rb +246 -0
  55. data/formtastic-6.0.0/lib/formtastic/inputs/base/validations.rb +250 -0
  56. data/formtastic-6.0.0/lib/formtastic/inputs/base/wrapping.rb +51 -0
  57. data/formtastic-6.0.0/lib/formtastic/inputs/base.rb +79 -0
  58. data/formtastic-6.0.0/lib/formtastic/inputs/boolean_input.rb +119 -0
  59. data/formtastic-6.0.0/lib/formtastic/inputs/check_boxes_input.rb +198 -0
  60. data/formtastic-6.0.0/lib/formtastic/inputs/color_input.rb +42 -0
  61. data/formtastic-6.0.0/lib/formtastic/inputs/country_input.rb +90 -0
  62. data/formtastic-6.0.0/lib/formtastic/inputs/datalist_input.rb +42 -0
  63. data/formtastic-6.0.0/lib/formtastic/inputs/date_picker_input.rb +94 -0
  64. data/formtastic-6.0.0/lib/formtastic/inputs/date_select_input.rb +35 -0
  65. data/formtastic-6.0.0/lib/formtastic/inputs/datetime_picker_input.rb +104 -0
  66. data/formtastic-6.0.0/lib/formtastic/inputs/datetime_select_input.rb +13 -0
  67. data/formtastic-6.0.0/lib/formtastic/inputs/email_input.rb +42 -0
  68. data/formtastic-6.0.0/lib/formtastic/inputs/file_input.rb +43 -0
  69. data/formtastic-6.0.0/lib/formtastic/inputs/hidden_input.rb +63 -0
  70. data/formtastic-6.0.0/lib/formtastic/inputs/number_input.rb +89 -0
  71. data/formtastic-6.0.0/lib/formtastic/inputs/password_input.rb +42 -0
  72. data/formtastic-6.0.0/lib/formtastic/inputs/phone_input.rb +43 -0
  73. data/formtastic-6.0.0/lib/formtastic/inputs/radio_input.rb +164 -0
  74. data/formtastic-6.0.0/lib/formtastic/inputs/range_input.rb +96 -0
  75. data/formtastic-6.0.0/lib/formtastic/inputs/search_input.rb +42 -0
  76. data/formtastic-6.0.0/lib/formtastic/inputs/select_input.rb +236 -0
  77. data/formtastic-6.0.0/lib/formtastic/inputs/string_input.rb +37 -0
  78. data/formtastic-6.0.0/lib/formtastic/inputs/text_input.rb +49 -0
  79. data/formtastic-6.0.0/lib/formtastic/inputs/time_picker_input.rb +100 -0
  80. data/formtastic-6.0.0/lib/formtastic/inputs/time_select_input.rb +39 -0
  81. data/formtastic-6.0.0/lib/formtastic/inputs/time_zone_input.rb +59 -0
  82. data/formtastic-6.0.0/lib/formtastic/inputs/url_input.rb +42 -0
  83. data/formtastic-6.0.0/lib/formtastic/inputs.rb +43 -0
  84. data/formtastic-6.0.0/lib/formtastic/localized_string.rb +18 -0
  85. data/formtastic-6.0.0/lib/formtastic/localizer.rb +151 -0
  86. data/formtastic-6.0.0/lib/formtastic/namespaced_class_finder.rb +98 -0
  87. data/formtastic-6.0.0/lib/formtastic/version.rb +4 -0
  88. data/formtastic-6.0.0/lib/formtastic.rb +48 -0
  89. data/formtastic-6.0.0/lib/generators/formtastic/form/form_generator.rb +111 -0
  90. data/formtastic-6.0.0/lib/generators/formtastic/input/input_generator.rb +47 -0
  91. data/formtastic-6.0.0/lib/generators/formtastic/install/install_generator.rb +23 -0
  92. data/formtastic-6.0.0/lib/generators/formtastic/stylesheets/stylesheets_generator.rb +15 -0
  93. data/formtastic-6.0.0/lib/generators/templates/_form.html.erb +11 -0
  94. data/formtastic-6.0.0/lib/generators/templates/_form.html.haml +8 -0
  95. data/formtastic-6.0.0/lib/generators/templates/_form.html.slim +8 -0
  96. data/formtastic-6.0.0/lib/generators/templates/formtastic.css +289 -0
  97. data/formtastic-6.0.0/lib/generators/templates/formtastic.rb +118 -0
  98. data/formtastic-6.0.0/lib/generators/templates/input.rb +19 -0
  99. data/formtastic-6.0.0/lib/locale/en.yml +10 -0
  100. data/formtastic-6.0.0/sample/basic_inputs.html +224 -0
  101. data/formtastic-6.0.0/sample/config.ru +69 -0
  102. data/formtastic-6.0.0/sample/index.html +14 -0
  103. data/formtastic-6.0.0/script/integration-template.rb +76 -0
  104. data/formtastic-6.0.0/script/integration.sh +32 -0
  105. data/formtastic-6.0.0/spec/action_class_finder_spec.rb +12 -0
  106. data/formtastic-6.0.0/spec/actions/button_action_spec.rb +63 -0
  107. data/formtastic-6.0.0/spec/actions/generic_action_spec.rb +521 -0
  108. data/formtastic-6.0.0/spec/actions/input_action_spec.rb +59 -0
  109. data/formtastic-6.0.0/spec/actions/link_action_spec.rb +92 -0
  110. data/formtastic-6.0.0/spec/builder/custom_builder_spec.rb +132 -0
  111. data/formtastic-6.0.0/spec/builder/error_proc_spec.rb +27 -0
  112. data/formtastic-6.0.0/spec/builder/semantic_fields_for_spec.rb +213 -0
  113. data/formtastic-6.0.0/spec/fast_spec_helper.rb +12 -0
  114. data/formtastic-6.0.0/spec/generators/formtastic/form/form_generator_spec.rb +132 -0
  115. data/formtastic-6.0.0/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
  116. data/formtastic-6.0.0/spec/generators/formtastic/install/install_generator_spec.rb +48 -0
  117. data/formtastic-6.0.0/spec/generators/formtastic/stylesheets/stylesheets_generator_spec.rb +22 -0
  118. data/formtastic-6.0.0/spec/helpers/action_helper_spec.rb +338 -0
  119. data/formtastic-6.0.0/spec/helpers/actions_helper_spec.rb +143 -0
  120. data/formtastic-6.0.0/spec/helpers/form_helper_spec.rb +224 -0
  121. data/formtastic-6.0.0/spec/helpers/input_helper_spec.rb +991 -0
  122. data/formtastic-6.0.0/spec/helpers/inputs_helper_spec.rb +669 -0
  123. data/formtastic-6.0.0/spec/helpers/reflection_helper_spec.rb +32 -0
  124. data/formtastic-6.0.0/spec/helpers/semantic_errors_helper_spec.rb +220 -0
  125. data/formtastic-6.0.0/spec/i18n_spec.rb +210 -0
  126. data/formtastic-6.0.0/spec/input_class_finder_spec.rb +10 -0
  127. data/formtastic-6.0.0/spec/inputs/base/collections_spec.rb +119 -0
  128. data/formtastic-6.0.0/spec/inputs/base/validations_spec.rb +481 -0
  129. data/formtastic-6.0.0/spec/inputs/boolean_input_spec.rb +254 -0
  130. data/formtastic-6.0.0/spec/inputs/check_boxes_input_spec.rb +547 -0
  131. data/formtastic-6.0.0/spec/inputs/color_input_spec.rb +85 -0
  132. data/formtastic-6.0.0/spec/inputs/country_input_spec.rb +133 -0
  133. data/formtastic-6.0.0/spec/inputs/custom_input_spec.rb +51 -0
  134. data/formtastic-6.0.0/spec/inputs/datalist_input_spec.rb +61 -0
  135. data/formtastic-6.0.0/spec/inputs/date_picker_input_spec.rb +449 -0
  136. data/formtastic-6.0.0/spec/inputs/date_select_input_spec.rb +249 -0
  137. data/formtastic-6.0.0/spec/inputs/datetime_picker_input_spec.rb +490 -0
  138. data/formtastic-6.0.0/spec/inputs/datetime_select_input_spec.rb +209 -0
  139. data/formtastic-6.0.0/spec/inputs/email_input_spec.rb +85 -0
  140. data/formtastic-6.0.0/spec/inputs/file_input_spec.rb +89 -0
  141. data/formtastic-6.0.0/spec/inputs/hidden_input_spec.rb +135 -0
  142. data/formtastic-6.0.0/spec/inputs/include_blank_spec.rb +78 -0
  143. data/formtastic-6.0.0/spec/inputs/label_spec.rb +181 -0
  144. data/formtastic-6.0.0/spec/inputs/number_input_spec.rb +815 -0
  145. data/formtastic-6.0.0/spec/inputs/password_input_spec.rb +99 -0
  146. data/formtastic-6.0.0/spec/inputs/phone_input_spec.rb +85 -0
  147. data/formtastic-6.0.0/spec/inputs/placeholder_spec.rb +71 -0
  148. data/formtastic-6.0.0/spec/inputs/radio_input_spec.rb +326 -0
  149. data/formtastic-6.0.0/spec/inputs/range_input_spec.rb +505 -0
  150. data/formtastic-6.0.0/spec/inputs/readonly_spec.rb +50 -0
  151. data/formtastic-6.0.0/spec/inputs/search_input_spec.rb +84 -0
  152. data/formtastic-6.0.0/spec/inputs/select_input_spec.rb +661 -0
  153. data/formtastic-6.0.0/spec/inputs/string_input_spec.rb +326 -0
  154. data/formtastic-6.0.0/spec/inputs/text_input_spec.rb +187 -0
  155. data/formtastic-6.0.0/spec/inputs/time_picker_input_spec.rb +455 -0
  156. data/formtastic-6.0.0/spec/inputs/time_select_input_spec.rb +261 -0
  157. data/formtastic-6.0.0/spec/inputs/time_zone_input_spec.rb +143 -0
  158. data/formtastic-6.0.0/spec/inputs/url_input_spec.rb +85 -0
  159. data/formtastic-6.0.0/spec/inputs/with_options_spec.rb +43 -0
  160. data/formtastic-6.0.0/spec/localizer_spec.rb +130 -0
  161. data/formtastic-6.0.0/spec/namespaced_class_finder_spec.rb +90 -0
  162. data/formtastic-6.0.0/spec/schema.rb +22 -0
  163. data/formtastic-6.0.0/spec/spec.opts +2 -0
  164. data/formtastic-6.0.0/spec/spec_helper.rb +466 -0
  165. data/formtastic-6.0.0/spec/support/custom_macros.rb +570 -0
  166. data/formtastic-6.0.0/spec/support/deprecation.rb +7 -0
  167. data/formtastic-6.0.0/spec/support/shared_examples.rb +13 -0
  168. data/formtastic-6.0.0/spec/support/specialized_class_finder_shared_example.rb +27 -0
  169. data/formtastic-6.0.0/spec/support/test_environment.rb +46 -0
  170. data/mega-safe-tool.gemspec +11 -0
  171. metadata +209 -0
@@ -0,0 +1,600 @@
1
+ # Formtastic
2
+
3
+ [![Build Status](https://github.com/formtastic/formtastic/workflows/test/badge.svg)](https://github.com/formtastic/formtastic/actions)
4
+ [![Inline docs](https://inch-ci.org/github/justinfrench/formtastic.svg?branch=master)](https://inch-ci.org/github/justinfrench/formtastic)
5
+ [![Code Climate](https://qlty.sh/gh/formtastic/projects/formtastic/maintainability.svg)](https://qlty.sh/gh/formtastic/projects/formtastic)
6
+ [![Gem Version](https://badge.fury.io/rb/formtastic.svg)](https://badge.fury.io/rb/formtastic)
7
+
8
+ Formtastic is a Rails FormBuilder DSL (with some other goodies) to make it far easier to create beautiful, semantically rich, syntactically awesome, readily stylable and wonderfully accessible HTML forms in your Rails applications.
9
+
10
+ ## Documentation & Support
11
+
12
+ * [Documentation is available on rubydoc.info](https://rubydoc.info/github/formtastic/formtastic)
13
+ * [We track issues & bugs on GitHub](https://github.com/formtastic/formtastic/issues)
14
+ * [We have a wiki on GitHub](https://github.com/formtastic/formtastic/wiki)
15
+ * [StackOverflow can help](https://stackoverflow.com/questions/tagged/formtastic)
16
+
17
+ ## Compatibility
18
+
19
+ * Formtastic 6.x requires Rails 7.2 and Ruby 3.1 minimum, inline with Rails minimum supported versions
20
+ * Formtastic 5.x requires Rails 6.0 and Ruby 2.6 minimum
21
+ * Formtastic, much like Rails, is very ActiveRecord-centric. Many are successfully using other ActiveModel-like ORMs and objects (DataMapper, MongoMapper, Mongoid, Authlogic, Devise...) but we're not guaranteeing full compatibility at this stage. Patches are welcome!
22
+
23
+ ## The Story
24
+
25
+ One day, I finally had enough, so I opened up my text editor, and wrote a DSL for how I'd like to author forms:
26
+
27
+ ```erb
28
+ <%= semantic_form_for @article do |f| %>
29
+
30
+ <%= f.inputs :name => "Basic" do %>
31
+ <%= f.input :title %>
32
+ <%= f.input :body %>
33
+ <%= f.input :section %>
34
+ <%= f.input :publication_state, :as => :radio %>
35
+ <%= f.input :category %>
36
+ <%= f.input :allow_comments, :label => "Allow commenting on this article" %>
37
+ <% end %>
38
+
39
+ <%= f.inputs :name => "Advanced" do %>
40
+ <%= f.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
41
+ <%= f.input :extract, :required => false %>
42
+ <%= f.input :description, :required => false %>
43
+ <%= f.input :url_title, :required => false %>
44
+ <% end %>
45
+
46
+ <%= f.inputs :name => "Author", :for => :author do |author_form| %>
47
+ <%= author_form.input :first_name %>
48
+ <%= author_form.input :last_name %>
49
+ <% end %>
50
+
51
+ <%= f.actions do %>
52
+ <%= f.action :submit, :as => :button %>
53
+ <%= f.action :cancel, :as => :link %>
54
+ <% end %>
55
+
56
+ <% end %>
57
+ ```
58
+
59
+ I also wrote the accompanying HTML output I expected, favoring something very similar to the fieldsets, lists and other semantic elements Aaron Gustafson presented in [Learning to Love Forms](https://www.slideshare.net/slideshow/learning-to-love-forms-webvisions-07/45589), hacking together enough Ruby to prove it could be done.
60
+
61
+
62
+ ## It's awesome because...
63
+
64
+ * It can handle `belongs_to` associations (like Post belongs_to :author), rendering a select or set of radio inputs with choices from the parent model.
65
+ * It can handle `has_many` and `has_and_belongs_to_many` associations (like: Post has_many :tags), rendering a multi-select with choices from the child models.
66
+ * It's Rails 3/4 compatible (including nested forms).
67
+ * It has internationalization (I18n)!
68
+ * It's _really_ quick to get started with a basic form in place (4 lines), then go back to add in more detail if you need it.
69
+ * There's heaps of elements, id and class attributes for you to hook in your CSS and JS.
70
+ * It handles real world stuff like inline hints, inline error messages & help text.
71
+ * It doesn't hijack or change any of the standard Rails form inputs, so you can still use them as expected (even mix and match).
72
+ * It's got absolutely awesome spec coverage.
73
+ * There's a bunch of people using and working on it (it's not just one developer building half a solution).
74
+ * It has growing HTML5 support (new inputs like email/phone/search, new attributes like required/min/max/step/placeholder)
75
+
76
+
77
+ ## Opinions
78
+
79
+ * It should be easier to do things the right way than the wrong way.
80
+ * Sometimes _more mark-up_ is better.
81
+ * Elements and attribute hooks are _gold_ for stylesheet authors.
82
+ * Make the common things we do easy, yet ensure uncommon things are still possible.
83
+
84
+
85
+ ## Installation
86
+
87
+ Simply add Formtastic to your Gemfile and bundle it up:
88
+
89
+ ```ruby
90
+ gem 'formtastic', '~> 5.0'
91
+ ```
92
+
93
+ Run the installation generator:
94
+
95
+ ```shell
96
+ $ rails generate formtastic:install
97
+ ```
98
+
99
+
100
+ ## Stylesheets
101
+
102
+ An optional proof-of-concept stylesheet can be generated and installed into your app:
103
+
104
+ ```shell
105
+ $ rails generate formtastic:stylesheet
106
+ ```
107
+
108
+
109
+ ## Usage
110
+
111
+ Forms are really boring to code... you want to get onto the good stuff as fast as possible.
112
+
113
+ This renders a set of inputs (one for _most_ columns in the database table, and one for each ActiveRecord `belongs_to`-association), followed by default action buttons (an input submit button):
114
+
115
+ ```erb
116
+ <%= semantic_form_for @user do |f| %>
117
+ <%= f.inputs %>
118
+ <%= f.actions %>
119
+ <% end %>
120
+ ```
121
+
122
+ This is a great way to get something up fast, but like scaffolding, it's *not recommended for production*. Don't be so lazy!
123
+
124
+ To specify the order of the fields, skip some of the fields or even add in fields that Formtastic couldn't infer. You can pass in a list of field names to `inputs` and list of action names to `actions`:
125
+
126
+ ```erb
127
+ <%= semantic_form_for @user do |f| %>
128
+ <%= f.inputs :title, :body, :section, :categories, :created_at %>
129
+ <%= f.actions :submit, :cancel %>
130
+ <% end %>
131
+ ```
132
+
133
+ You probably want control over the input type Formtastic uses for each field. You can expand the `inputs` and `actions` to block helper format and use the `:as` option to specify an exact input type:
134
+
135
+ ```erb
136
+ <%= semantic_form_for @post do |f| %>
137
+ <%= f.inputs do %>
138
+ <%= f.input :title %>
139
+ <%= f.input :body %>
140
+ <%= f.input :section, :as => :radio %>
141
+ <%= f.input :categories %>
142
+ <%= f.input :created_at, :as => :string %>
143
+ <% end %>
144
+ <%= f.actions do %>
145
+ <%= f.action :submit, :as => :button %>
146
+ <%= f.action :cancel, :as => :link %>
147
+ <% end %>
148
+ <% end %>
149
+ ```
150
+
151
+ If you want to customize the label text, or render some hint text below the field, specify which fields are required/optional, or break the form into two fieldsets, the DSL is pretty comprehensive:
152
+
153
+ ```erb
154
+ <%= semantic_form_for @post do |f| %>
155
+ <%= f.inputs "Basic", :id => "basic" do %>
156
+ <%= f.input :title %>
157
+ <%= f.input :body %>
158
+ <% end %>
159
+ <%= f.inputs :name => "Advanced Options", :id => "advanced" do %>
160
+ <%= f.input :slug, :label => "URL Title", :hint => "Created automatically if left blank", :required => false %>
161
+ <%= f.input :section, :as => :radio %>
162
+ <%= f.input :user, :label => "Author" %>
163
+ <%= f.input :categories, :required => false %>
164
+ <%= f.input :created_at, :as => :string, :label => "Publication Date", :required => false %>
165
+ <% end %>
166
+ <%= f.actions do %>
167
+ <%= f.action :submit %>
168
+ <% end %>
169
+ <% end %>
170
+ ```
171
+
172
+ You can create forms for nested resources:
173
+
174
+ ```erb
175
+ <%= semantic_form_for [@author, @post] do |f| %>
176
+ ```
177
+
178
+ Nested forms are also supported (don't forget your models need to be setup correctly with `accepts_nested_attributes_for`). You can do it in the Rails way:
179
+
180
+ ```erb
181
+ <%= semantic_form_for @post do |f| %>
182
+ <%= f.inputs :title, :body, :created_at %>
183
+ <%= f.semantic_fields_for :author do |author| %>
184
+ <%= author.inputs :first_name, :last_name, :name => "Author" %>
185
+ <% end %>
186
+ <%= f.actions %>
187
+ <% end %>
188
+ ```
189
+
190
+ Or the Formtastic way with the `:for` option:
191
+
192
+ ```erb
193
+ <%= semantic_form_for @post do |f| %>
194
+ <%= f.inputs :title, :body, :created_at %>
195
+ <%= f.inputs :first_name, :last_name, :for => :author, :name => "Author" %>
196
+ <%= f.actions %>
197
+ <% end %>
198
+ ```
199
+
200
+ When working in has many association, you can even supply `"%i"` in your fieldset name; they will be properly interpolated with the child index. For example:
201
+
202
+ ```erb
203
+ <%= semantic_form_for @post do |f| %>
204
+ <%= f.inputs %>
205
+ <%= f.inputs :name => 'Category #%i', :for => :categories %>
206
+ <%= f.actions %>
207
+ <% end %>
208
+ ```
209
+
210
+ Alternatively, the current index can be accessed via the `inputs` block's arguments for use anywhere:
211
+
212
+ ```erb
213
+ <%= semantic_form_for @post do |f| %>
214
+ <%= f.inputs :for => :categories do |category, i| %>
215
+ ...
216
+ <%= f.actions %>
217
+ <% end %>
218
+ ```
219
+
220
+ If you have more than one form on the same page, it may lead to HTML invalidation because of the way HTML element id attributes are assigned. You can provide a namespace for your form to ensure uniqueness of id attributes on form elements. The namespace attribute will be prefixed with underscore on the generate HTML id. For example:
221
+
222
+ ```erb
223
+ <%= semantic_form_for(@post, :namespace => 'cat_form') do |f| %>
224
+ <%= f.inputs do %>
225
+ <%= f.input :title %> # id="cat_form_post_title"
226
+ <%= f.input :body %> # id="cat_form_post_body"
227
+ <%= f.input :created_at %> # id="cat_form_post_created_at"
228
+ <% end %>
229
+ <%= f.actions %>
230
+ <% end %>
231
+ ```
232
+
233
+ Customize HTML attributes for any input using the `:input_html` option. Typically this is used to disable the input, change the size of a text field, change the rows in a textarea, or even to add a special class to an input to attach special behavior like [autogrow](https://plugins.jquery.com/project/autogrowtextarea) textareas:
234
+
235
+ ```erb
236
+ <%= semantic_form_for @post do |f| %>
237
+ <%= f.inputs do %>
238
+ <%= f.input :title, :input_html => { :size => 10 } %>
239
+ <%= f.input :body, :input_html => { :class => 'autogrow', :rows => 10, :cols => 20, :maxlength => 10 } %>
240
+ <%= f.input :created_at, :input_html => { :disabled => true } %>
241
+ <%= f.input :updated_at, :input_html => { :readonly => true } %>
242
+ <% end %>
243
+ <%= f.actions %>
244
+ <% end %>
245
+ ```
246
+
247
+ The same can be done for actions with the `:button_html` option:
248
+
249
+ ```erb
250
+ <%= semantic_form_for @post do |f| %>
251
+ ...
252
+ <%= f.actions do %>
253
+ <%= f.action :submit, :button_html => { :class => "primary", :disable_with => 'Wait...' } %>
254
+ <% end %>
255
+ <% end %>
256
+ ```
257
+
258
+ Customize the HTML attributes for the `<li>` wrapper around every input with the `:wrapper_html` option hash. There's one special key in the hash: (`:class`), which will actually _append_ your string of classes to the existing classes provided by Formtastic (like `"required string error"`).
259
+
260
+ ```erb
261
+ <%= semantic_form_for @post do |f| %>
262
+ <%= f.inputs do %>
263
+ <%= f.input :title, :wrapper_html => { :class => "important" } %>
264
+ <%= f.input :body %>
265
+ <%= f.input :description, :wrapper_html => { :style => "display:none;" } %>
266
+ <% end %>
267
+ ...
268
+ <% end %>
269
+ ```
270
+
271
+ Many inputs provide a collection of options to choose from (like `:select`, `:radio`, `:check_boxes`, `:boolean`). In many cases, Formtastic can find choices through the model associations, but if you want to use your own set of choices, the `:collection` option is what you want. You can pass in an Array of objects, an array of Strings, a Hash... Throw almost anything at it! Examples:
272
+
273
+ ```ruby
274
+ f.input :authors, :as => :check_boxes, :collection => User.order("last_name ASC").all
275
+ f.input :authors, :as => :check_boxes, :collection => current_user.company.users.active
276
+ f.input :authors, :as => :check_boxes, :collection => [@justin, @kate]
277
+ f.input :authors, :as => :check_boxes, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
278
+ f.input :author, :as => :select, :collection => Author.all
279
+ f.input :author, :as => :select, :collection => Author.pluck(:first_name, :id)
280
+ f.input :author, :as => :select, :collection => Author.pluck(Arel.sql("CONCAT(`first_name`, ' ', `last_name`)"), :id)
281
+ f.input :author, :as => :select, :collection => Author.your_custom_scope_or_class_method
282
+ f.input :author, :as => :select, :collection => { @justin.name => @justin.id, @kate.name => @kate.id }
283
+ f.input :author, :as => :select, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
284
+ f.input :author, :as => :radio, :collection => User.all
285
+ f.input :author, :as => :radio, :collection => [@justin, @kate]
286
+ f.input :author, :as => :radio, :collection => { @justin.name => @justin.id, @kate.name => @kate.id }
287
+ f.input :author, :as => :radio, :collection => ["Justin", "Kate", "Amelia", "Gus", "Meg"]
288
+ f.input :admin, :as => :radio, :collection => ["Yes!", "No"]
289
+ f.input :book_id, :as => :select, :collection => Hash[Book.all.map{|b| [b.name,b.id]}]
290
+ f.input :fav_book,:as => :datalist , :collection => Book.pluck(:name)
291
+ ```
292
+
293
+
294
+ ## The Available Inputs
295
+
296
+ The Formtastic input types:
297
+
298
+ * `:select` - a select menu. Default for ActiveRecord associations: `belongs_to`, `has_many`, and `has_and_belongs_to_many`.
299
+ * `:check_boxes` - a set of check_box inputs. Alternative to `:select` for ActiveRecord-associations: `has_many`, and has_and_belongs_to_many`.
300
+ * `:radio` - a set of radio inputs. Alternative to `:select` for ActiveRecord-associations: `belongs_to`.
301
+ * `:time_zone` - a select input. Default for column types: `:string` with name matching `"time_zone"`.
302
+ * `:password` - a password input. Default for column types: `:string` with name matching `"password"`.
303
+ * `:text` - a textarea. Default for column types: `:text`.
304
+ * `:date_select` - a date select. Default for column types: `:date`.
305
+ * `:datetime_select` - a date and time select. Default for column types: `:datetime` and `:timestamp`.
306
+ * `:time_select` - a time select. Default for column types: `:time`.
307
+ * `:boolean` - a checkbox. Default for column types: `:boolean`.
308
+ * `:string` - a text field. Default for column types: `:string`.
309
+ * `:number` - a text field (just like string). Default for column types: `:integer`, `:float`, and `:decimal`.
310
+ * `:file` - a file field. Default for file-attachment attributes matching: [paperclip](https://github.com/thoughtbot/paperclip) or [attachment_fu](https://github.com/technoweenie/attachment_fu).
311
+ * `:country` - a select menu of country names. Default for column types: `:string` with name `"country"` - requires a *country_select* plugin to be installed.
312
+ * `:email` - a text field (just like string). Default for columns with name matching `"email"`. New in HTML5. Works on some mobile browsers already.
313
+ * `:url` - a text field (just like string). Default for columns with name matching `"url"`. New in HTML5. Works on some mobile browsers already.
314
+ * `:phone` - a text field (just like string). Default for columns with name matching `"phone"` or `"fax"`. New in HTML5.
315
+ * `:search` - a text field (just like string). Default for columns with name matching `"search"`. New in HTML5. Works on Safari.
316
+ * `:hidden` - a hidden field. Creates a hidden field (added for compatibility).
317
+ * `:range` - a slider field.
318
+ * `:datalist` - a text field with a accompanying [datalist tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/datalist) which provides options for autocompletion
319
+
320
+ The comments in the code are pretty good for each of these (what it does, what the output is, what the options are, etc.) so go check it out.
321
+
322
+
323
+ ## Delegation for label lookups
324
+
325
+ Formtastic decides which label to use in the following order:
326
+
327
+ ```
328
+ 1. :label # :label => "Choose Title"
329
+ 2. Formtastic i18n # if either :label => true || i18n_lookups_by_default = true (see Internationalization)
330
+ 3. Activerecord i18n # if localization file found for the given attribute
331
+ 4. label_str_method # if nothing provided this defaults to :humanize but can be set to a custom method
332
+ ```
333
+
334
+ ## Internationalization (I18n)
335
+
336
+ ### Basic Localization
337
+
338
+ Formtastic has some neat I18n-features. ActiveRecord object names and attributes are, by default, taken from calling `@object.human_name` and `@object.human_attribute_name(attr)` respectively. There are a few words specific to Formtastic that can be translated. See `lib/locale/en.yml` for more information.
339
+
340
+ Basic localization (labels only, with ActiveRecord):
341
+
342
+ ```erb
343
+ <%= semantic_form_for @post do |f| %>
344
+ <%= f.inputs do %>
345
+ <%= f.input :title %> # => :label => I18n.t('activerecord.attributes.user.title') or 'Title'
346
+ <%= f.input :body %> # => :label => I18n.t('activerecord.attributes.user.body') or 'Body'
347
+ <%= f.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
348
+ <% end %>
349
+ <% end %>
350
+ ```
351
+
352
+ *Note:* This is perfectly fine if you just want your labels/attributes and/or models to be translated using *ActiveRecord I18n attribute translations*, and you don't use input hints and legends. But what if you do? And what if you don't want same labels in all forms?
353
+
354
+ ### Enhanced Localization (Formtastic I18n API)
355
+
356
+ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the I18n API for more advanced usage. Your forms can now be DRYer and more flexible than ever, and still fully localized. This is how:
357
+
358
+ *1. Enable I18n lookups by default (`config/initializers/formtastic.rb`):*
359
+
360
+ ```ruby
361
+ Formtastic::FormBuilder.i18n_lookups_by_default = true
362
+ ```
363
+
364
+ *2. Add some label-translations/variants (`config/locales/en.yml`):*
365
+
366
+ ```yml
367
+ en:
368
+ formtastic:
369
+ titles:
370
+ post_details: "Post details"
371
+ labels:
372
+ post:
373
+ title: "Your Title"
374
+ body: "Write something..."
375
+ edit:
376
+ title: "Edit title"
377
+ hints:
378
+ post:
379
+ title: "Choose a good title for your post."
380
+ body: "Write something inspiring here."
381
+ placeholders:
382
+ post:
383
+ title: "Title your post"
384
+ slug: "Leave blank for an automatically generated slug"
385
+ user:
386
+ email: "you@yours.com"
387
+ actions:
388
+ create: "Create my %{model}"
389
+ update: "Save changes"
390
+ reset: "Reset form"
391
+ cancel: "Cancel and go back"
392
+ dummie: "Launch!"
393
+ ```
394
+
395
+ *3. ...and now you'll get:*
396
+
397
+ ```erb
398
+ <%= semantic_form_for Post.new do |f| %>
399
+ <%= f.inputs do %>
400
+ <%= f.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for your post."
401
+ <%= f.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
402
+ <%= f.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
403
+ <% end %>
404
+ <%= f.actions do %>
405
+ <%= f.action :submit %> # => "Create my %{model}"
406
+ <% end %>
407
+ <% end %>
408
+ ```
409
+
410
+ *4. Localized titles (a.k.a. legends):*
411
+
412
+ _Note: Slightly different because Formtastic can't guess how you group fields in a form. Legend text can be set with first (as in the sample below) specified value, or :name/:title options - depending on what flavor is preferred._
413
+
414
+ ```erb
415
+ <%= semantic_form_for @post do |f| %>
416
+ <%= f.inputs :post_details do %> # => :title => "Post details"
417
+ # ...
418
+ <% end %>
419
+ # ...
420
+ <% end %>
421
+ ```
422
+
423
+ *5. Override I18n settings:*
424
+
425
+ ```erb
426
+ <%= semantic_form_for @post do |f| %>
427
+ <%= f.inputs do %>
428
+ <%= f.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for your post."
429
+ <%= f.input :body, :hint => false %> # => :label => "Write something..."
430
+ <%= f.input :section, :label => 'Some section' %> # => :label => 'Some section'
431
+ <% end %>
432
+ <%= f.actions do %>
433
+ <%= f.action :submit, :label => :dummie %> # => "Launch!"
434
+ <% end %>
435
+ <% end %>
436
+ ```
437
+
438
+ If I18n-lookups is disabled, i.e.:
439
+
440
+ ```ruby
441
+ Formtastic::FormBuilder.i18n_lookups_by_default = false
442
+ ```
443
+
444
+ ...then you can enable I18n within the forms instead:
445
+
446
+ ```erb
447
+ <%= semantic_form_for @post do |f| %>
448
+ <%= f.inputs do %>
449
+ <%= f.input :title, :label => true %> # => :label => "Choose a title..."
450
+ <%= f.input :body, :label => true %> # => :label => "Write something..."
451
+ <%= f.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
452
+ <% end %>
453
+ <%= f.actions do %>
454
+ <%= f.action :submit, :label => true %> # => "Update %{model}" (if we are in edit that is...)
455
+ <% end %>
456
+ <% end %>
457
+ ```
458
+
459
+ *6. Advanced I18n lookups*
460
+
461
+ For more flexible forms; Formtastic finds translations using a bottom-up approach taking the following variables in account:
462
+
463
+ * `MODEL`, e.g. "post"
464
+ * `ACTION`, e.g. "edit"
465
+ * `KEY/ATTRIBUTE`, e.g. "title", :my_custom_key, ...
466
+
467
+ ...in the following order:
468
+
469
+ 1. `formtastic.{titles,labels,hints,actions}.MODEL.ACTION.ATTRIBUTE` - by model and action
470
+ 2. `formtastic.{titles,labels,hints,actions}.MODEL.ATTRIBUTE` - by model
471
+ 3. `formtastic.{titles,labels,hints,actions}.ATTRIBUTE` - global default
472
+
473
+ ...which means that you can define translations like this:
474
+
475
+ ```yml
476
+ en:
477
+ formtastic:
478
+ labels:
479
+ title: "Title" # Default global value
480
+ article:
481
+ body: "Article content"
482
+ post:
483
+ new:
484
+ title: "Choose a title..."
485
+ body: "Write something..."
486
+ edit:
487
+ title: "Edit title"
488
+ body: "Edit body"
489
+ ```
490
+
491
+ Values for `labels`/`hints`/`actions` are can take values: `String` (explicit value), `Symbol` (i18n-lookup-key relative to the current "type", e.g. actions:), `true` (force I18n lookup), `false` (force no I18n lookup). Titles (legends) can only take: `String` and `Symbol` - true/false have no meaning.
492
+
493
+ *7. Basic Translations*
494
+ If you want some basic translations, take a look on the [formtastic_i18n gem](https://github.com/formtastic/formtastic_i18n).
495
+
496
+ ## Semantic errors
497
+
498
+ You can show errors on base (by default) and any other attribute just by passing its name to the semantic_errors method:
499
+
500
+ ```erb
501
+ <%= semantic_form_for @post do |f| %>
502
+ <%= f.semantic_errors :state %>
503
+ <% end %>
504
+ ```
505
+
506
+
507
+ ## Modified & Custom Inputs
508
+
509
+ You can modify existing inputs, subclass them, or create your own from scratch. Here's the basic process:
510
+
511
+ * Run the input generator and provide your custom input name. For example, `rails generate formtastic:input hat_size`. This creates the file `app/inputs/hat_size_input.rb`. You can also provide namespace to input name like `rails generate formtastic:input foo/custom` or `rails generate formtastic:input Foo::Custom`, this will create the file `app/inputs/foo/custom_input.rb` in both cases.
512
+ * To use that input, leave off the word "input" in your `as` statement. For example, `f.input(:size, :as => :hat_size)`
513
+
514
+ Specific examples follow.
515
+
516
+ ### Changing Existing Input Behavior
517
+
518
+ To modify the behavior of `StringInput`, subclass it in a new file, `app/inputs/string_input.rb`:
519
+
520
+ ```ruby
521
+ class StringInput < Formtastic::Inputs::StringInput
522
+ def to_html
523
+ puts "this is my modified version of StringInput"
524
+ super
525
+ end
526
+ end
527
+ ```
528
+
529
+ Another way to modify behavior is by using the input generator:
530
+ ```shell
531
+ $ rails generate formtastic:input string --extend
532
+ ```
533
+
534
+ This generates the file `app/inputs/string_input.rb` with its respective content class.
535
+
536
+ You can use your modified version with `:as => :string`.
537
+
538
+ ### Creating New Inputs Based on Existing Ones
539
+
540
+ To create your own new types of inputs based on existing inputs, the process is similar. For example, to create `FlexibleTextInput` based on `StringInput`, put the following in `app/inputs/flexible_text_input.rb`:
541
+
542
+ ```ruby
543
+ class FlexibleTextInput < Formtastic::Inputs::StringInput
544
+ def input_html_options
545
+ super.merge(:class => "flexible-text-area")
546
+ end
547
+
548
+ def options
549
+ super.merge(hint: 'This is a flexible text area')
550
+ end
551
+ end
552
+ ```
553
+
554
+ You can also extend existing input behavior by using the input generator:
555
+
556
+ ```shell
557
+ $ rails generate formtastic:input FlexibleText --extend string
558
+ ```
559
+
560
+ This generates the file `app/inputs/flexible_text_input.rb` with its respective content class.
561
+
562
+ You can use your new input with `:as => :flexible_text`.
563
+
564
+ ### Creating New Inputs From Scratch
565
+
566
+ To create a custom `DatePickerInput` from scratch, put the following in `app/inputs/date_picker_input.rb`:
567
+
568
+ ```ruby
569
+ class DatePickerInput
570
+ include Formtastic::Inputs::Base
571
+ def to_html
572
+ # ...
573
+ end
574
+ end
575
+ ```
576
+
577
+ You can use your new input with `:as => :date_picker`.
578
+
579
+
580
+ ## Dependencies
581
+
582
+ There are none other than Rails itself, but...
583
+
584
+ * If you want to use the `:country` input, you'll need to install the [country-select plugin](https://github.com/countries/country_select) (or any other country_select plugin with the same API).
585
+ * There are a bunch of development dependencies if you plan to contribute to Formtastic
586
+
587
+
588
+ ## How to contribute
589
+
590
+ See `CONTRIBUTING.md`
591
+
592
+
593
+ ## Project Info
594
+
595
+ Formtastic was created by [Justin French](https://justinfrench.com) with contributions from around 180 awesome developers. Run `git shortlog -n -s` to see the awesome.
596
+
597
+ The project is hosted on Github: [https://github.com/formtastic/formtastic](https://github.com/formtastic/formtastic), where your contributions, forkings, comments, issues and feedback are greatly welcomed.
598
+
599
+ Copyright (c) 2007-2025, released under the MIT license.
600
+
@@ -0,0 +1,7 @@
1
+ # review & edit README
2
+ # edit lib/formtastic/version.rb
3
+ git ci -am "version bump" # commit changes
4
+ git tag X.X.X # tag the new version in the code base too
5
+ gem build formtastic.gemspec # build the gem
6
+ gem push formtastic-X.X.X.gem # publish the gem
7
+ git push && git push --tags # push to remote
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ require 'bundler/setup'
3
+ require 'yard'
4
+ require 'rspec/core/rake_task'
5
+
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ desc 'Default: run unit specs.'
9
+ if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
10
+ task :default => :appraisal
11
+ else
12
+ task :default => :spec
13
+ end
14
+
15
+ desc 'Run the default task over all gemfiles.'
16
+ task :appraisal do
17
+ for_all_gemfiles("exec", "rake")
18
+ end
19
+
20
+ namespace :appraisal do
21
+ desc 'Run `bundle install` over all gemfiles.'
22
+ task :install do
23
+ for_all_gemfiles("install")
24
+ end
25
+ end
26
+
27
+ def for_all_gemfiles(*args)
28
+ Dir.glob("gemfiles/*.gemfile").sort.each do |gemfile|
29
+ Bundler.with_original_env do
30
+ sh({ "APPRAISAL_INITIALIZED" => "true", "BUNDLE_GEMFILE" => gemfile }, "bundle", *args)
31
+ end
32
+ end
33
+ end
34
+
35
+ desc 'Generate documentation for the formtastic plugin.'
36
+ YARD::Rake::YardocTask.new(:yard) do |t|
37
+
38
+ end
39
+ task doc: :yard
40
+
41
+ desc 'Test the formtastic plugin.'
42
+ RSpec::Core::RakeTask.new('spec') do |t|
43
+ t.pattern = FileList['spec/**/*_spec.rb']
44
+ end
45
+
46
+ desc 'Test the formtastic inputs.'
47
+ RSpec::Core::RakeTask.new('spec:inputs') do |t|
48
+ t.pattern = FileList['spec/inputs/*_spec.rb']
49
+ end
50
+
51
+ desc 'Test the formtastic plugin with specdoc formatting and colors'
52
+ RSpec::Core::RakeTask.new('specdoc') do |t|
53
+ t.pattern = FileList['spec/**/*_spec.rb']
54
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+
3
+ if [ "$1" = "" ]
4
+ then
5
+ bundle exec rake appraisal
6
+ else
7
+ bundle exec rake "appraisal:$1"
8
+ fi