Class: Maglove::Widgets::Container

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

Defined Under Namespace

Modules: Helpers

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #typeloft_widget_options

Constructor Details

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

Instance Method Details

#container_classesObject



48
49
50
51
52
53
54
55
# File 'lib/maglove/widgets/container.rb', line 48

def container_classes
  classes = ["one-container"]
  classes.push("animate #{@options[:animate]}") if @options[:animate] != "none"
  classes.push("container-#{@options[:style]}") unless @options[:style].empty?
  classes.push("container-image-#{@options[:image_size]}") unless @options[:image_size].empty?
  classes.push("container-parallax") if !@options[:parallax_effect].empty? and @options[:parallax_effect] != "none"
  classes.join(" ")
end

#container_optionsObject



38
39
40
41
42
# File 'lib/maglove/widgets/container.rb', line 38

def container_options
  result = { class: container_classes, style: container_styles }
  result["data-parallax-style"] = @options[:parallax_effect] if !@options[:parallax_effect].empty? and @options[:parallax_effect] != "none"
  result
end

#container_stylesObject



57
58
59
60
61
62
63
64
65
# File 'lib/maglove/widgets/container.rb', line 57

def container_styles
  style_string @options, :opacity, :border, :opacity, :border_radius, :border_width, :border_style, :margin do |sb|
    sb.add(:background_color, @options[:background_color] == "custom" ? @options[:bg_color] : nil)
    if @options[:background_color] == "overlay"
      sb.add(:background_image, @options[:image_source], "linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(<%= value %>)")
    end
    sb.add(:background_position, @options[:image_position], "<%= value.split('_').join(' ') %>")
  end
end

#defaultsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/maglove/widgets/container.rb', line 8

def defaults
  {
      animate: "none",
      image_source: false,
      image_position: "center_center",
      image_size: "cover",
      parallax_effect: "none",
      background_color: "",
      bg_color: "",
      opacity: "",
      border_radius: "",
      border_width: "",
      border_style: "",
      style: "default",
      padding_top: "",
      padding_right: "",
      padding_bottom: "",
      padding_left: "",
      alignment: "center",
      min_height: "",
      max_height: "",
      max_width: "",
      margin_top: "",
      margin_right: "",
      margin_bottom: "",
      margin_left: "",
      overflow_y: ""
  }
end

#identifierObject



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

def identifier
  "container"
end

#image_optionsObject



44
45
46
# File 'lib/maglove/widgets/container.rb', line 44

def image_options
  { class: "one-container-image", style: image_styles }
end

#image_stylesObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/maglove/widgets/container.rb', line 67

def image_styles
  if @options[:alignment] == "left"
    @options[:margin_left] = "0"
    @options[:margin_right] = "auto"
  elsif @options[:alignment] == "right"
    @options[:margin_left] = "auto"
    @options[:margin_right] = "0"
  else
    @options[:margin_left] = "auto"
    @options[:margin_right] = "auto"
  end

  style_string @options, :min_height, :max_height, :max_width, :padding, :overflow_y, :margin_left, :margin_right do |sb|
    if @options[:background_color] != "overlay"
      sb.add(:background_image, @options[:image_source], "url(<%= value %>)")
    end
  end
end