Sha256: cfe4f62a6b566dd532e137962ab4463bc52f69bcef3e68ba4317ad09defbf0cc

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

module Maglove
  module Widgets
    class Base
      extend Forwardable
      include Hamloft::Helpers
      attr_reader :options, :scope
      def_delegators :@scope, :haml_tag, :haml_concat

      def identifier
        "base"
      end

      def defaults
        {}
      end

      def initialize(options, scope)
        @options = defaults.merge(options)
        @scope = scope
      end

      def widget_options
        attributes = { "type" => identifier }
        classes = []
        classes.push("mobile-#{@options[:mobile]}") if @options[:mobile]
        if @options[:effect]
          classes.push("effect")
          classes.push("effect-#{@options[:effect]}")
        end
        attributes["class"] = classes.join(" ") if classes.any?
        widget_style_keys = %i[padding padding_top padding_bottom padding_left padding_right background_color background_image background_size background_position]
        widget_options = @options.except(*widget_style_keys)
        styles = @options.slice(*widget_style_keys)
        attributes["style"] = style_string(styles, :padding, :background_color, :background_size, :background_position) do |sb|
          sb.add(:background_image, styles[:background_image], "url(<%= value %>)")
        end
        widget_options.each do |key, value|
          attributes["attribute-#{key.to_s.dasherize}"] = value
        end
        attributes
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
maglove-widgets-2.0.3 lib/maglove/widgets/base.rb
maglove-widgets-2.0.2 lib/maglove/widgets/base.rb