Sha256: d1b1e0ca187d80d1c9c5d68d5719169e653504e8f50a36270455e346032cb667

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

module Maglove
  module Widgets
    class Button < Base
      def identifier
        "button"
      end

      def defaults
        {
          background_color: "#e6e6e6",
          border_radius: "4px",
          border_width: "1px",
          border_style: "solid",
          media: false,
          size: "btn-lg",
          style: "primary",
          type: "btn-fit"
        }
      end

      def button_classes
        classes = ["btn", "btn-#{@options[:style]}", @options[:size], @options[:type], "_typeloft_editable"]
        classes.push("btn-media") if @options[:media]
        classes.join(" ")
      end

      def button_options
        result = { class: button_classes, href: (@options[:href] or "#"), style: button_styles }
        result["data-media"] = @options[:media] if @options[:media] and !@options[:media].empty?
        result
      end

      def button_styles
        style_string @options, :border_radius, :border_width, :border_style, :border_color, :background_color do |sb|
          sb.add(:border_style, "solid")
        end
      end

      def template(scope, &block)
        scope.haml_tag :a, button_options do
          if options[:media] and !options[:media].blank?
            scope.haml_tag :video do
              scope.haml_tag :source, { src: options[:media], type: "video/mp4" }
            end
          end
          yield if block
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
maglove-widgets-2.0.5 lib/maglove/widgets/button.rb
maglove-widgets-2.0.4 lib/maglove/widgets/button.rb
maglove-widgets-2.0.3 lib/maglove/widgets/button.rb
maglove-widgets-2.0.2 lib/maglove/widgets/button.rb