generic_form_for 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.
- data/.document +5 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +123 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +217 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/generic_form_for.gemspec +232 -0
- data/generic_form_for.tmproj +166 -0
- data/lib/generators/generic_form_for/form_builder/form_builder_generator.rb +16 -0
- data/lib/generators/generic_form_for/form_builder/templates/form_builder.erb +37 -0
- data/lib/generators/generic_form_for/form_builder/templates/helper.erb +15 -0
- data/lib/generators/generic_form_for/install/install_generator.rb +20 -0
- data/lib/generators/generic_form_for/install/templates/_form.html.erb +11 -0
- data/lib/generators/generic_form_for/install/templates/_form.html.haml +8 -0
- data/lib/generators/generic_form_for/install/templates/form_for.en.yml +11 -0
- data/lib/generators/generic_form_for/install/templates/initializer.rb +5 -0
- data/lib/generic_form_for.rb +22 -0
- data/lib/generic_form_for/actions.rb +10 -0
- data/lib/generic_form_for/actions/base.rb +63 -0
- data/lib/generic_form_for/actions/base/icon.rb +24 -0
- data/lib/generic_form_for/actions/button_action.rb +14 -0
- data/lib/generic_form_for/actions/input_action.rb +11 -0
- data/lib/generic_form_for/engine.rb +11 -0
- data/lib/generic_form_for/form_builder.rb +111 -0
- data/lib/generic_form_for/helpers.rb +10 -0
- data/lib/generic_form_for/helpers/action_helper.rb +52 -0
- data/lib/generic_form_for/helpers/actions_helper.rb +35 -0
- data/lib/generic_form_for/helpers/fieldset_helper.rb +48 -0
- data/lib/generic_form_for/helpers/form_helper.rb +64 -0
- data/lib/generic_form_for/helpers/input_helper.rb +77 -0
- data/lib/generic_form_for/i18n.rb +44 -0
- data/lib/generic_form_for/inputs.rb +22 -0
- data/lib/generic_form_for/inputs/base.rb +98 -0
- data/lib/generic_form_for/inputs/base/error_message.rb +30 -0
- data/lib/generic_form_for/inputs/base/hint.rb +28 -0
- data/lib/generic_form_for/inputs/base/label.rb +42 -0
- data/lib/generic_form_for/inputs/base/number.rb +18 -0
- data/lib/generic_form_for/inputs/base/placeholder.rb +20 -0
- data/lib/generic_form_for/inputs/base/string.rb +17 -0
- data/lib/generic_form_for/inputs/base/validations.rb +42 -0
- data/lib/generic_form_for/inputs/boolean_input.rb +35 -0
- data/lib/generic_form_for/inputs/email_input.rb +19 -0
- data/lib/generic_form_for/inputs/file_input.rb +13 -0
- data/lib/generic_form_for/inputs/hidden_input.rb +23 -0
- data/lib/generic_form_for/inputs/number_input.rb +20 -0
- data/lib/generic_form_for/inputs/password_input.rb +13 -0
- data/lib/generic_form_for/inputs/phone_input.rb +19 -0
- data/lib/generic_form_for/inputs/range_input.rb +19 -0
- data/lib/generic_form_for/inputs/search_input.rb +19 -0
- data/lib/generic_form_for/inputs/select_input.rb +32 -0
- data/lib/generic_form_for/inputs/string_input.rb +13 -0
- data/lib/generic_form_for/inputs/text_input.rb +20 -0
- data/lib/generic_form_for/inputs/url_input.rb +19 -0
- data/sample_app/.gitignore +15 -0
- data/sample_app/Gemfile +15 -0
- data/sample_app/Gemfile.lock +130 -0
- data/sample_app/README.rdoc +261 -0
- data/sample_app/Rakefile +7 -0
- data/sample_app/app/assets/images/rails.png +0 -0
- data/sample_app/app/assets/javascripts/application.js +14 -0
- data/sample_app/app/assets/javascripts/posts.js.coffee +3 -0
- data/sample_app/app/assets/javascripts/samples.js.coffee +3 -0
- data/sample_app/app/assets/stylesheets/application.css +14 -0
- data/sample_app/app/assets/stylesheets/posts.css.scss +3 -0
- data/sample_app/app/assets/stylesheets/samples.css.scss +3 -0
- data/sample_app/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/sample_app/app/controllers/application_controller.rb +3 -0
- data/sample_app/app/controllers/samples_controller.rb +83 -0
- data/sample_app/app/form_builders/sample_form_builder.rb +17 -0
- data/sample_app/app/helpers/application_helper.rb +2 -0
- data/sample_app/app/helpers/sample_form_builder_helper.rb +15 -0
- data/sample_app/app/helpers/samples_helper.rb +2 -0
- data/sample_app/app/mailers/.gitkeep +0 -0
- data/sample_app/app/models/.gitkeep +0 -0
- data/sample_app/app/models/sample.rb +29 -0
- data/sample_app/app/views/layouts/application.html.erb +16 -0
- data/sample_app/app/views/samples/_form.html.erb +49 -0
- data/sample_app/app/views/samples/edit.html.erb +6 -0
- data/sample_app/app/views/samples/index.html.erb +21 -0
- data/sample_app/app/views/samples/new.html.erb +5 -0
- data/sample_app/app/views/samples/show.html.erb +5 -0
- data/sample_app/config.ru +4 -0
- data/sample_app/config/application.rb +65 -0
- data/sample_app/config/boot.rb +6 -0
- data/sample_app/config/database.yml +25 -0
- data/sample_app/config/environment.rb +5 -0
- data/sample_app/config/environments/development.rb +37 -0
- data/sample_app/config/environments/production.rb +67 -0
- data/sample_app/config/environments/test.rb +37 -0
- data/sample_app/config/initializers/backtrace_silencers.rb +7 -0
- data/sample_app/config/initializers/generic_form_for.rb +5 -0
- data/sample_app/config/initializers/inflections.rb +15 -0
- data/sample_app/config/initializers/mime_types.rb +5 -0
- data/sample_app/config/initializers/secret_token.rb +7 -0
- data/sample_app/config/initializers/session_store.rb +8 -0
- data/sample_app/config/initializers/wrap_parameters.rb +14 -0
- data/sample_app/config/locales/en.yml +22 -0
- data/sample_app/config/locales/form_for.en.yml +13 -0
- data/sample_app/config/routes.rb +61 -0
- data/sample_app/db/migrate/20120203082117_create_samples.rb +22 -0
- data/sample_app/db/schema.rb +36 -0
- data/sample_app/db/seeds.rb +7 -0
- data/sample_app/lib/assets/.gitkeep +0 -0
- data/sample_app/lib/tasks/.gitkeep +0 -0
- data/sample_app/lib/templates/erb/scaffold/_form.html.erb +11 -0
- data/sample_app/log/.gitkeep +0 -0
- data/sample_app/public/404.html +26 -0
- data/sample_app/public/422.html +26 -0
- data/sample_app/public/500.html +25 -0
- data/sample_app/public/favicon.ico +0 -0
- data/sample_app/public/robots.txt +5 -0
- data/sample_app/script/rails +6 -0
- data/sample_app/vendor/assets/javascripts/.gitkeep +0 -0
- data/sample_app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/sample_app/vendor/plugins/.gitkeep +0 -0
- data/spec/actions/base/icon_spec.rb +38 -0
- data/spec/actions/button_action_spec.rb +43 -0
- data/spec/actions/input_action_spec.rb +66 -0
- data/spec/helpers/action_helper_spec.rb +32 -0
- data/spec/helpers/actions_helper_spec.rb +60 -0
- data/spec/helpers/fieldset_helper_spec.rb +83 -0
- data/spec/helpers/form_helper_spec.rb +101 -0
- data/spec/helpers/input_helper_spec.rb +66 -0
- data/spec/i18n_spec.rb +46 -0
- data/spec/inputs/base/error_message_spec.rb +86 -0
- data/spec/inputs/base/hint_spec.rb +77 -0
- data/spec/inputs/base/label_spec.rb +99 -0
- data/spec/inputs/base/number_spec.rb +32 -0
- data/spec/inputs/base/placeholder_spec.rb +32 -0
- data/spec/inputs/base/string_spec.rb +25 -0
- data/spec/inputs/base/validations_spec.rb +53 -0
- data/spec/inputs/base_spec.rb +69 -0
- data/spec/inputs/boolean_input_spec.rb +95 -0
- data/spec/inputs/email_input_spec.rb +30 -0
- data/spec/inputs/file_input_spec.rb +30 -0
- data/spec/inputs/hidden_input_spec.rb +30 -0
- data/spec/inputs/number_input_spec.rb +37 -0
- data/spec/inputs/password_input_spec.rb +30 -0
- data/spec/inputs/phone_input_spec.rb +30 -0
- data/spec/inputs/range_input_spec.rb +37 -0
- data/spec/inputs/search_input_spec.rb +30 -0
- data/spec/inputs/select_input_spec.rb +51 -0
- data/spec/inputs/string_input_spec.rb +115 -0
- data/spec/inputs/text_input_spec.rb +30 -0
- data/spec/inputs/url_input_spec.rb +30 -0
- data/spec/spec_helper.rb +122 -0
- metadata +374 -0
@@ -0,0 +1,166 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>currentDocument</key>
|
6
|
+
<string>lib/generic_form_for/actions/button_action.rb</string>
|
7
|
+
<key>documents</key>
|
8
|
+
<array>
|
9
|
+
<dict>
|
10
|
+
<key>expanded</key>
|
11
|
+
<true/>
|
12
|
+
<key>name</key>
|
13
|
+
<string>generic_form_for</string>
|
14
|
+
<key>regexFolderFilter</key>
|
15
|
+
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
|
16
|
+
<key>sourceDirectory</key>
|
17
|
+
<string></string>
|
18
|
+
</dict>
|
19
|
+
</array>
|
20
|
+
<key>fileHierarchyDrawerWidth</key>
|
21
|
+
<integer>302</integer>
|
22
|
+
<key>metaData</key>
|
23
|
+
<dict>
|
24
|
+
<key>lib/generic_form_for/actions/button_action.rb</key>
|
25
|
+
<dict>
|
26
|
+
<key>caret</key>
|
27
|
+
<dict>
|
28
|
+
<key>column</key>
|
29
|
+
<integer>6</integer>
|
30
|
+
<key>line</key>
|
31
|
+
<integer>10</integer>
|
32
|
+
</dict>
|
33
|
+
<key>firstVisibleColumn</key>
|
34
|
+
<integer>0</integer>
|
35
|
+
<key>firstVisibleLine</key>
|
36
|
+
<integer>0</integer>
|
37
|
+
</dict>
|
38
|
+
<key>sample_app/app/form_builders/sample_form_builder.rb</key>
|
39
|
+
<dict>
|
40
|
+
<key>caret</key>
|
41
|
+
<dict>
|
42
|
+
<key>column</key>
|
43
|
+
<integer>52</integer>
|
44
|
+
<key>line</key>
|
45
|
+
<integer>36</integer>
|
46
|
+
</dict>
|
47
|
+
<key>firstVisibleColumn</key>
|
48
|
+
<integer>0</integer>
|
49
|
+
<key>firstVisibleLine</key>
|
50
|
+
<integer>3</integer>
|
51
|
+
</dict>
|
52
|
+
</dict>
|
53
|
+
<key>openDocuments</key>
|
54
|
+
<array>
|
55
|
+
<string>sample_app/app/form_builders/sample_form_builder.rb</string>
|
56
|
+
<string>lib/generic_form_for/actions/button_action.rb</string>
|
57
|
+
</array>
|
58
|
+
<key>showFileHierarchyDrawer</key>
|
59
|
+
<false/>
|
60
|
+
<key>showFileHierarchyPanel</key>
|
61
|
+
<true/>
|
62
|
+
<key>treeState</key>
|
63
|
+
<dict>
|
64
|
+
<key>generic_form_for</key>
|
65
|
+
<dict>
|
66
|
+
<key>isExpanded</key>
|
67
|
+
<true/>
|
68
|
+
<key>subItems</key>
|
69
|
+
<dict>
|
70
|
+
<key>lib</key>
|
71
|
+
<dict>
|
72
|
+
<key>isExpanded</key>
|
73
|
+
<true/>
|
74
|
+
<key>subItems</key>
|
75
|
+
<dict>
|
76
|
+
<key>generators</key>
|
77
|
+
<dict>
|
78
|
+
<key>isExpanded</key>
|
79
|
+
<true/>
|
80
|
+
<key>subItems</key>
|
81
|
+
<dict>
|
82
|
+
<key>generic_form_for</key>
|
83
|
+
<dict>
|
84
|
+
<key>isExpanded</key>
|
85
|
+
<true/>
|
86
|
+
<key>subItems</key>
|
87
|
+
<dict/>
|
88
|
+
</dict>
|
89
|
+
</dict>
|
90
|
+
</dict>
|
91
|
+
<key>generic_form_for</key>
|
92
|
+
<dict>
|
93
|
+
<key>isExpanded</key>
|
94
|
+
<true/>
|
95
|
+
<key>subItems</key>
|
96
|
+
<dict>
|
97
|
+
<key>actions</key>
|
98
|
+
<dict>
|
99
|
+
<key>isExpanded</key>
|
100
|
+
<true/>
|
101
|
+
<key>subItems</key>
|
102
|
+
<dict>
|
103
|
+
<key>base</key>
|
104
|
+
<dict>
|
105
|
+
<key>isExpanded</key>
|
106
|
+
<true/>
|
107
|
+
<key>subItems</key>
|
108
|
+
<dict/>
|
109
|
+
</dict>
|
110
|
+
</dict>
|
111
|
+
</dict>
|
112
|
+
<key>helpers</key>
|
113
|
+
<dict>
|
114
|
+
<key>isExpanded</key>
|
115
|
+
<true/>
|
116
|
+
<key>subItems</key>
|
117
|
+
<dict/>
|
118
|
+
</dict>
|
119
|
+
<key>inputs</key>
|
120
|
+
<dict>
|
121
|
+
<key>isExpanded</key>
|
122
|
+
<true/>
|
123
|
+
<key>subItems</key>
|
124
|
+
<dict/>
|
125
|
+
</dict>
|
126
|
+
</dict>
|
127
|
+
</dict>
|
128
|
+
</dict>
|
129
|
+
</dict>
|
130
|
+
<key>spec</key>
|
131
|
+
<dict>
|
132
|
+
<key>isExpanded</key>
|
133
|
+
<true/>
|
134
|
+
<key>subItems</key>
|
135
|
+
<dict>
|
136
|
+
<key>actions</key>
|
137
|
+
<dict>
|
138
|
+
<key>isExpanded</key>
|
139
|
+
<true/>
|
140
|
+
<key>subItems</key>
|
141
|
+
<dict>
|
142
|
+
<key>base</key>
|
143
|
+
<dict>
|
144
|
+
<key>isExpanded</key>
|
145
|
+
<true/>
|
146
|
+
<key>subItems</key>
|
147
|
+
<dict/>
|
148
|
+
</dict>
|
149
|
+
</dict>
|
150
|
+
</dict>
|
151
|
+
<key>helpers</key>
|
152
|
+
<dict>
|
153
|
+
<key>isExpanded</key>
|
154
|
+
<true/>
|
155
|
+
<key>subItems</key>
|
156
|
+
<dict/>
|
157
|
+
</dict>
|
158
|
+
</dict>
|
159
|
+
</dict>
|
160
|
+
</dict>
|
161
|
+
</dict>
|
162
|
+
</dict>
|
163
|
+
<key>windowFrame</key>
|
164
|
+
<string>{{25, 283}, {1361, 706}}</string>
|
165
|
+
</dict>
|
166
|
+
</plist>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GenericFormFor
|
2
|
+
module Generators
|
3
|
+
class FormBuilderGenerator < Rails::Generators::Base
|
4
|
+
source_root File.join(File.dirname(__FILE__), 'templates')
|
5
|
+
desc "Create frame for new GenericFormFor customization."
|
6
|
+
|
7
|
+
argument :name
|
8
|
+
|
9
|
+
def copy_files
|
10
|
+
template "form_builder.erb", "app/form_builders/#{name.downcase}_form_builder.rb"
|
11
|
+
template "helper.erb", "app/helpers/#{name.downcase}_form_builder_helper.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module <%=name.camelize%>FormBuilder
|
2
|
+
class <%=name.camelize%>FormBuilder < GenericFormFor::FormBuilder
|
3
|
+
|
4
|
+
self.html5_browser_validate = true
|
5
|
+
self.html5_browser_autofocus = true
|
6
|
+
self.default_text_field_size = 40
|
7
|
+
self.required_string = "<abbr>*</abbr>"
|
8
|
+
self.use_translations = true
|
9
|
+
|
10
|
+
form_wrapper do
|
11
|
+
form :class => "form-vertical"
|
12
|
+
end
|
13
|
+
|
14
|
+
fieldset_wrapper do
|
15
|
+
fieldset_html do
|
16
|
+
legend_html
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
input_wrapper do
|
21
|
+
wrap_in :class => "controls" do
|
22
|
+
label_html :class => "control-label"
|
23
|
+
input_html
|
24
|
+
error_html
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
actions_wrapper do
|
29
|
+
actions_html :class => "form-actions"
|
30
|
+
end
|
31
|
+
|
32
|
+
action_wrapper do
|
33
|
+
action_html :class => "btn btn-primary"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module <%=name.camelize%>FormBuilderHelper
|
2
|
+
|
3
|
+
def <%=name%>_form_for(record, *args, &proc)
|
4
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
5
|
+
options[:builder] = <%=name.camelize%>FormBuilder::<%=name.camelize%>FormBuilder
|
6
|
+
generic_form_for(record, *(args << options), &proc)
|
7
|
+
end
|
8
|
+
|
9
|
+
def <%=name%>_fields_for(record, *args, &proc)
|
10
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
11
|
+
options[:builder] = <%=name.camelize%>FormBuilder::<%=name.camelize%>FormBuilder
|
12
|
+
generic_fields_for(name, *(args << options), &proc)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GenericFormFor
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.join(File.dirname(__FILE__), 'templates')
|
5
|
+
desc "Installs GenericFormFor into your application."
|
6
|
+
class_option :template_engine
|
7
|
+
|
8
|
+
def copy_files
|
9
|
+
copy_file "initializer.rb", "config/initializers/generic_form_for.rb"
|
10
|
+
copy_file "form_for.en.yml", "config/locales/form_for.en.yml"
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_scaffold_template
|
14
|
+
engine = options[:template_engine]
|
15
|
+
copy_file "_form.html.#{engine}", "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%%= generic_form_for @<%= singular_name %> do |f| %>
|
2
|
+
<%%= f.inputs do %>
|
3
|
+
<%- attributes.each do |attribute| -%>
|
4
|
+
<%%= f.input :<%= attribute.name %> %>
|
5
|
+
<%- end -%>
|
6
|
+
<%% end %>
|
7
|
+
|
8
|
+
<%%= f.actions do %>
|
9
|
+
<%%= f.action :submit %>
|
10
|
+
<%% end %>
|
11
|
+
<%% end %>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
GenericFormFor::FormBuilder.html5_browser_validate = true
|
2
|
+
GenericFormFor::FormBuilder.html5_browser_autofocus = true
|
3
|
+
GenericFormFor::FormBuilder.default_text_field_size = 30
|
4
|
+
GenericFormFor::FormBuilder.required_string = "<abbr>*</abbr>"
|
5
|
+
GenericFormFor::FormBuilder.use_translations = true
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'generic_form_for/engine' if defined?(::Rails)
|
2
|
+
|
3
|
+
module GenericFormFor
|
4
|
+
extend ActiveSupport::Autoload
|
5
|
+
autoload :FormBuilder
|
6
|
+
autoload :I18n
|
7
|
+
autoload :Helpers
|
8
|
+
autoload :Inputs
|
9
|
+
autoload :Actions
|
10
|
+
|
11
|
+
# @private
|
12
|
+
class UnknownInputError < NameError
|
13
|
+
end
|
14
|
+
|
15
|
+
# @private
|
16
|
+
class UnknownActionError < NameError
|
17
|
+
end
|
18
|
+
|
19
|
+
# @private
|
20
|
+
class UnknownWrapperError < NameError
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module GenericFormFor
|
2
|
+
module Actions
|
3
|
+
extend ActiveSupport::Autoload
|
4
|
+
|
5
|
+
autoload :Base, 'generic_form_for/actions/base'
|
6
|
+
autoload :InputAction, 'generic_form_for/actions/input_action'
|
7
|
+
autoload :ButtonAction, 'generic_form_for/actions/button_action'
|
8
|
+
# autoload :LinkAction, 'generic_form_for/actions/link_action'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module GenericFormFor
|
2
|
+
module Actions
|
3
|
+
module Base
|
4
|
+
include I18n
|
5
|
+
|
6
|
+
def wrap_in(*args, &block)
|
7
|
+
wrap_options = args.last.is_a?(Hash) ? args.pop : {}
|
8
|
+
wrap_options[:class] = [*"#{options[:as]}-action", *wrap_options[:class], *(options[:wrapper_html]||{})[:class]].join(' ').strip
|
9
|
+
wrap_options.merge!((options[:wrapper_html] || {}).except(:class))
|
10
|
+
template.concat( template.content_tag(wrap_options.delete(:tag) || :div, wrap_options) do
|
11
|
+
template.capture(&block) if block_given?
|
12
|
+
end.html_safe)
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :builder, :template, :object, :object_name, :method, :options
|
16
|
+
|
17
|
+
def initialize(builder, template, object, object_name, method, options)
|
18
|
+
@output_buffer = ""
|
19
|
+
@builder = builder
|
20
|
+
@template = template
|
21
|
+
@object = object
|
22
|
+
@object_name = object_name
|
23
|
+
@method = method
|
24
|
+
@options = options.dup
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_html
|
28
|
+
instance_exec &builder.action_wrapper_proc
|
29
|
+
""
|
30
|
+
end
|
31
|
+
|
32
|
+
def merge_action_html_options(runtime_options,config_options)
|
33
|
+
runtime_options[:class] = [*runtime_options[:class], *config_options[:class]].compact.join(' ').strip
|
34
|
+
config_options.merge(runtime_options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def action_html_options
|
38
|
+
default_action_options.merge(options[:html] || {}).merge(action_options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_action_options
|
42
|
+
{:name => method, :type => method }
|
43
|
+
end
|
44
|
+
|
45
|
+
def action_options
|
46
|
+
options.except(*form_builder_options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def form_builder_options
|
50
|
+
[:as, :url, :icon, :icon_html]
|
51
|
+
end
|
52
|
+
|
53
|
+
def button_text
|
54
|
+
translate_action(options[:label] || method)
|
55
|
+
end
|
56
|
+
|
57
|
+
extend ActiveSupport::Autoload
|
58
|
+
#
|
59
|
+
autoload :Icon
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module GenericFormFor
|
2
|
+
module Actions
|
3
|
+
module Base
|
4
|
+
module Icon
|
5
|
+
|
6
|
+
def icon_html(config_options={})
|
7
|
+
return "" unless render_icon?
|
8
|
+
template.content_tag(config_options.delete(:tag) || :span, "", icon_html_options(config_options))
|
9
|
+
end
|
10
|
+
|
11
|
+
def icon_html_options(config_options={})
|
12
|
+
opts = (options[:icon_html] || {}).dup
|
13
|
+
opts[:class] = [*options[:icon], *opts[:class], *config_options[:class]].compact.join(' ').strip
|
14
|
+
config_options.merge(opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_icon?
|
18
|
+
options.key?(:icon)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module GenericFormFor
|
2
|
+
module Actions
|
3
|
+
class ButtonAction
|
4
|
+
include Base
|
5
|
+
include Icon
|
6
|
+
|
7
|
+
def action_html(config_options={}, &html_block)
|
8
|
+
icon = template.capture(&html_block) if block_given?
|
9
|
+
template.concat template.button_tag("#{icon}#{button_text}".html_safe, merge_action_html_options(action_html_options,config_options))
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|