Sha256: 39f7fd392728de0621c5ac09b8d96df6615f003474d8c86dc0f15c4f6ba4bff9
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
module TopHat module TwitterCardHelper class TwitterCardGenerator include ActionView::Helpers attr_reader :card_data def initialize(type, &block) @type = type @card_data = {} yield self if block_given? end def to_html output = ActiveSupport::SafeBuffer.new output << tag(:meta, :name => 'twitter:card', :value => @type) @card_data.each do |key, value| output << "\n".html_safe output << tag(:meta, :name => "twitter:#{key}", :value => value) end output << "\n".html_safe unless @card_data.empty? output end alias render to_html def add_nested_attributes(method, &block) image_generator = TwitterCardGenerator.new(method, &block) image_generator.card_data.each do |key, value| @card_data["#{method}:#{key}"] = value end end def method_missing(method, *args, &block) #:nodoc @card_data ||= {} @card_data[method] = args.shift add_nested_attributes(method, &block) if block_given? end end def twitter_card(type=nil, &block) if type.nil? if TopHat.current['twitter_card'] TopHat.current['twitter_card'].to_html end else TopHat.current['twitter_card'] = TwitterCardGenerator.new(type, &block) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tophat-2.1.0 | lib/tophat/twitter_card.rb |