Class: Coco::App::Blocks::SlideEditor

Inherits:
Component
  • Object
show all
Includes:
Coco::AppHelper, BookHelper, FormatHelper
Defined in:
app/components/coco/app/blocks/slide_editor/slide_editor.rb

Constant Summary

Constants included from Concerns::AcceptsTagAttributes

Concerns::AcceptsTagAttributes::TAG_ATTRIBUTE_NAMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FormatHelper

#format_css_hex_color

Methods included from BookHelper

#coco_editable_slide, #coco_media_slide

Methods included from Coco::AppHelper

#coco_button, #coco_button_group, #coco_color_picker_button, #coco_confirm_button, #coco_dropdown_button, #coco_fields, #coco_form_button, #coco_form_for, #coco_form_with, #coco_image_picker_button, #coco_link, #coco_menu_button, #coco_notice, #coco_seamless_textarea, #coco_snackbar, #coco_system_banner, #coco_toast, #coco_toolbar

Methods inherited from Component

#accepts_options?, after_initialize, before_initialize, before_render, new

Methods included from Coco::AlpineHelper

#x_attrs, #x_data

Methods included from TagHelper

#prefix_attr_keys, #random_id, #style_str

Methods included from ComponentHelper

#coco_component, #resolve_component

Methods included from BaseHelper

#coco_embed, #coco_icon, #coco_image, #coco_placeholder, #coco_tag

Methods included from Concerns::HasName

#component_name

Methods included from Concerns::AcceptsTagAttributes

#tag_attrs

Constructor Details

#initialize(form: nil, **kwargs) ⇒ SlideEditor

Returns a new instance of SlideEditor.



43
44
45
46
47
# File 'app/components/coco/app/blocks/slide_editor/slide_editor.rb', line 43

def initialize(form: nil, **kwargs)
  @form_args = form.to_h
  @model = @form_args[:model]
  @fields = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'app/components/coco/app/blocks/slide_editor/slide_editor.rb', line 80

def method_missing(name, *args, &block)
  name.match(/_(value|options|name)/) do |matches|
    field_name = name.to_s.gsub(matches[0], "").to_sym
    method = matches[1].to_sym
    if field?(field_name)
      fields[field_name].public_send(method)
    end
  end
end

Instance Attribute Details

#fields ⇒ Object (readonly)

Returns the value of attribute fields.



41
42
43
# File 'app/components/coco/app/blocks/slide_editor/slide_editor.rb', line 41

def fields
  @fields
end

Instance Method Details

#alpine_props ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/components/coco/app/blocks/slide_editor/slide_editor.rb', line 66

def alpine_props
  {
    bg_color: format_css_hex_color(bg_color_value),
    text_color: format_css_hex_color(text_color_value),
    title: title_value,
    text_1: text_1_value,
    layout: layout_value,
    bg_image: {
      name: ((field?(:bg_image) && bg_image_value.present?) && File.basename(bg_image_value)),
      data: (bg_image_value if field?(:bg_image))
    }
  }
end

#field?(name) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/components/coco/app/blocks/slide_editor/slide_editor.rb', line 95

def field?(name)
  fields.key?(name)
end

#form_args(attrs = {}) ⇒ Object



49
50
51
52
53
54
# File 'app/components/coco/app/blocks/slide_editor/slide_editor.rb', line 49

def form_args(attrs = {})
  html_args = @form_args.fetch(:html, {})
  attrs[:class] = class_names(html_args[:class], attrs[:class])
  html_args.merge!(attrs)
  @form_args.merge({html: html_args})
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
93
# File 'app/components/coco/app/blocks/slide_editor/slide_editor.rb', line 90

def respond_to_missing?(name, include_private = false)
  field_name = name.to_s.gsub(/_(value|options|name)/, "")
  field?(field_name.to_sym)
end

#slide_args ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'app/components/coco/app/blocks/slide_editor/slide_editor.rb', line 56

def slide_args
  {
    bg_image: bg_image_value,
    bg_color_hex: bg_color_value,
    text_color_hex: text_color_value,
    layout: layout_value,
    render_empty: true
  }
end