class Facebooker::Rails::FacebookFormBuilder

Public Instance Methods

add_default_name_and_id(options, method) click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 106
def add_default_name_and_id(options, method)
  @method_name = method
  if options.has_key?("index")
    options["name"] ||= tag_name_with_index(options["index"])
    options["id"]   ||= tag_id_with_index(options["index"])
    options.delete("index")
  else
    options["name"] ||= tag_name + (options.has_key?('multiple') ? '[]' : '')
    options["id"]   ||= "#{sanitized_object_name}_#{sanitized_method_name}"
  end
end
build_shell(field,options) { || ... } click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 29
def build_shell(field,options)
  @template.content_tag "fb:editor-custom", :label=>label_for(field,options) do
    yield
  end
end
buttons(*names) click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 94
def buttons(*names)
  buttons=names.map do |name|
    create_button(name)
  end.join
  
  @template.content_tag "fb:editor-buttonset",buttons
end
collection_typeahead(method,collection,value_method,text_method,options={}) click to toggle source

Build a text input area that uses typeahed options are like collection_select

# File lib/facebooker/rails/facebook_form_builder.rb, line 62
def collection_typeahead(method,collection,value_method,text_method,options={})
  build_shell(method,options) do
    collection_typeahead_internal(method,collection,value_method,text_method,options)
  end
end
collection_typeahead_internal(method,collection,value_method,text_method,options={}) click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 68
def collection_typeahead_internal(method,collection,value_method,text_method,options={})
  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(options,method)
  options["value"] ||= value_before_type_cast(object,method)
  @template.content_tag("fb:typeahead-input",option_values,options)        
end
create_button(name) click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 102
def create_button(name)
  @template.content_tag("fb:editor-button","",:value=>name,:name=>"commit")
end
label_for(field,options) click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 35
def label_for(field,options)
  options[:label] || field.to_s.humanize
end
multi_friend_input(options={}) click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 88
def multi_friend_input(options={})
  build_shell(:friends,options) do
    @template.content_tag("fb:multi-friend-input","",options)
  end
end
text(string,options={}) click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 39
def text(string,options={})
  @template.content_tag "fb:editor-custom",string, :label=>label_for("",options)
end
text_area(method, options = {}) click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 53
def text_area(method, options = {})
  options[:label] ||= label_for(method,options)
  add_default_name_and_id(options,method)
  @template.content_tag("fb:editor-textarea",value_before_type_cast(object,method),options)        
end
text_field(method, options = {}) click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 44
def text_field(method, options = {})
  options = options.with_indifferent_access
  options[:label] ||= label_for(method,options)
  add_default_name_and_id(options,method)
  options["value"] ||= value_before_type_cast(object,method)
  @template.content_tag("fb:editor-text","",options)
end
value_before_type_cast(object,method) click to toggle source
# 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

Public Class Methods

create_with_offset(name,offset) click to toggle source
# File lib/facebooker/rails/facebook_form_builder.rb, line 10
def self.create_with_offset(name,offset)
  define_method name do |field,*args|
    options = args[offset] || {}
    build_shell(field,options.with_indifferent_access) do
      super(field,*args)
    end
  end    
end