Sha256: 0d2450cb7114b122f38265b3bbfb30944545bbf00c5d4438bfbb9942b097923e

Contents?: true

Size: 838 Bytes

Versions: 1

Compression:

Stored size: 838 Bytes

Contents

module Sociyal
  class Widget
    def initialize(view, opts = {})
      @view = view

      @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
      @html ||= render
    end

    private

    def render
      view.content_tag(:div, nil, class: 'yashare-auto-init', data: data_attrs)
    end

    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sociyal-1.0.0 lib/sociyal/widget.rb