formatted_form 1.1.0 → 2.0.0
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/Gemfile +7 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +121 -29
- data/Rakefile +29 -10
- data/VERSION +1 -1
- data/app/assets/javascripts/formatted_form.js +12 -0
- data/app/assets/stylesheets/formatted_form.css +0 -0
- data/app/views/formatted_form/_check_box.html.erb +1 -0
- data/app/views/formatted_form/_date_select.html.erb +1 -0
- data/app/views/formatted_form/_datetime_select.html.erb +1 -0
- data/app/views/formatted_form/_element.html.erb +1 -0
- data/app/views/formatted_form/_email_field.html.erb +1 -0
- data/app/views/formatted_form/_file_field.html.erb +1 -0
- data/app/views/formatted_form/_number_field.html.erb +1 -0
- data/app/views/formatted_form/_password_field.html.erb +1 -0
- data/app/views/formatted_form/_phone_field.html.erb +1 -0
- data/app/views/formatted_form/_radio_button.html.erb +1 -0
- data/app/views/formatted_form/_range_field.html.erb +1 -0
- data/app/views/formatted_form/_search_field.html.erb +1 -0
- data/app/views/formatted_form/_select.html.erb +1 -0
- data/app/views/formatted_form/_submit.html.erb +1 -0
- data/app/views/formatted_form/_telephone_field.html.erb +1 -0
- data/app/views/formatted_form/_text_area.html.erb +1 -0
- data/app/views/formatted_form/_text_field.html.erb +1 -0
- data/app/views/formatted_form/_time_select.html.erb +1 -0
- data/app/views/formatted_form/_time_zone_select.html.erb +1 -0
- data/app/views/formatted_form/templates/_choices.html.erb +35 -0
- data/app/views/formatted_form/templates/_field.html.erb +34 -0
- data/formatted_form.gemspec +76 -26
- data/lib/formatted_form/engine.rb +6 -11
- data/lib/formatted_form/form_builder.rb +125 -0
- data/lib/formatted_form/view_helper.rb +49 -0
- data/lib/formatted_form.rb +3 -20
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +65 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +31 -0
- data/test/dummy/config/environments/production.rb +64 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +10 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/form_builder_test.rb +391 -0
- data/test/test_helper.rb +47 -0
- metadata +105 -25
- data/app/views/formatted_form/_check_box.html.haml +0 -14
- data/app/views/formatted_form/_default_field.html.haml +0 -17
- data/app/views/formatted_form/_radio_button.html.haml +0 -17
- data/app/views/formatted_form/_submit.html.haml +0 -3
- data/app/views/twitter_bootstrap/_check_box.html.haml +0 -18
- data/app/views/twitter_bootstrap/_default_field.html.haml +0 -10
- data/app/views/twitter_bootstrap/_radio_button.html.haml +0 -24
- data/app/views/twitter_bootstrap/_submit.html.haml +0 -3
- data/lib/formatted_form/builder.rb +0 -178
- data/lib/formatted_form/configuration.rb +0 -16
- data/lib/formatted_form/helper.rb +0 -10
- data/lib/generators/formatted_form/javascripts/javascripts_generator.rb +0 -11
- data/lib/generators/formatted_form/stylesheets/stylesheets_generator.rb +0 -11
- data/templates/javascripts/formatted_form.js +0 -17
- data/templates/stylesheets/formatted_form.sass +0 -121
@@ -1,24 +0,0 @@
|
|
1
|
-
.clearfix{:class => ('error' if error_messages.present?)}
|
2
|
-
|
3
|
-
%label
|
4
|
-
= label_text
|
5
|
-
- if required
|
6
|
-
%span.required *
|
7
|
-
|
8
|
-
.input
|
9
|
-
%ul.inputs-list
|
10
|
-
- choices.each do |choice|
|
11
|
-
%li
|
12
|
-
%label{:for => choice[:label_for]}
|
13
|
-
= choice[:field]
|
14
|
-
%span= choice[:label]
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
- if description.present?
|
19
|
-
%span.help-block= description
|
20
|
-
|
21
|
-
- if error_messages.present?
|
22
|
-
%span.help-inline= error_messages
|
23
|
-
|
24
|
-
|
@@ -1,178 +0,0 @@
|
|
1
|
-
module FormattedForm
|
2
|
-
class Builder < ActionView::Helpers::FormBuilder
|
3
|
-
|
4
|
-
%w(text_field password_field text_area file_field datetime_select date_select).each do |field_name|
|
5
|
-
define_method field_name do |method, *args|
|
6
|
-
options = args.detect { |a| a.is_a?(Hash) } || {}
|
7
|
-
render_field(field_name, method, options) { super(method, options) }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def select(method, choices, options = {}, html_options = {})
|
12
|
-
render_field('select', method, options) { super(method, choices, options, html_options) }
|
13
|
-
end
|
14
|
-
|
15
|
-
def hidden_field(method, options = {}, html_options = {})
|
16
|
-
super(method, options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
|
20
|
-
render_field('check_box', method, options) do
|
21
|
-
super(method, options, checked_value, unchecked_value)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def radio_button(method, tag_value, options = {})
|
26
|
-
case tag_value
|
27
|
-
when Array
|
28
|
-
choices = tag_value.collect do |choice|
|
29
|
-
if !choice.is_a?(Array)
|
30
|
-
choice = [choice, choice]
|
31
|
-
elsif choice.length == 1
|
32
|
-
choice << choice[0]
|
33
|
-
end
|
34
|
-
{
|
35
|
-
:field => super(method, choice[1], options),
|
36
|
-
:label => choice[0],
|
37
|
-
:label_for => "#{object_name}_#{method}_#{choice[1].to_s.gsub(' ', '_').underscore}"
|
38
|
-
}
|
39
|
-
end
|
40
|
-
else
|
41
|
-
choices = [{
|
42
|
-
:field => super(method, tag_value),
|
43
|
-
:label => tag_value,
|
44
|
-
:label_for => "#{object_name}_#{method}_#{tag_value.to_s.gsub(' ', '_').underscore}"
|
45
|
-
}]
|
46
|
-
end
|
47
|
-
|
48
|
-
@template.render(:partial => "#{FormattedForm.config.template}/radio_button", :locals => {
|
49
|
-
:builder => self,
|
50
|
-
:method => method,
|
51
|
-
:field_name => 'radio_button',
|
52
|
-
:label_text => label_text(method, options.delete(:label)),
|
53
|
-
:choices => choices,
|
54
|
-
:required => options.delete(:required),
|
55
|
-
:before_text => @template.raw(options.delete(:before_text)),
|
56
|
-
:after_text => @template.raw(options.delete(:after_text)),
|
57
|
-
:description => @template.raw(options.delete(:desc)),
|
58
|
-
:error_messages => error_messages_for(method)
|
59
|
-
})
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
# f.submit 'Log In', :change_to_text => 'Logging you in ...'
|
64
|
-
def submit(value, options={}, &block)
|
65
|
-
after_text = @template.capture(&block) if block_given?
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
case FormattedForm.config.template
|
70
|
-
when :formatted_form
|
71
|
-
# Set the script to change the text
|
72
|
-
if change_to_text = options.delete(:change_to_text)
|
73
|
-
options[:onclick] ||= ''
|
74
|
-
options[:onclick] = "$(this).closest('.form_element').hide();$(this).closest('.form_element').after($('<div class=form_element><div class=value>#{change_to_text}</div></div>'))"
|
75
|
-
end
|
76
|
-
|
77
|
-
when :twitter_bootstrap
|
78
|
-
# Add specific bootstrap class
|
79
|
-
options[:class] ||= ''
|
80
|
-
options[:class] += ' btn primary'
|
81
|
-
|
82
|
-
# Set the script to change the text
|
83
|
-
if change_to_text = options.delete(:change_to_text)
|
84
|
-
options[:onclick] ||= ''
|
85
|
-
options[:onclick] = "$(this).closest('.actions').hide();$(this).closest('.actions').after($('<div class=actions>#{change_to_text}</div>'))"
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
@template.render(:partial => "#{FormattedForm.config.template}/submit", :locals => {
|
90
|
-
:field_name => 'submit',
|
91
|
-
:field => super(value, options),
|
92
|
-
:after_text => after_text,
|
93
|
-
:change_to_text => change_to_text
|
94
|
-
})
|
95
|
-
|
96
|
-
|
97
|
-
# out = @template.content_tag(:div, :class => "form_element submit#{' change_to_text' if change_to_text}") do
|
98
|
-
# if options.delete(:image)
|
99
|
-
# content = super(value, options.merge(:style=>'visibility:hidden;position: absolute'))
|
100
|
-
# content << @template.link_to(@template.content_tag(:span, value), "#", :class => 'submit_image')
|
101
|
-
# content << cancel_link.html_safe
|
102
|
-
# else
|
103
|
-
# super(value, options) + cancel_link.html_safe
|
104
|
-
# end
|
105
|
-
# end
|
106
|
-
#
|
107
|
-
# if change_to_text
|
108
|
-
# out << @template.content_tag(:div, change_to_text, :class => 'form_element submit_text')
|
109
|
-
# end
|
110
|
-
# out.html_safe
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
# generic container for all things form
|
115
|
-
def element(label = ' ', value = '', type = 'text_field', &block)
|
116
|
-
value += @template.capture(&block) if block_given?
|
117
|
-
%{
|
118
|
-
<div class='form_element #{type}'>
|
119
|
-
<div class='label'>
|
120
|
-
#{label}
|
121
|
-
</div>
|
122
|
-
<div class='value'>
|
123
|
-
#{value}
|
124
|
-
</div>
|
125
|
-
</div>
|
126
|
-
}.html_safe
|
127
|
-
end
|
128
|
-
|
129
|
-
def error_messages
|
130
|
-
if object && !object.errors.empty?
|
131
|
-
message = object.errors[:base].present? ? object.errors[:base]: 'There were some problems submitting this form. Please correct all the highlighted fields and try again'
|
132
|
-
@template.content_tag(:div, message, :class => 'form_error')
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def error_messages_for(method)
|
137
|
-
if (object and object.respond_to?(:errors) and errors = object.errors[method] and !errors.empty?)
|
138
|
-
errors.is_a?(Array) ? errors.first : errors
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def fields_for(record_or_name_or_array, *args, &block)
|
143
|
-
options = args.extract_options!
|
144
|
-
options.merge!(:builder => FormattedForm::Builder)
|
145
|
-
super(record_or_name_or_array, *(args << options), &block)
|
146
|
-
end
|
147
|
-
|
148
|
-
|
149
|
-
protected
|
150
|
-
|
151
|
-
# Main rendering method
|
152
|
-
def render_field(field_name, method, options={}, &block)
|
153
|
-
case field_name
|
154
|
-
when 'check_box'
|
155
|
-
template = field_name
|
156
|
-
else
|
157
|
-
template = 'default_field'
|
158
|
-
end
|
159
|
-
@template.render(:partial => "#{FormattedForm.config.template}/#{template}", :locals => {
|
160
|
-
:builder => self,
|
161
|
-
:method => method,
|
162
|
-
:field_name => field_name,
|
163
|
-
:field => @template.capture(&block),
|
164
|
-
:label_text => label_text(method, options.delete(:label)),
|
165
|
-
:required => options.delete(:required),
|
166
|
-
:before_text => @template.raw(options.delete(:before_text)),
|
167
|
-
:after_text => @template.raw(options.delete(:after_text)),
|
168
|
-
:description => @template.raw(options.delete(:desc)),
|
169
|
-
:error_messages => error_messages_for(method)
|
170
|
-
})
|
171
|
-
end
|
172
|
-
|
173
|
-
def label_text(method, text = nil)
|
174
|
-
text.blank? ? method.to_s.titleize.capitalize : @template.raw(text)
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module FormattedForm
|
2
|
-
class Configuration
|
3
|
-
|
4
|
-
# The templates used to use the views.
|
5
|
-
# Options are
|
6
|
-
# :formatted_form - the default rendering template
|
7
|
-
# :twitter_bootstrap - Twitter Bootstrap templates
|
8
|
-
attr_accessor :template
|
9
|
-
|
10
|
-
# Configuration defaults
|
11
|
-
def initialize
|
12
|
-
@template = :formatted_form
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
module FormattedForm::Helper
|
2
|
-
|
3
|
-
def formatted_form_for(record_or_name_or_array, *args, &proc)
|
4
|
-
options = args.extract_options!
|
5
|
-
options.merge!(:builder => FormattedForm::Builder)
|
6
|
-
(options[:html] ||= { }).merge!(:class => "#{options[:html][:class]} formatted")
|
7
|
-
form_for(record_or_name_or_array, *(args << options), &proc)
|
8
|
-
end
|
9
|
-
|
10
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module FormattedForm
|
2
|
-
class JavascriptsGenerator < Rails::Generators::Base
|
3
|
-
|
4
|
-
source_root File.expand_path('../../../../..', __FILE__)
|
5
|
-
|
6
|
-
def generate_javascripts
|
7
|
-
copy_file 'templates/javascripts/formatted_form.js', 'public/javascripts/formatted_form.js'
|
8
|
-
end
|
9
|
-
|
10
|
-
end
|
11
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module FormattedForm
|
2
|
-
class StylesheetsGenerator < Rails::Generators::Base
|
3
|
-
|
4
|
-
source_root File.expand_path('../../../../..', __FILE__)
|
5
|
-
|
6
|
-
def generate_stylesheets
|
7
|
-
copy_file 'templates/stylesheets/formatted_form.sass', 'app/views/stylesheets/formatted_form.sass'
|
8
|
-
end
|
9
|
-
|
10
|
-
end
|
11
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
// Reset the state of the submit button
|
2
|
-
$(document).ready(function() {
|
3
|
-
$('.form_element.submit.change_to_text').show();
|
4
|
-
$('.submit_text').hide();
|
5
|
-
});
|
6
|
-
|
7
|
-
// Shows the submit button replacement text on click
|
8
|
-
$('.form_element.submit.change_to_text input[type=submit]').live('click', function(){
|
9
|
-
$(this).parent().next().show();
|
10
|
-
$(this).parent().hide();
|
11
|
-
})
|
12
|
-
|
13
|
-
// Activates the submit button click when clicking the image button
|
14
|
-
$('.form_element.submit a.submit_image').live('click', function(){
|
15
|
-
$(this).prev().click();
|
16
|
-
return false;
|
17
|
-
})
|
@@ -1,121 +0,0 @@
|
|
1
|
-
form.formatted
|
2
|
-
font: 13px/20px Trebuchet MS,serif
|
3
|
-
margin: auto
|
4
|
-
background: #eee
|
5
|
-
border: solid #ddd 2px
|
6
|
-
color: #000
|
7
|
-
width: 50%
|
8
|
-
padding: 10px 20px
|
9
|
-
-webkit-box-shadow: 0 1px 4px rgba(0,0,0,0.3)
|
10
|
-
-moz-box-shadow: 0 1px 4px rgba(0,0,0,0.3)
|
11
|
-
box-shadow: 0 1px 4px rgba(0,0,0,0.3)
|
12
|
-
|
13
|
-
// --- Form element container ---
|
14
|
-
.form_element
|
15
|
-
overflow: hidden
|
16
|
-
_height: 1%
|
17
|
-
margin-bottom: 1px
|
18
|
-
padding: 5px 0px
|
19
|
-
.label
|
20
|
-
font: 10px/30px Trebuchet MS,serif
|
21
|
-
color: #6E666E
|
22
|
-
text-transform: uppercase
|
23
|
-
letter-spacing: 1px
|
24
|
-
float: left
|
25
|
-
width: 120px
|
26
|
-
text-align: right
|
27
|
-
.value
|
28
|
-
margin-left: 130px
|
29
|
-
.errors
|
30
|
-
font: 9px/12px Trebuchet MS, serif
|
31
|
-
color: #BE1E2D
|
32
|
-
clear: both
|
33
|
-
.description
|
34
|
-
clear: both
|
35
|
-
font: italic 10px/12px Trebuchet MS, serif
|
36
|
-
|
37
|
-
// --- Text and password fields ---
|
38
|
-
.form_element.text_field, .form_element.password_field
|
39
|
-
input
|
40
|
-
width: 250px
|
41
|
-
border: 1px solid #a6a8ab
|
42
|
-
padding: 5px
|
43
|
-
width: 90%
|
44
|
-
|
45
|
-
// --- Text area ---
|
46
|
-
.form_element.text_area
|
47
|
-
textarea
|
48
|
-
width: 250px
|
49
|
-
height: 150px
|
50
|
-
|
51
|
-
// --- Check box and Radio button ---
|
52
|
-
.form_element.check_box, .form_element.radio_button
|
53
|
-
.value
|
54
|
-
label
|
55
|
-
font: 10px/20px Trebuchet MS,serif
|
56
|
-
color: #6E666E
|
57
|
-
text-transform: uppercase
|
58
|
-
margin-right: 10px
|
59
|
-
letter-spacing: 0.1em
|
60
|
-
input
|
61
|
-
margin-right: 5px
|
62
|
-
.field_with_errors
|
63
|
-
float: left
|
64
|
-
|
65
|
-
.form_element.radio_button
|
66
|
-
.value
|
67
|
-
.option
|
68
|
-
float: left
|
69
|
-
.option + .option
|
70
|
-
margin-left: 10px
|
71
|
-
|
72
|
-
|
73
|
-
// --- Submit button ---
|
74
|
-
.form_element.submit
|
75
|
-
padding-left: 130px
|
76
|
-
a.submit_image
|
77
|
-
padding: 5px 10px
|
78
|
-
font: bold 12px/20px helvetica,arial,freesans,clean,sans-serif
|
79
|
-
text-decoration: none
|
80
|
-
color: #333
|
81
|
-
text-shadow: 1px 1px 0 #fff
|
82
|
-
white-space: nowrap
|
83
|
-
border: none
|
84
|
-
overflow: visible
|
85
|
-
background: #ddd
|
86
|
-
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#ffffff',endColorstr='#e1e1e1')
|
87
|
-
background: -webkit-gradient(linear,0% 0,0% 100%,from(#fff),to(#e1e1e1))
|
88
|
-
background: -moz-linear-gradient(-90deg,#fff,#e1e1e1)
|
89
|
-
border-bottom: 1px solid #ebebeb
|
90
|
-
-webkit-border-radius: 4px
|
91
|
-
-moz-border-radius: 4px
|
92
|
-
border-radius: 4px
|
93
|
-
-webkit-box-shadow: 0 1px 4px rgba(0,0,0,0.3)
|
94
|
-
-moz-box-shadow: 0 1px 4px rgba(0,0,0,0.3)
|
95
|
-
box-shadow: 0 1px 4px rgba(0,0,0,0.3)
|
96
|
-
cursor: pointer
|
97
|
-
-webkit-font-smoothing: subpixel-antialiased!important
|
98
|
-
a.submit_image:hover
|
99
|
-
color: #fff
|
100
|
-
text-decoration: none
|
101
|
-
text-shadow: -1px -1px 0 rgba(0,0,0,0.3)
|
102
|
-
border-color: #518cc6
|
103
|
-
border-bottom-color: #2a65a0
|
104
|
-
background: #599bdc
|
105
|
-
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#599bdc',endColorstr='#3072b3')
|
106
|
-
background: -webkit-gradient(linear,left top,left bottom,from(#599bdc),to(#3072b3))
|
107
|
-
background: -moz-linear-gradient(top,#599bdc,#3072b3)
|
108
|
-
|
109
|
-
|
110
|
-
.form_element.submit_text
|
111
|
-
padding-left: 130px
|
112
|
-
font: normal 12px/20px Trebuchet MS,serif
|
113
|
-
|
114
|
-
// --- Form error ---
|
115
|
-
.form_error
|
116
|
-
background-color: #BE1E2D
|
117
|
-
color: #fff
|
118
|
-
text-align: center
|
119
|
-
padding: 10px
|
120
|
-
margin-bottom: 1px
|
121
|
-
font-size: 14px
|