formatted_form 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/app/views/formatted_form/_check_box.html.haml +3 -2
- data/app/views/formatted_form/_default_field.html.haml +6 -4
- data/app/views/formatted_form/_radio_button.html.haml +2 -2
- data/app/views/formatted_form/_submit.html.haml +3 -0
- data/app/views/twitter_bootstrap/_check_box.html.haml +18 -0
- data/app/views/twitter_bootstrap/_default_field.html.haml +10 -0
- data/app/views/twitter_bootstrap/_radio_button.html.haml +24 -0
- data/app/views/twitter_bootstrap/_submit.html.haml +3 -0
- data/formatted_form.gemspec +11 -4
- data/lib/formatted_form/builder.rb +65 -29
- data/lib/formatted_form/configuration.rb +16 -0
- data/lib/formatted_form/engine.rb +8 -1
- data/lib/formatted_form/helper.rb +10 -0
- data/lib/formatted_form.rb +15 -10
- data/templates/stylesheets/formatted_form.sass +6 -2
- metadata +29 -29
data/Rakefile
CHANGED
@@ -3,11 +3,10 @@ require 'rake'
|
|
3
3
|
require 'jeweler'
|
4
4
|
|
5
5
|
Jeweler::Tasks.new do |gem|
|
6
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
7
6
|
gem.name = "formatted_form"
|
8
7
|
gem.homepage = "http://github.com/twg/formatted_form"
|
9
8
|
gem.license = "MIT"
|
10
|
-
gem.summary = "A Rails form builder to simplify
|
9
|
+
gem.summary = "A Rails form builder to simplify your forms"
|
11
10
|
gem.description = ''
|
12
11
|
gem.email = "jack@theworkinggroup.ca"
|
13
12
|
gem.authors = ["Jack Neto"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
.value
|
4
4
|
= field
|
5
|
-
= label_text
|
5
|
+
= builder.label(method, label_text)
|
6
|
+
|
6
7
|
- if required
|
7
8
|
%span.required *
|
8
9
|
|
9
10
|
- if error_messages.present?
|
10
|
-
|
11
|
+
.errors= error_messages
|
11
12
|
|
12
13
|
- if description.present?
|
13
14
|
.description= description
|
@@ -1,6 +1,6 @@
|
|
1
1
|
.form_element{:class => "#{field_name}"}
|
2
2
|
.label
|
3
|
-
= label_text
|
3
|
+
= builder.label(method, label_text)
|
4
4
|
- if required
|
5
5
|
%span.required *
|
6
6
|
|
@@ -8,8 +8,10 @@
|
|
8
8
|
= before_text
|
9
9
|
= field
|
10
10
|
= after_text
|
11
|
-
- if error_messages.present?
|
12
|
-
= error_messages
|
13
11
|
|
14
12
|
- if description.present?
|
15
|
-
.description= description
|
13
|
+
.description= description
|
14
|
+
|
15
|
+
- if error_messages.present?
|
16
|
+
.errors= error_messages
|
17
|
+
|
@@ -8,10 +8,10 @@
|
|
8
8
|
- choices.each do |choice|
|
9
9
|
.option
|
10
10
|
= choice[:field]
|
11
|
-
= choice[:label]
|
11
|
+
%label{:for => choice[:label_for]}= choice[:label]
|
12
12
|
|
13
13
|
- if error_messages.present?
|
14
|
-
|
14
|
+
.errors= error_messages
|
15
15
|
|
16
16
|
- if description.present?
|
17
17
|
.description= description
|
@@ -0,0 +1,18 @@
|
|
1
|
+
.clearfix{:class => ('error' if error_messages.present?)}
|
2
|
+
|
3
|
+
.input
|
4
|
+
%ul.inputs-list
|
5
|
+
%li
|
6
|
+
%label
|
7
|
+
= field
|
8
|
+
%span
|
9
|
+
= label_text
|
10
|
+
- if required
|
11
|
+
%span.required *
|
12
|
+
|
13
|
+
- if error_messages.present?
|
14
|
+
%span.help-inline= error_messages
|
15
|
+
- if description.present?
|
16
|
+
%span.help-block= description
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,24 @@
|
|
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
|
+
|
data/formatted_form.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{formatted_form}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jack Neto"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-10-16}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{jack@theworkinggroup.ca}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,10 +24,17 @@ Gem::Specification.new do |s|
|
|
24
24
|
"app/views/formatted_form/_check_box.html.haml",
|
25
25
|
"app/views/formatted_form/_default_field.html.haml",
|
26
26
|
"app/views/formatted_form/_radio_button.html.haml",
|
27
|
+
"app/views/formatted_form/_submit.html.haml",
|
28
|
+
"app/views/twitter_bootstrap/_check_box.html.haml",
|
29
|
+
"app/views/twitter_bootstrap/_default_field.html.haml",
|
30
|
+
"app/views/twitter_bootstrap/_radio_button.html.haml",
|
31
|
+
"app/views/twitter_bootstrap/_submit.html.haml",
|
27
32
|
"formatted_form.gemspec",
|
28
33
|
"lib/formatted_form.rb",
|
29
34
|
"lib/formatted_form/builder.rb",
|
35
|
+
"lib/formatted_form/configuration.rb",
|
30
36
|
"lib/formatted_form/engine.rb",
|
37
|
+
"lib/formatted_form/helper.rb",
|
31
38
|
"lib/generators/formatted_form/javascripts/javascripts_generator.rb",
|
32
39
|
"lib/generators/formatted_form/stylesheets/stylesheets_generator.rb",
|
33
40
|
"templates/javascripts/formatted_form.js",
|
@@ -36,8 +43,8 @@ Gem::Specification.new do |s|
|
|
36
43
|
s.homepage = %q{http://github.com/twg/formatted_form}
|
37
44
|
s.licenses = ["MIT"]
|
38
45
|
s.require_paths = ["lib"]
|
39
|
-
s.rubygems_version = %q{1.
|
40
|
-
s.summary = %q{A Rails form builder to simplify
|
46
|
+
s.rubygems_version = %q{1.6.2}
|
47
|
+
s.summary = %q{A Rails form builder to simplify your forms}
|
41
48
|
|
42
49
|
if s.respond_to? :specification_version then
|
43
50
|
s.specification_version = 3
|
@@ -33,19 +33,23 @@ module FormattedForm
|
|
33
33
|
end
|
34
34
|
{
|
35
35
|
:field => super(method, choice[1], options),
|
36
|
-
:label =>
|
36
|
+
:label => choice[0],
|
37
|
+
:label_for => "#{object_name}_#{method}_#{choice[1].to_s.gsub(' ', '_').underscore}"
|
37
38
|
}
|
38
39
|
end
|
39
40
|
else
|
40
41
|
choices = [{
|
41
42
|
:field => super(method, tag_value),
|
42
|
-
:label =>
|
43
|
+
:label => tag_value,
|
44
|
+
:label_for => "#{object_name}_#{method}_#{tag_value.to_s.gsub(' ', '_').underscore}"
|
43
45
|
}]
|
44
46
|
end
|
45
47
|
|
46
|
-
@template.render(:partial => "
|
48
|
+
@template.render(:partial => "#{FormattedForm.config.template}/radio_button", :locals => {
|
49
|
+
:builder => self,
|
50
|
+
:method => method,
|
47
51
|
:field_name => 'radio_button',
|
48
|
-
:label_text =>
|
52
|
+
:label_text => label_text(method, options.delete(:label)),
|
49
53
|
:choices => choices,
|
50
54
|
:required => options.delete(:required),
|
51
55
|
:before_text => @template.raw(options.delete(:before_text)),
|
@@ -58,24 +62,53 @@ module FormattedForm
|
|
58
62
|
|
59
63
|
# f.submit 'Log In', :change_to_text => 'Logging you in ...'
|
60
64
|
def submit(value, options={}, &block)
|
61
|
-
|
62
|
-
|
63
|
-
|
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'
|
64
81
|
|
65
|
-
|
66
|
-
if options.delete(:
|
67
|
-
|
68
|
-
|
69
|
-
content << cancel_link.html_safe
|
70
|
-
else
|
71
|
-
super(value, options) + cancel_link.html_safe
|
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>'))"
|
72
86
|
end
|
73
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
|
74
111
|
|
75
|
-
if change_to_text
|
76
|
-
out << @template.content_tag(:div, change_to_text, :class => 'form_element submit_text')
|
77
|
-
end
|
78
|
-
out.html_safe
|
79
112
|
end
|
80
113
|
|
81
114
|
# generic container for all things form
|
@@ -102,19 +135,20 @@ module FormattedForm
|
|
102
135
|
|
103
136
|
def error_messages_for(method)
|
104
137
|
if (object and object.respond_to?(:errors) and errors = object.errors[method] and !errors.empty?)
|
105
|
-
|
138
|
+
errors.is_a?(Array) ? errors.first : errors
|
106
139
|
end
|
107
140
|
end
|
108
141
|
|
109
|
-
def
|
142
|
+
def fields_for(record_or_name_or_array, *args, &block)
|
110
143
|
options = args.extract_options!
|
111
144
|
options.merge!(:builder => FormattedForm::Builder)
|
112
|
-
|
145
|
+
super(record_or_name_or_array, *(args << options), &block)
|
113
146
|
end
|
114
|
-
|
147
|
+
|
115
148
|
|
116
149
|
protected
|
117
150
|
|
151
|
+
# Main rendering method
|
118
152
|
def render_field(field_name, method, options={}, &block)
|
119
153
|
case field_name
|
120
154
|
when 'check_box'
|
@@ -122,21 +156,23 @@ module FormattedForm
|
|
122
156
|
else
|
123
157
|
template = 'default_field'
|
124
158
|
end
|
125
|
-
@template.render(:partial => "
|
159
|
+
@template.render(:partial => "#{FormattedForm.config.template}/#{template}", :locals => {
|
160
|
+
:builder => self,
|
161
|
+
:method => method,
|
126
162
|
:field_name => field_name,
|
127
|
-
:
|
163
|
+
:field => @template.capture(&block),
|
164
|
+
:label_text => label_text(method, options.delete(:label)),
|
128
165
|
:required => options.delete(:required),
|
129
166
|
:before_text => @template.raw(options.delete(:before_text)),
|
130
167
|
:after_text => @template.raw(options.delete(:after_text)),
|
131
|
-
:field => @template.capture(&block),
|
132
168
|
:description => @template.raw(options.delete(:desc)),
|
133
169
|
:error_messages => error_messages_for(method)
|
134
170
|
})
|
135
171
|
end
|
136
172
|
|
137
|
-
def
|
138
|
-
|
139
|
-
end
|
140
|
-
|
173
|
+
def label_text(method, text = nil)
|
174
|
+
text.blank? ? method.to_s.titleize.capitalize : @template.raw(text)
|
175
|
+
end
|
176
|
+
|
141
177
|
end
|
142
178
|
end
|
@@ -0,0 +1,16 @@
|
|
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
|
@@ -3,8 +3,15 @@ require "rails"
|
|
3
3
|
|
4
4
|
module FormattedForm
|
5
5
|
class Engine < Rails::Engine
|
6
|
+
|
6
7
|
initializer 'formatted_form_helper' do |app|
|
7
|
-
ActionView::Base.send(:include, FormattedForm::
|
8
|
+
ActionView::Base.send(:include, FormattedForm::Helper)
|
9
|
+
|
10
|
+
# Removing field_with_errors div araound elemetns with errors
|
11
|
+
if FormattedForm.config.template == :twitter_bootstrap
|
12
|
+
ActionView::Base.field_error_proc = proc { |input, instance| input }
|
13
|
+
end
|
8
14
|
end
|
15
|
+
|
9
16
|
end
|
10
17
|
end
|
@@ -0,0 +1,10 @@
|
|
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
|
data/lib/formatted_form.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
|
+
require 'formatted_form/engine' if defined?(Rails)
|
2
|
+
require 'formatted_form/builder'
|
3
|
+
require 'formatted_form/helper'
|
4
|
+
require 'formatted_form/configuration'
|
5
|
+
|
1
6
|
module FormattedForm
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def formatted_form_for(record_or_name_or_array, *args, &proc)
|
7
|
-
options = args.extract_options!
|
8
|
-
options.merge!(:builder => FormattedForm::Builder)
|
9
|
-
(options[:html] ||= { }).merge!(:class => "#{options[:html][:class]} formatted")
|
10
|
-
form_for(record_or_name_or_array, *(args << options), &proc)
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def configure
|
10
|
+
yield configuration
|
11
11
|
end
|
12
|
+
|
13
|
+
def configuration
|
14
|
+
@configuration ||= Configuration.new
|
15
|
+
end
|
16
|
+
alias :config :configuration
|
17
|
+
|
12
18
|
end
|
13
|
-
|
14
19
|
end
|
15
20
|
|
@@ -4,7 +4,7 @@ form.formatted
|
|
4
4
|
background: #eee
|
5
5
|
border: solid #ddd 2px
|
6
6
|
color: #000
|
7
|
-
width:
|
7
|
+
width: 50%
|
8
8
|
padding: 10px 20px
|
9
9
|
-webkit-box-shadow: 0 1px 4px rgba(0,0,0,0.3)
|
10
10
|
-moz-box-shadow: 0 1px 4px rgba(0,0,0,0.3)
|
@@ -29,6 +29,7 @@ form.formatted
|
|
29
29
|
.errors
|
30
30
|
font: 9px/12px Trebuchet MS, serif
|
31
31
|
color: #BE1E2D
|
32
|
+
clear: both
|
32
33
|
.description
|
33
34
|
clear: both
|
34
35
|
font: italic 10px/12px Trebuchet MS, serif
|
@@ -58,13 +59,16 @@ form.formatted
|
|
58
59
|
letter-spacing: 0.1em
|
59
60
|
input
|
60
61
|
margin-right: 5px
|
61
|
-
.
|
62
|
+
.field_with_errors
|
62
63
|
float: left
|
63
64
|
|
64
65
|
.form_element.radio_button
|
65
66
|
.value
|
66
67
|
.option
|
67
68
|
float: left
|
69
|
+
.option + .option
|
70
|
+
margin-left: 10px
|
71
|
+
|
68
72
|
|
69
73
|
// --- Submit button ---
|
70
74
|
.form_element.submit
|
metadata
CHANGED
@@ -1,29 +1,25 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: formatted_form
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
4
5
|
prerelease:
|
5
|
-
version: 1.0.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Jack Neto
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-04-20 00:00:00 -04:00
|
12
|
+
date: 2011-10-16 00:00:00.000000000 -04:00
|
14
13
|
default_executable:
|
15
14
|
dependencies: []
|
16
|
-
|
17
|
-
description: ""
|
15
|
+
description: ''
|
18
16
|
email: jack@theworkinggroup.ca
|
19
17
|
executables: []
|
20
|
-
|
21
18
|
extensions: []
|
22
|
-
|
23
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
24
20
|
- LICENSE.txt
|
25
21
|
- README.md
|
26
|
-
files:
|
22
|
+
files:
|
27
23
|
- LICENSE.txt
|
28
24
|
- README.md
|
29
25
|
- Rakefile
|
@@ -31,41 +27,45 @@ files:
|
|
31
27
|
- app/views/formatted_form/_check_box.html.haml
|
32
28
|
- app/views/formatted_form/_default_field.html.haml
|
33
29
|
- app/views/formatted_form/_radio_button.html.haml
|
30
|
+
- app/views/formatted_form/_submit.html.haml
|
31
|
+
- app/views/twitter_bootstrap/_check_box.html.haml
|
32
|
+
- app/views/twitter_bootstrap/_default_field.html.haml
|
33
|
+
- app/views/twitter_bootstrap/_radio_button.html.haml
|
34
|
+
- app/views/twitter_bootstrap/_submit.html.haml
|
34
35
|
- formatted_form.gemspec
|
35
36
|
- lib/formatted_form.rb
|
36
37
|
- lib/formatted_form/builder.rb
|
38
|
+
- lib/formatted_form/configuration.rb
|
37
39
|
- lib/formatted_form/engine.rb
|
40
|
+
- lib/formatted_form/helper.rb
|
38
41
|
- lib/generators/formatted_form/javascripts/javascripts_generator.rb
|
39
42
|
- lib/generators/formatted_form/stylesheets/stylesheets_generator.rb
|
40
43
|
- templates/javascripts/formatted_form.js
|
41
44
|
- templates/stylesheets/formatted_form.sass
|
42
45
|
has_rdoc: true
|
43
46
|
homepage: http://github.com/twg/formatted_form
|
44
|
-
licenses:
|
47
|
+
licenses:
|
45
48
|
- MIT
|
46
49
|
post_install_message:
|
47
50
|
rdoc_options: []
|
48
|
-
|
49
|
-
require_paths:
|
51
|
+
require_paths:
|
50
52
|
- lib
|
51
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
54
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version:
|
57
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
60
|
none: false
|
59
|
-
requirements:
|
60
|
-
- -
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version:
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
63
65
|
requirements: []
|
64
|
-
|
65
66
|
rubyforge_project:
|
66
|
-
rubygems_version: 1.
|
67
|
+
rubygems_version: 1.6.2
|
67
68
|
signing_key:
|
68
69
|
specification_version: 3
|
69
|
-
summary: A Rails form builder to simplify
|
70
|
+
summary: A Rails form builder to simplify your forms
|
70
71
|
test_files: []
|
71
|
-
|