module Coco module Book module Blocks module Slides class EditableSlide < Coco::Component include Concerns::AcceptsOptions include Coco::TagHelper include Coco::FormatHelper accepts_option :layout, from: %w[one-col-title one-col-text one-col-media two-col-text two-col-media two-col-mixed], default: "one-col-title" renders_one :title, ->(&block) do @has_content = true block.call end renders_one :text_1, ->(&block) do @has_content = true block.call end renders_one :text_2, ->(&block) do @has_content = true block.call end renders_one :image_1, ->(href:) do @has_content = true href end renders_one :image_2, ->(href:) do @has_content = true href end before_initialize do |kwargs| if kwargs[:layout] kwargs[:layout] = kwargs[:layout].to_s.tr("_", "-") kwargs[:layout] = "one-col-title" if kwargs[:layout] == "basic" # handle legacy layout name end kwargs end attr_reader :bg_image, :text_color_hex, :bg_color_hex def initialize(bg_image: nil, bg_color_hex: nil, text_color_hex: nil, render_empty: false, **kwargs) @bg_image = bg_image @bg_color_hex = bg_color_hex @text_color_hex = text_color_hex @has_content = false @render_empty = render_empty end def render? @has_content || bg_image.present? || @render_empty == true end def slide_styles style_str({ background_color: format_css_hex_color(bg_color_hex), color: format_css_hex_color(text_color_hex), background_image: ("url('#{bg_image}')" if bg_image) }) end end end end end end