Module: Facilbook::ApplicationHelperMethods

Defined in:
lib/facilbook.rb

Instance Method Summary collapse

Instance Method Details

#facebook_image_tag(uid, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/facilbook.rb', line 26

def facebook_image_tag(uid, options = {})
  options.symbolize_keys!
  image_url = "https://graph.facebook.com/#{uid}/picture"
  if options[:type] && (['square','small','large'].include? options[:type])
    image_url << "?type=#{type}"
  end
  
  src = image_url
  options[:src] = src
  
  unless src =~ /^cid:/
    options[:alt] = options.fetch(:alt){ File.basename(src, '.*').capitalize }
  end
  if size = options.delete(:size)
    options[:width], options[:height] = size.split("x") if size =~ %{^\d+x\d+$}
  end
  tag("img", options)
end


45
46
47
48
49
50
51
52
53
# File 'lib/facilbook.rb', line 45

def link_to_facebook(*args, &block)
  html_options = args.extract_options!.symbolize_keys
  # logger.debug "OPTIONS: #{html_options.inspect}"
  name = args[0]
  path = block_given? ? update_page(&block) : args[1] || ''
  tag_class = html_options[:class] ||= ''
  onclick = "window.top.location='#{FACILBOOK_CONFIG[:facebook_app_url]}#{path}'; return false;"
  (:a, name, html_options.merge(:href => '#', :onclick => onclick, :class => tag_class))
end

#url_for_facebook(path) ⇒ Object



55
56
57
# File 'lib/facilbook.rb', line 55

def url_for_facebook(path)
  "#{FACILBOOK_CONFIG[:facebook_app_url]}#{path}"
end