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