Class: Shareable::Helpers::SocialButtons

Inherits:
Tag
  • Object
show all
Includes:
ActionView::Context
Defined in:
lib/shareable/helpers/social_buttons.rb

Instance Method Summary collapse

Constructor Details

#initialize(template, options) ⇒ SocialButtons

:nodoc:


25
26
27
28
29
30
31
32
33
34
# File 'lib/shareable/helpers/social_buttons.rb', line 25

def initialize(template, options) #:nodoc:
  @template, @options = template, options
  @options[:buttons] ||= allowable(Shareable.config.names)
  @options[:options] ||= {}
  Shareable.config.config.each_key do |key|
    @options[:options].merge! key => (options[key].blank? ? Shareable.config.config.values_at(key).first : options[key])
  end
  # initialize @output_bugger i.v. used in ActionView::Context
  @output_buffer = ActionView::OutputBuffer.new
end

Instance Method Details

#each_relevant_buttonObject Also known as: each_button

:nodoc:


81
82
83
84
85
# File 'lib/shareable/helpers/social_buttons.rb', line 81

def each_relevant_button #:nodoc:
  @options[:buttons].each do |button|
    yield button
  end
end

#render(&block) ⇒ Object

render given block, view template for socialize class


37
38
39
40
# File 'lib/shareable/helpers/social_buttons.rb', line 37

def render(&block) #:nodoc:
  instance_eval(&block)
  @output_buffer
end

#to_sObject

:nodoc:


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/shareable/helpers/social_buttons.rb', line 50

def to_s #:nodoc:
  #from Kamanari for handling log subscriber:
  subscriber = ActionView::LogSubscriber.log_subscribers.detect {|ls| ls.is_a? ActionView::LogSubscriber}

  # There is a logging subscriber
  # and we don't want it to log render_partial
  # It is threadsafe, but might not repress logging
  # consistently in a high-load environment
  if subscriber
    unless defined? subscriber.render_partial_with_logging
      class << subscriber
        alias_method :render_partial_with_logging, :render_partial
        attr_accessor :render_without_logging
        # ugly hack to make a renderer where
        # we can turn logging on or off
        def render_partial(event)
          render_partial_with_logging(event) unless render_without_logging
        end
      end
    end

    subscriber.render_without_logging = true
    ret = super @options.merge :social_buttons => self
    subscriber.render_without_logging = false

    ret
  else
    super @options.merge :social_buttons => self
  end
end