Class: TopHat::OpenGraphHelper::OpenGraphGenerator

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers
Defined in:
lib/tophat/opengraph.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ OpenGraphGenerator

Returns a new instance of OpenGraphGenerator.

Yields:

  • (_self)

Yield Parameters:



7
8
9
10
11
12
13
# File 'lib/tophat/opengraph.rb', line 7

def initialize(options={}, &block)
  @app_id = options.delete(:app_id) if options && options.has_key?(:app_id)
  @admins = options.delete(:admins) if options && options.has_key?(:admins)
  @graph_data = {}

  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

:nodoc



46
47
48
49
# File 'lib/tophat/opengraph.rb', line 46

def method_missing(method, *args, &block) #:nodoc
  @graph_data ||= {}
  @graph_data[method] = args.shift
end

Instance Method Details

#adminsObject



24
25
26
# File 'lib/tophat/opengraph.rb', line 24

def admins
  tag(:meta, :property => 'fb:admins', :content => [*@admins].join(',')) + "\n".html_safe if @admins
end

#app_idObject



20
21
22
# File 'lib/tophat/opengraph.rb', line 20

def app_id
  tag(:meta, :property => 'fb:app_id', :content => @app_id) + "\n".html_safe if @app_id
end

#has_graph_data?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/tophat/opengraph.rb', line 42

def has_graph_data?
  !!@graph_data
end

#merge(options = {}) ⇒ Object



15
16
17
18
# File 'lib/tophat/opengraph.rb', line 15

def merge(options={})
  @app_id = options.delete(:app_id) if options && options.has_key?(:app_id)
  @admins = options.delete(:admins) if options && options.has_key?(:admins)
end

#render_graph_dataObject



28
29
30
31
32
33
34
35
# File 'lib/tophat/opengraph.rb', line 28

def render_graph_data
  output = ActiveSupport::SafeBuffer.new
  @graph_data.each do |key, value|
    output << tag(:meta, :property => "og:#{key}", :content => value)
    output << "\n".html_safe if @graph_data.size > 1
  end
  output
end

#type(t) ⇒ Object



37
38
39
40
# File 'lib/tophat/opengraph.rb', line 37

def type(t)
  @graph_data ||= {}
  @graph_data[:type] = t
end