Class: Maglove::Widgets::Base

Inherits:
Object
  • Object
show all
Includes:
Hamloft::Helpers
Defined in:
lib/maglove/widgets/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



15
16
17
# File 'lib/maglove/widgets/base.rb', line 15

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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/maglove/widgets/base.rb', line 5

def options
  @options
end

Instance Method Details

#defaultsObject



11
12
13
# File 'lib/maglove/widgets/base.rb', line 11

def defaults
  {}
end

#identifierObject



7
8
9
# File 'lib/maglove/widgets/base.rb', line 7

def identifier
  "base"
end

#typeloft_widget_optionsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/maglove/widgets/base.rb', line 19

def typeloft_widget_options
  attributes = {
    :class => "_typeloft_widget",
    :"data-widget-identifier" => identifier
  }
  @options.each do |k, v|
    if k == :padding or k == :margin
      [:top, :right, :bottom, :left].each do |dir|
        attributes["data-attribute-#{k}_#{dir}"] = v
      end
    end
    attributes["data-attribute-#{k}"] = v
  end
  attributes
end