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,.with_indifferent_access) do super(field,*args) end end end |
Instance Method Details
#add_default_name_and_id(options, method) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 106 def add_default_name_and_id(, method) @method_name = method if .has_key?("index") ["name"] ||= tag_name_with_index(["index"]) ["id"] ||= tag_id_with_index(["index"]) .delete("index") else ["name"] ||= tag_name + (.has_key?('multiple') ? '[]' : '') ["id"] ||= "#{sanitized_object_name}_#{sanitized_method_name}" end 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
94 95 96 97 98 99 100 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 94 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
62 63 64 65 66 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 62 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
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 68 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
102 103 104 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 102 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
88 89 90 91 92 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 88 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
53 54 55 56 57 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 53 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 50 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 44 def text_field(method, = {}) = .with_indifferent_access [: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
79 80 81 82 83 84 85 86 |
# File 'lib/facebooker/rails/facebook_form_builder.rb', line 79 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 |