homeschool 0.0.1.31 → 0.0.1.34

Sign up to get free protection for your applications and to get access to all the features.
data/lib/form_buildr.rb CHANGED
@@ -35,32 +35,41 @@
35
35
  # labeled_text_field(:name)
36
36
  # <label class="fieldLabel" for="person_name">Name:</label>
37
37
  # <input id="person_name" name="person[name]" size="30" type="text" />
38
- #
39
- class ActionView::Helpers::FormBuilder
40
-
41
- def labeled_radio_button(method, tag_value, options={})
42
- id = %{#{@object_name}_#{method}_#{tag_value}}
43
- send(:radio_button, method, tag_value, {:id => id}.update(options.without(:label, :no_colon))) + send(:label_for, method, {:no_colon => true, :label => tag_value.humanize, :id => id}.update(options))
44
- end
45
-
46
- def labeled_check_box(method, options={}, checked_value="1", unchecked_value="0")
47
- send(:check_box, method, options.without(:label, :no_colon), checked_value, unchecked_value) + send(:label_for, method, options.update(:no_colon => true))
48
- end
49
-
50
- def labeled_select(method, choices, options={}, html_options={})
51
- label_for(method, options) + select(method, choices, options.without(:label, :no_colon), html_options)
52
- end
53
-
54
- def labeled_collection_select(method, collection, value_method, text_method, options={}, html_options={})
55
- label_for(method, options) + collection_select(method, collection, value_method, text_method, options.without(:label, :no_colon), html_options)
38
+ #
39
+ module Homeschool::FormBuildr
40
+ module ClassMethods; end
41
+ module InstanceMethods
42
+ def label_for(method, options={})
43
+ options = {:label => options} if options.is_a? String
44
+ begin
45
+ label = options[:label] || @object_name.to_s.classify.constantize.human_name(method)
46
+ rescue NameError
47
+ label = method.to_s.titleize
48
+ end
49
+ %{<label class="fieldLabel" for="#{options[:id] || "#{@object_name}_#{method}"}">#{label}#{":" if !options[:no_colon]}</label>}
50
+ end
51
+
52
+ def labeled_radio_button(method, tag_value, options={})
53
+ id = %{#{@object_name}_#{method}_#{tag_value}}
54
+ send(:radio_button, method, tag_value, {:id => id}.update(options.without(:label, :no_colon))) + send(:label_for, method, {:no_colon => true, :label => tag_value.humanize, :id => id}.update(options))
55
+ end
56
+
57
+ def labeled_check_box(method, options={}, checked_value="1", unchecked_value="0")
58
+ send(:check_box, method, options.without(:label, :no_colon), checked_value, unchecked_value) + send(:label_for, method, options.update(:no_colon => true))
59
+ end
60
+
61
+ def labeled_select(method, choices, options={}, html_options={})
62
+ label_for(method, options) + select(method, choices, options.without(:label, :no_colon), html_options)
63
+ end
64
+
65
+ def labeled_collection_select(method, collection, value_method, text_method, options={}, html_options={})
66
+ label_for(method, options) + collection_select(method, collection, value_method, text_method, options.without(:label, :no_colon), html_options)
67
+ end
56
68
  end
57
-
69
+ end
70
+ ActionView::Helpers::FormBuilder.add_extension(Homeschool::FormBuildr)
71
+ class ActionView::Helpers::FormBuilder
58
72
  rdef(/labeled_(.*)/) do |match, *args|
59
73
  return send(:label_for, *args) + send(match[1].to_sym, *args)
60
74
  end
61
-
62
- def label_for(method, options={})
63
- options = {:label => options} if options.is_a? String
64
- %{<label class="fieldLabel" for="#{options[:id] || "#{@object_name}_#{method}"}">#{options[:label] || @object.human_name(method)}#{":" if !options[:no_colon]}</label>}
65
- end
66
75
  end
data/lib/homeschool.rb CHANGED
@@ -2,6 +2,8 @@ require 'rubygems'
2
2
  require 'metaid'
3
3
  require 'active_support'
4
4
 
5
+ module Homeschool; end
6
+
5
7
  class Symbol
6
8
  def self.pattern(name, pattern, &formation)
7
9
  define_method(name) {to_s.match(pattern) ? self : formation.call(self).to_sym}
@@ -1,14 +1,18 @@
1
- module Homeschool; module ModelExtensions
1
+ module Homeschool::ModelExtensions
2
2
  module ClassMethods
3
3
  def human_field_names(hash=nil)
4
4
  @human_field_names = hash if hash
5
5
  @human_field_names || {}
6
6
  end
7
+
8
+ def human_name(field)
9
+ human_field_names[field.to_sym] || field.to_s.titleize
10
+ end
7
11
  end
8
12
  module InstanceMethods
9
13
  def human_name(field)
10
- self.class.human_field_names[field.to_sym] || field.to_s.titleize
14
+ self.class.human_name(field)
11
15
  end
12
16
  end
13
- end; end
17
+ end
14
18
  ActiveRecord::Base.add_extension(Homeschool::ModelExtensions)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: homeschool
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1.31
7
- date: 2007-10-05 00:00:00 -04:00
6
+ version: 0.0.1.34
7
+ date: 2007-10-06 00:00:00 -04:00
8
8
  summary: The homeschool gem
9
9
  require_paths:
10
10
  - lib