Class: Facebooker::Rails::FacebookFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Facebooker::Rails::FacebookFormBuilder
- Defined in:
- lib/facebooker/rails/facebook_form_builder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_default_name_and_id(options, method) ⇒ Object
- #build_shell(field, options) ⇒ Object
- #buttons(*names) ⇒ Object
-
#collection_typeahead(method, collection, value_method, text_method, options = {}) ⇒ Object
Build a text input area that uses typeahed options are like collection_select.
- #collection_typeahead_internal(method, collection, value_method, text_method, options = {}) ⇒ Object
- #create_button(name) ⇒ Object
- #label_for(field, options) ⇒ Object
- #multi_friend_input(options = {}) ⇒ Object
- #text(string, options = {}) ⇒ Object
- #text_area(method, options = {}) ⇒ Object
- #text_field(method, options = {}) ⇒ Object
- #value_before_type_cast(object, method) ⇒ Object
Class Method Details
.create_with_offset(name, offset) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 10 def self.create_with_offset(name,offset) define_method name do |field,*args| = args[offset] || {} build_shell(field,) do super end end end |
Instance Method Details
#add_default_name_and_id(options, method) ⇒ Object
105 106 107 108 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 105 def add_default_name_and_id(,method) [:name] ||= "#{object.class.name.underscore}[#{method}]" [:id] ||= "#{object.class.name.underscore}_#{method}" end |
#build_shell(field, options) ⇒ Object
29 30 31 32 33 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 29 def build_shell(field,) @template.content_tag "fb:editor-custom", :label=>label_for(field,) do yield end end |
#buttons(*names) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 93 def (*names) =names.map do |name| (name) end.join @template.content_tag "fb:editor-buttonset", end |
#collection_typeahead(method, collection, value_method, text_method, options = {}) ⇒ Object
Build a text input area that uses typeahed options are like collection_select
61 62 63 64 65 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 61 def collection_typeahead(method,collection,value_method,text_method,={}) build_shell(method,) do collection_typeahead_internal(method,collection,value_method,text_method,) end end |
#collection_typeahead_internal(method, collection, value_method, text_method, options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 67 def collection_typeahead_internal(method,collection,value_method,text_method,={}) option_values = collection.map do |item| value=item.send(value_method) text=item.send(text_method) @template.content_tag "fb:typeahead-option",text,:value=>value end.join add_default_name_and_id(,method) ["value"] ||= value_before_type_cast(object,method) @template.content_tag("fb:typeahead-input",option_values,) end |
#create_button(name) ⇒ Object
101 102 103 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 101 def (name) @template.content_tag("fb:editor-button","",:value=>name,:name=>"commit") end |
#label_for(field, options) ⇒ Object
35 36 37 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 35 def label_for(field,) [:label] || field.to_s.humanize end |
#multi_friend_input(options = {}) ⇒ Object
87 88 89 90 91 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 87 def multi_friend_input(={}) build_shell(:friends,) do @template.content_tag("fb:multi-friend-input","",) end end |
#text(string, options = {}) ⇒ Object
39 40 41 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 39 def text(string,={}) @template.content_tag "fb:editor-custom",string, :label=>label_for("",) end |
#text_area(method, options = {}) ⇒ Object
52 53 54 55 56 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 52 def text_area(method, = {}) [:label] ||= label_for(method,) add_default_name_and_id(,method) @template.content_tag("fb:editor-textarea",value_before_type_cast(object,method),) end |
#text_field(method, options = {}) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 44 def text_field(method, = {}) [:label] ||= label_for(method,) add_default_name_and_id(,method) ["value"] ||= value_before_type_cast(object,method) @template.content_tag("fb:editor-text","",) end |
#value_before_type_cast(object, method) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 78 def value_before_type_cast(object,method) unless object.nil? method_name = method.to_s object.respond_to?(method_name + "_before_type_cast") ? object.send(method_name + "_before_type_cast") : object.send(method_name) end end |