lib/yashare/widget.rb in yashare-0.1 vs lib/yashare/widget.rb in yashare-0.9
- old
+ new
@@ -1,37 +1,35 @@
module Yashare
class Widget
- def initialize(view, opts={})
+ def initialize(view, opts = {})
@view = view
- @services = opts.fetch(:services, ['vkontakte', 'facebook', 'twitter', 'lj'])
+ @services = opts.fetch(:services, %w(vkontakte facebook twitter lj))
@image = opts.fetch(:image, nil)
@type = opts.fetch(:type, 'button')
@lang = opts.fetch(:lang, 'ru')
end
def to_s
- attrs = {
- class: 'yashare-auto-init',
- data: {
- yashareL10n: lang,
- yashareType: type,
- yashareQuickServices: services.join(',')
- }
- }
+ @html ||= render
+ end
- if type == 'small'
- attrs[:data][:yashareTheme] = 'counter'
- end
+ private
- if image.present?
- attrs[:data][:yashareImage] = image
- end
-
- view.content_tag(:div, nil, attrs)
+ def render
+ view.content_tag(:div, nil, class: 'yashare-auto-init', data: data_attrs)
end
- private
+ def data_attrs
+ {
+ yashareQuickServices: Array(services).join(','),
+ yashareL10n: lang,
+ yashareType: type
+ }.tap do |data|
+ data[:yashareTheme] = 'counter' if type.to_s == 'small'
+ data[:yashareImage] = image if image.present?
+ end
+ end
attr_reader :view, :type, :services, :image, :lang
end
end