Class: Maglove::Widgets::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, scope) ⇒ Base

Returns a new instance of Base.



17
18
19
20
# File 'lib/maglove/widgets/base.rb', line 17

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



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

def scope
  @scope
end

Instance Method Details

#defaultsObject



13
14
15
# File 'lib/maglove/widgets/base.rb', line 13

def defaults
  {}
end

#identifierObject



9
10
11
# File 'lib/maglove/widgets/base.rb', line 9

def identifier
  "base"
end

#widget_optionsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/maglove/widgets/base.rb', line 22

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