Class: Maglove::Widgets::Base
- Inherits:
-
Object
- Object
- Maglove::Widgets::Base
- Extended by:
- Forwardable
- Includes:
- Hamloft::Helpers
- Defined in:
- lib/maglove/widgets/base.rb
Direct Known Subclasses
Button, Columns, Container, Heading, HorizontalRule, Image, Paragraph, ScrollableImage, Slider, Video, Youtube
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #defaults ⇒ Object
- #identifier ⇒ Object
-
#initialize(options, scope) ⇒ Base
constructor
A new instance of Base.
- #widget_options ⇒ Object
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(, scope) @options = defaults.merge() @scope = scope end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/maglove/widgets/base.rb', line 6 def @options end |
#scope ⇒ Object (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
#defaults ⇒ Object
13 14 15 |
# File 'lib/maglove/widgets/base.rb', line 13 def defaults {} end |
#identifier ⇒ Object
9 10 11 |
# File 'lib/maglove/widgets/base.rb', line 9 def identifier "base" end |
#widget_options ⇒ Object
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 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? = %i[padding padding_top padding_bottom padding_left padding_right background_color background_image background_size background_position] = @options.except(*) styles = @options.slice(*) attributes["style"] = style_string(styles, :padding, :background_color, :background_size, :background_position) do |sb| sb.add(:background_image, styles[:background_image], "url(<%= value %>)") end .each do |key, value| attributes["attribute-#{key.to_s.dasherize}"] = value end attributes end |