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 +33 -24
- data/lib/homeschool.rb +2 -0
- data/lib/model_extensions.rb +7 -3
- metadata +2 -2
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
data/lib/model_extensions.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
-
module Homeschool
|
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.
|
14
|
+
self.class.human_name(field)
|
11
15
|
end
|
12
16
|
end
|
13
|
-
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.
|
7
|
-
date: 2007-10-
|
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
|