Class: Maglove::Widgets::Button

Inherits:
Base
  • Object
show all
Defined in:
lib/maglove/widgets/button.rb

Instance Attribute Summary

Attributes inherited from Base

#options, #scope

Instance Method Summary collapse

Methods inherited from Base

#initialize, #widget_options

Constructor Details

This class inherits a constructor from Maglove::Widgets::Base

Instance Method Details

#button_classesObject



21
22
23
24
25
# File 'lib/maglove/widgets/button.rb', line 21

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

#button_optionsObject



27
28
29
30
31
# File 'lib/maglove/widgets/button.rb', line 27

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

#button_stylesObject



33
34
35
36
37
# File 'lib/maglove/widgets/button.rb', line 33

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

#defaultsObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/maglove/widgets/button.rb', line 8

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

#identifierObject



4
5
6
# File 'lib/maglove/widgets/button.rb', line 4

def identifier
  "button"
end

#template(scope, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/maglove/widgets/button.rb', line 39

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