JimNeath-fudge-form 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/MIT-LICENSE +20 -0
- data/README.textile +13 -0
- data/Rakefile +22 -0
- data/fudge-form.gemspec +20 -0
- data/initializers/fudge_form.rb +1 -0
- data/install.rb +8 -0
- data/lib/fudge_form_builder.rb +128 -0
- data/lib/fudge_form_helper.rb +43 -0
- metadata +60 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
h1. Fudge Form
|
2
|
+
|
3
|
+
Fudge Form is a way of building easier, semantically correct forms using a custom form builder.
|
4
|
+
Building forms in rails is boring and repetitive. This plugin helps to remove the boredom and
|
5
|
+
fills you full of form building mega powers.
|
6
|
+
|
7
|
+
Fudge Form is based on "Semantic Form Builder":http://github.com/rubypond/semantic_form_builder/tree/master by "Ruby Pond":http://rubypond.com/. The main difference is that
|
8
|
+
Fudge Form generates forms to fit with the method of building forms described on "A List Apart":http://www.alistapart.com/articles/prettyaccessibleforms/
|
9
|
+
using fieldsets and ols to wrap your content.
|
10
|
+
|
11
|
+
This plugin is currently experimental and does not have any tests. Use at your own peril.
|
12
|
+
|
13
|
+
Copyright (c) 2008 Jim Neath / Fudge Studios Ltd, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the fudge_forms plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the fudge_forms plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'FudgeForms'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
data/fudge-form.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "fudge-form"
|
3
|
+
s.version = "0.1"
|
4
|
+
s.date = "2008-09-18"
|
5
|
+
s.summary = "Semantic form builder."
|
6
|
+
s.email = "jim@fudgestudios.com"
|
7
|
+
s.homepage = "http://github.com/JimNeath/fudge-form"
|
8
|
+
s.description = "Fudge Form is a way of building easier, semantically correct forms using a custom form builder. Building forms in rails is boring and repetitive. This plugin helps to remove the boredom and fills you full of form building mega powers."
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.authors = ["Jim Neath"]
|
11
|
+
s.files = ["fudge-form.gemspec",
|
12
|
+
"install.rb",
|
13
|
+
"MIT-LICENSE",
|
14
|
+
"Rakefile",
|
15
|
+
"README.textile",
|
16
|
+
"initializers/fudge_form.rb",
|
17
|
+
"lib/fudge_form_builder.rb",
|
18
|
+
"lib/fudge_form_helper.rb"]
|
19
|
+
s.test_files = []
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
ActionView::Base.default_form_builder = FudgeFormBuilder
|
data/install.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
puts "Copying file..."
|
2
|
+
dir = "initializers"
|
3
|
+
["fudge_form.rb"].each do |file|
|
4
|
+
dest_file = File.join(RAILS_ROOT, "config", dir, file)
|
5
|
+
src_file = File.join(File.dirname(__FILE__) , dir, file)
|
6
|
+
FileUtils.cp_r(src_file, dest_file)
|
7
|
+
end
|
8
|
+
puts "File copied - Installation complete!"
|
@@ -0,0 +1,128 @@
|
|
1
|
+
class FudgeFormBuilder < ActionView::Helpers::FormBuilder
|
2
|
+
include FudgeFormHelper
|
3
|
+
|
4
|
+
def field_settings(method, options = {}, tag_value = nil)
|
5
|
+
field_name = "#{@object_name}_#{method.to_s}"
|
6
|
+
default_label = tag_value.nil? ? "#{method.to_s.humanize.titleize}" : "#{tag_value.to_s.humanize.titleize}"
|
7
|
+
label = options[:label] ? options.delete(:label) : default_label
|
8
|
+
options[:class] ||= ""
|
9
|
+
options[:class] += options[:required] ? "required" : ""
|
10
|
+
label += '<em>*</em>' if options[:required]
|
11
|
+
options.delete(:required)
|
12
|
+
[field_name, label, options]
|
13
|
+
end
|
14
|
+
|
15
|
+
def text_field(method, options = {})
|
16
|
+
add_class_name(options, 'text')
|
17
|
+
field_name, label, options = field_settings(method, options)
|
18
|
+
wrapping("text", field_name, label, super, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def file_field(method, options = {})
|
22
|
+
add_class_name(options, 'file')
|
23
|
+
field_name, label, options = field_settings(method, options)
|
24
|
+
wrapping("file", field_name, label, super, options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def datetime_select(method, options = {}, html_options = {})
|
28
|
+
options[:order] = [:day, :month, :year]
|
29
|
+
add_class_name(html_options, 'select')
|
30
|
+
field_name, label, options = field_settings(method, options)
|
31
|
+
wrapping("datetime", field_name, label, super, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def date_select(method, options = {}, html_options = {})
|
35
|
+
options[:order] = [:day, :month, :year]
|
36
|
+
add_class_name(html_options, 'select')
|
37
|
+
field_name, label, options = field_settings(method, options)
|
38
|
+
wrapping("date", field_name, label, super, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def radio_button(method, tag_value, options = {})
|
42
|
+
add_class_name(options, 'radio')
|
43
|
+
field_name, label, options = field_settings(method, options)
|
44
|
+
wrapping("radio", field_name, label, super, options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
|
48
|
+
add_class_name(options, 'checkbox')
|
49
|
+
field_name, label, options = field_settings(method, options)
|
50
|
+
wrapping("check-box", field_name, label, super, options)
|
51
|
+
end
|
52
|
+
|
53
|
+
def select(method, choices, options = {}, html_options = {})
|
54
|
+
add_class_name(html_options, 'select')
|
55
|
+
field_name, label, options = field_settings(method, options)
|
56
|
+
wrapping("select", field_name, label, super, options)
|
57
|
+
end
|
58
|
+
|
59
|
+
def password_field(method, options = {})
|
60
|
+
add_class_name(options, 'password')
|
61
|
+
field_name, label, options = field_settings(method, options)
|
62
|
+
wrapping("password", field_name, label, super, options)
|
63
|
+
end
|
64
|
+
|
65
|
+
def text_area(method, options = {})
|
66
|
+
options[:rows] = 5
|
67
|
+
add_class_name(options, 'textarea')
|
68
|
+
field_name, label, options = field_settings(method, options)
|
69
|
+
wrapping("textarea", field_name, label, super, options)
|
70
|
+
end
|
71
|
+
|
72
|
+
def radio_button_group(method, values, options = {})
|
73
|
+
add_class_name(options, 'radio')
|
74
|
+
selections = []
|
75
|
+
values.each do |value|
|
76
|
+
if value.is_a?(Array)
|
77
|
+
tag_value = value.last
|
78
|
+
value_text = value.first
|
79
|
+
else
|
80
|
+
tag_value = value
|
81
|
+
value_text = value
|
82
|
+
end
|
83
|
+
radio_button = @template.radio_button(@object_name, method, tag_value, options.merge(:object => @object))
|
84
|
+
selections << boolean_field_wrapper(radio_button, "#{@object_name}_#{method.to_s}", tag_value, value_text)
|
85
|
+
end
|
86
|
+
selections
|
87
|
+
field_name, label, options = field_settings(method, options)
|
88
|
+
semantic_group("radio", field_name, label, selections, options)
|
89
|
+
end
|
90
|
+
|
91
|
+
def check_box_group(method, values, options = {})
|
92
|
+
add_class_name(options, 'checkbox')
|
93
|
+
selections = []
|
94
|
+
values.each do |value|
|
95
|
+
if value.is_a?(Array)
|
96
|
+
checked_value = value.last.to_i
|
97
|
+
value_text = value.first
|
98
|
+
else
|
99
|
+
checked_value = 1
|
100
|
+
value_text = value
|
101
|
+
end
|
102
|
+
check_box = check_box = @template.check_box_tag("#{@object_name}[#{method.to_s}][]", checked_value, @object.send(method).include?(checked_value), options.merge(:object => @object))
|
103
|
+
selections << boolean_field_wrapper(check_box, "#{@object_name}_#{method.to_s}", checked_value, value_text)
|
104
|
+
end
|
105
|
+
field_name, label, options = field_settings(method, options)
|
106
|
+
semantic_group("check-box", field_name, label, selections, options)
|
107
|
+
end
|
108
|
+
|
109
|
+
def submit(method, options = {})
|
110
|
+
add_class_name(options, 'submit')
|
111
|
+
%Q{<div class="buttons">#{super}</div>}
|
112
|
+
end
|
113
|
+
|
114
|
+
def submit_and_back(submit_name, options = {})
|
115
|
+
add_class_name(options, 'submit')
|
116
|
+
submit_button = @template.submit_tag(submit_name, options)
|
117
|
+
back_link = @template.link_to('Back', :back, :class => 'back')
|
118
|
+
%Q{<div class="buttons">#{submit_button} #{back_link}</div>}
|
119
|
+
end
|
120
|
+
|
121
|
+
protected
|
122
|
+
|
123
|
+
def add_class_name(options, class_name)
|
124
|
+
classes = (options[:class]) ? options[:class].split(' ') : []
|
125
|
+
options[:class] = (classes << class_name).join(' ')
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module FudgeFormHelper
|
2
|
+
|
3
|
+
def wrapping(type, field_name, label, field, options = {})
|
4
|
+
help = %Q{<small>#{options[:help]}</small>} if options[:help]
|
5
|
+
to_return = []
|
6
|
+
to_return << %Q{<li class="#{options[:class]}">}
|
7
|
+
to_return << options[:before_html] if options[:before_html]
|
8
|
+
to_return << %Q{<label for="#{field_name}">#{label}</label>} unless ["radio","check", "submit"].include?(type)
|
9
|
+
to_return << field
|
10
|
+
to_return << %Q{<label for="#{field_name}">#{label}</label>} if ["radio","check"].include?(type)
|
11
|
+
to_return << help
|
12
|
+
to_return << options[:after_html] if options[:after_html]
|
13
|
+
to_return << %Q{</li>}
|
14
|
+
end
|
15
|
+
|
16
|
+
def semantic_group(type, field_name, label, fields, options = {})
|
17
|
+
help = %Q{<span class="help">#{options[:help]}</span>} if options[:help]
|
18
|
+
to_return = []
|
19
|
+
to_return << %Q{<li><fieldset class="#{options[:class]}">}
|
20
|
+
to_return << %Q{<legend>#{label}</legend>}
|
21
|
+
to_return << %Q{<ol>}
|
22
|
+
to_return << fields.join("\n")
|
23
|
+
to_return << %Q{</ol></fieldset></li>}
|
24
|
+
end
|
25
|
+
|
26
|
+
def boolean_field_wrapper(input, name, value, text, help = nil)
|
27
|
+
field = []
|
28
|
+
field << %Q{<li><label>#{input} #{text}</label>}
|
29
|
+
field << %Q{<small>#{help}</small>} if help
|
30
|
+
field << %Q{</li>}
|
31
|
+
field
|
32
|
+
end
|
33
|
+
|
34
|
+
def field_set(legend = nil, &block)
|
35
|
+
content = @template.capture(&block)
|
36
|
+
@template.concat(@template.tag(:fieldset, {}, true), block.binding)
|
37
|
+
@template.concat(@template.content_tag(:legend, legend), block.binding) unless legend.blank?
|
38
|
+
@template.concat(@template.tag(:ol, {}, true), block.binding)
|
39
|
+
@template.concat(content, block.binding)
|
40
|
+
@template.concat("</ol></fieldset>", block.binding)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: JimNeath-fudge-form
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jim Neath
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-09-18 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Fudge Form is a way of building easier, semantically correct forms using a custom form builder. Building forms in rails is boring and repetitive. This plugin helps to remove the boredom and fills you full of form building mega powers.
|
17
|
+
email: jim@fudgestudios.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- fudge-form.gemspec
|
26
|
+
- install.rb
|
27
|
+
- MIT-LICENSE
|
28
|
+
- Rakefile
|
29
|
+
- README.textile
|
30
|
+
- initializers/fudge_form.rb
|
31
|
+
- lib/fudge_form_builder.rb
|
32
|
+
- lib/fudge_form_helper.rb
|
33
|
+
has_rdoc: false
|
34
|
+
homepage: http://github.com/JimNeath/fudge-form
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: Semantic form builder.
|
59
|
+
test_files: []
|
60
|
+
|