module Maglove module Widgets class Container < Base def identifier "container" end 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 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 def image_options { class: "one-container-image", style: image_styles } end 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 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 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 module Helpers def container_widget(options = {}, &block) widget_block(Widgets::Container.new(options)) do |widget| haml_tag :section, widget.container_options do haml_tag :div, widget.image_options do yield if block drop_container end end end end end end end end