midas-ul_form_builder 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 1.0.1 2009-03-11
2
+
3
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,15 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/ul_form_builder.rb
7
+ lib/ul_form_builder/form_builders.rb
8
+ lib/ul_form_builder/form_helpers.rb
9
+ script/console
10
+ script/destroy
11
+ script/generate
12
+ spec/spec.opts
13
+ spec/spec_helper.rb
14
+ spec/ul_form_builder_spec.rb
15
+ tasks/rspec.rake
data/PostInstall.txt ADDED
@@ -0,0 +1,3 @@
1
+
2
+
3
+
data/README.rdoc ADDED
@@ -0,0 +1,83 @@
1
+ = ul_form_builder
2
+
3
+ http://github.com/midas/ul_form_builder/tree/master
4
+
5
+
6
+ == DESCRIPTION:
7
+
8
+ A Rails form builder and helpers that will render a form wrapped in ul tags, with fields wrapped in li tags. Also generates a
9
+ label with the human friendly name for the field. In addition it generates a note span and puts the hint defined in attr_human_hint
10
+ (added to ActiveRecord by Guilded (http://github.com/midas/guilded/tree/master))
11
+
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ * Builds a form wrapped in ul tags with fields wrapped in li tags
16
+ * Creates a label for the field automatically adds the human name defined by attr_human_name
17
+ * Creates a note span and automatically adds the human hint defined by attr_human_hint (added to Activerecord by Guidled (http://github.com/midas/guilded/tree/master))
18
+
19
+ == SYNOPSIS:
20
+
21
+ new.html.erb:
22
+
23
+ <% ul_form_for @item do |f| %>
24
+ <%= render :partial => 'form', :locals => { :f => f } %>
25
+ <li><%= f.submit 'Create Item' %></li>
26
+ <% end %>
27
+
28
+ _form.html.erb:
29
+
30
+ <%= f.text_field :name %>
31
+
32
+ results:
33
+
34
+ <form id="new_item" method="post" action="items">
35
+ <div style="margin: 0pt; padding: 0pt;"></div>
36
+ <ul>
37
+ <li>
38
+ <label for="item_name">Name</label>
39
+ <input id="item_name" type="text" size="65" name="item[name]" label="Name"/>
40
+ <span class="note"/>
41
+ </li>
42
+ </ul>
43
+ </form>
44
+
45
+
46
+ == REQUIREMENTS:
47
+
48
+ * Rails >= 2.2.0
49
+ * Guilded >= 0.0.7 (http://github.com/midas/guilded/tree/master)
50
+
51
+
52
+ == INSTALL:
53
+
54
+ sudo gem install midas-ul_form_builder
55
+
56
+ Rails environment.rb file:
57
+
58
+ config.gem 'midas-ul_form_builder', :version => '1.0.0', :lib => 'ul_form_builder', :source => 'http://gems.github.com'
59
+
60
+ == LICENSE:
61
+
62
+ (The MIT License)
63
+
64
+ Copyright (c) 2009 C. Jason Harrelson (midas)
65
+
66
+ Permission is hereby granted, free of charge, to any person obtaining
67
+ a copy of this software and associated documentation files (the
68
+ 'Software'), to deal in the Software without restriction, including
69
+ without limitation the rights to use, copy, modify, merge, publish,
70
+ distribute, sublicense, and/or sell copies of the Software, and to
71
+ permit persons to whom the Software is furnished to do so, subject to
72
+ the following conditions:
73
+
74
+ The above copyright notice and this permission notice shall be
75
+ included in all copies or substantial portions of the Software.
76
+
77
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
78
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
79
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
80
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
81
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
82
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
83
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/ul_form_builder'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('ul_form_builder', UlFormBuilder::VERSION) do |p|
7
+ p.developer('C. Jason Harrelson (midas)', 'jason@lookforwardenterprises.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
+ p.rubyforge_name = p.name # TODO this is default value
11
+ # p.extra_deps = [
12
+ # ['activesupport','>= 2.0.2'],
13
+ # ]
14
+ p.extra_dev_deps = [
15
+ ['newgem', ">= #{::Newgem::VERSION}"],
16
+ ['rails', ">= 2.2.0"],
17
+ ['guilded', ">= 0.0.7"]
18
+ ]
19
+
20
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
21
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
22
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
23
+ p.rsync_args = '-av --delete --ignore-errors'
24
+ end
25
+
26
+ require 'newgem/tasks' # load /tasks/*.rake
27
+ Dir['tasks/**/*.rake'].each { |t| load t }
28
+
29
+ # TODO - want other tests/tasks run by default? Add them to the list
30
+ # task :default => [:spec, :features]
@@ -0,0 +1,113 @@
1
+ require 'action_view/helpers/form_helper'
2
+
3
+ module UlFormBuilder
4
+ module FormBuilders
5
+
6
+ class GUnorderedListFormBuilder < ActionView::Helpers::FormBuilder
7
+ helpers = field_helpers +
8
+ %w{date_select datetime_select time_select} +
9
+ %w{collection_select select country_select time_zone_select} -
10
+ %w{hidden_field label fields_for} # Don't decorate these
11
+
12
+ helpers.each do |name|
13
+ define_method( name ) do |field, *args|
14
+ options = args.extract_options!
15
+
16
+ label = ""
17
+ if !options.nil? && options.has_key?( :label )
18
+ label = ( opts.respond_to?( :delete ) ? opts.delete( :label ) : nil )
19
+ else
20
+ begin
21
+ label = self.object.class.human_attribute_name( field )
22
+ rescue => ex
23
+ label = field.to_s.humanize.titleize if ex.is_a? NoMethodError
24
+ end
25
+ end
26
+
27
+ options.merge! :label => label unless options.has_key?( :label )
28
+ options.merge!( :class => 'frm-standard' ) unless options.has_key?( :class )
29
+ label = label( field, options[:label], :class => options.delete( :label_class ) )
30
+ if self.object.class.respond_to?( :human_attribute_hint )
31
+ hint = @template.content_tag( :span, self.object.class.human_attribute_hint( field.to_sym ), :class => 'note' )
32
+ else
33
+ hint = @template.content_tag( :span, (options[:hint] || ''), :class => 'note' )
34
+ end
35
+ @template.content_tag( :li, label + super( field, options ) + hint, :class => options[:li_class] ) #wrap with an li
36
+ end
37
+ end
38
+
39
+ def select( method, choices, options={}, html_options={} )
40
+ label = resolve_label( method, options )
41
+ hint = resolve_hint( options, self.object, method )
42
+ label_class = resolve_label_class( options )
43
+ field_id = resolve_field_id( method )
44
+ merge_standard_class( html_options )
45
+
46
+ super_out = super
47
+ do_output( method, field_id, label, label_class, hint, super_out )
48
+ end
49
+
50
+ def collection_select( method, collection, value_method, text_method, options={}, html_options={} )
51
+ label = resolve_label( method, options )
52
+ hint = resolve_hint( options, self.object, method )
53
+ label_class = resolve_label_class( options )
54
+ field_id = resolve_field_id( method )
55
+ merge_standard_class( html_options )
56
+
57
+ super_out = super
58
+ do_output( method, field_id, label, label_class, hint, super_out )
59
+ end
60
+
61
+ def time_zone_select( method, priority_zones=nil, options={}, html_options={} )
62
+ label = resolve_label( method, options )
63
+ hint = resolve_hint( options, self.object, method )
64
+ label_class = resolve_label_class( options )
65
+ field_id = resolve_field_id( method )
66
+ merge_standard_class( html_options )
67
+
68
+ super_out = super
69
+ do_output( method, field_id, label, label_class, hint, super_out )
70
+ end
71
+
72
+ private
73
+
74
+ def resolve_label( field, opts )
75
+ label = ""
76
+ if !opts.nil? && opts.has_key?( :label )
77
+ label = ( opts.respond_to?( :delete ) ? opts.delete( :label ) : nil )
78
+ else
79
+ begin
80
+ label = self.object.class.human_attribute_name( field )
81
+ rescue => ex
82
+ label = field.to_s.humanize.titleize if ex.is_a? NoMethodError
83
+ end
84
+ end
85
+
86
+ return label
87
+ end
88
+
89
+ def resolve_field_id( field )
90
+ CGI.escapeHTML( [self.object_name, field].join( '_' ).downcase )
91
+ end
92
+
93
+ def resolve_label_class( opts )
94
+ ( opts.respond_to?( :delete ) ? opts.delete( :label_class ) : nil )
95
+ end
96
+
97
+ def resolve_hint( opts, obj, field )
98
+ obj.class.human_attribute_hint( field.to_sym ) || ( opts.respond_to?( :delete ) ? opts.delete( :hint ) : '' )
99
+ end
100
+
101
+ def merge_standard_class( opts )
102
+ opts.merge!( :class => 'frm-standard' ) unless opts.has_key?( :class )
103
+ end
104
+
105
+ def do_output( field, field_id, label, label_class, hint, super_out )
106
+ "<li><label class=\"#{field} #{field_id} #{label_class}\" for=\"#{field_id}\"" +
107
+ ">#{label}</label>#{super_out}<span class=\"note\">" +
108
+ "#{hint}</span></li>"
109
+ end
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,42 @@
1
+ module UlFormBuilder
2
+ module FormHelpers
3
+
4
+ def ul_form_for( record_or_name_or_array, *args, &proc )
5
+ raise ArgumentError, "Missing block" unless block_given?
6
+
7
+ options = args.extract_options!
8
+ options.merge!( :builder => ActionView::Base::GUnorderedListFormBuilder )
9
+
10
+ case record_or_name_or_array
11
+ when String, Symbol
12
+ object_name = record_or_name_or_array
13
+ when Array
14
+ object = record_or_name_or_array.last
15
+ object_name = ActionController::RecordIdentifier.singular_class_name( object )
16
+ apply_form_for_options!( record_or_name_or_array, options )
17
+ args.unshift object
18
+ else
19
+ object = record_or_name_or_array
20
+ object_name = ActionController::RecordIdentifier.singular_class_name( object )
21
+ apply_form_for_options!( [object], options )
22
+ args.unshift object
23
+ end
24
+
25
+ html_options = options.delete( :html ) || {}
26
+ html_options.merge!( :class => options.delete( :class ) )
27
+
28
+ concat( form_tag( options.delete( :url ) || {}, html_options || {} ) )
29
+ concat( "<ul>" )
30
+ fields_for( object_name, *(args << options), &proc )
31
+ concat( "</ul>" )
32
+ concat( '</form>' )
33
+ end
34
+
35
+ def ul_fields_for( record_or_name_or_array, *args, &proc )
36
+ options = args.extract_options!
37
+ options.merge!( :builder => ActionView::Base::GUnorderedListFormBuilder )
38
+ fields_for( record_or_name_or_array, *(args << options), &proc )
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'ul_form_builder/form_builders'
5
+ require 'ul_form_builder/form_helpers'
6
+
7
+ module UlFormBuilder
8
+ VERSION = '1.0.1'
9
+ end
10
+
11
+ if defined?( ActionView::Base )
12
+ ActionView::Base.send( :include, UlFormBuilder::FormBuilders ) unless ActionView::Base.include?( UlFormBuilder::FormBuilders )
13
+ ActionView::Base.send( :include, UlFormBuilder::FormHelpers ) unless ActionView::Base.include?( UlFormBuilder::FormHelpers )
14
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/ul_form_builder.rb'}"
9
+ puts "Loading ul_form_builder gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'ul_form_builder'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: midas-ul_form_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - C. Jason Harrelson (midas)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-11 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newgem
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: guilded
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.0.7
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: hoe
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.0
54
+ version:
55
+ description: A Rails form builder and helpers that will render a form wrapped in ul tags, with fields wrapped in li tags. Also generates a label with the human friendly name for the field. In addition it generates a note span and puts the hint defined in attr_human_hint (added to ActiveRecord by Guilded (http://github.com/midas/guilded/tree/master))
56
+ email:
57
+ - jason@lookforwardenterprises.com
58
+ executables: []
59
+
60
+ extensions: []
61
+
62
+ extra_rdoc_files:
63
+ - History.txt
64
+ - Manifest.txt
65
+ - PostInstall.txt
66
+ - README.rdoc
67
+ files:
68
+ - History.txt
69
+ - Manifest.txt
70
+ - PostInstall.txt
71
+ - README.rdoc
72
+ - Rakefile
73
+ - lib/ul_form_builder.rb
74
+ - lib/ul_form_builder/form_builders.rb
75
+ - lib/ul_form_builder/form_helpers.rb
76
+ - script/console
77
+ - script/destroy
78
+ - script/generate
79
+ - spec/spec.opts
80
+ - spec/spec_helper.rb
81
+ - spec/ul_form_builder_spec.rb
82
+ - tasks/rspec.rake
83
+ has_rdoc: true
84
+ homepage: http://github.com/midas/ul_form_builder/tree/master
85
+ post_install_message: PostInstall.txt
86
+ rdoc_options:
87
+ - --main
88
+ - README.rdoc
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ version:
103
+ requirements: []
104
+
105
+ rubyforge_project: ul_form_builder
106
+ rubygems_version: 1.2.0
107
+ signing_key:
108
+ specification_version: 2
109
+ summary: A Rails form builder and helpers that will render a form wrapped in ul tags, with fields wrapped in li tags
110
+ test_files: []
111
+