Class: TopHat::OpenGraphHelper::OpenGraphGenerator
- Inherits:
-
Object
- Object
- TopHat::OpenGraphHelper::OpenGraphGenerator
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.
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
48
49
50
51
|
# File 'lib/tophat/opengraph.rb', line 48
def method_missing(method, *args, &block) @graph_data ||= {}
@graph_data[method] = args.shift
end
|
Instance Method Details
#admins ⇒ Object
26
27
28
|
# File 'lib/tophat/opengraph.rb', line 26
def admins
tag(:meta, :property => 'fb:admins', :content => [*@admins].join(',')) + "\n".html_safe
end
|
#app_id ⇒ Object
22
23
24
|
# File 'lib/tophat/opengraph.rb', line 22
def app_id
tag(:meta, :property => 'fb:app_id', :content => @app_id) + "\n".html_safe
end
|
#graph_data ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/tophat/opengraph.rb', line 30
def 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
|
#has_graph_data? ⇒ Boolean
44
45
46
|
# File 'lib/tophat/opengraph.rb', line 44
def has_graph_data?
!!@graph_data
end
|
#merge(options = {}) {|_self| ... } ⇒ Object
15
16
17
18
19
20
|
# File 'lib/tophat/opengraph.rb', line 15
def merge(options={}, &block)
yield self if block_given?
@app_id = options.delete(:app_id) if options && options.has_key?(:app_id)
@admins = options.delete(:admins) if options && options.has_key?(:admins)
end
|
#to_html ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/tophat/opengraph.rb', line 53
def to_html
output = ActiveSupport::SafeBuffer.new
output << app_id if defined?(@app_id) && @app_id
output << admins if defined?(@admins) && @admins
output << graph_data if has_graph_data?
output
end
|
#type(t) ⇒ Object
39
40
41
42
|
# File 'lib/tophat/opengraph.rb', line 39
def type(t)
@graph_data ||= {}
@graph_data[:type] = t
end
|