Module: Plum::BaseBlocks

Defined in:
app/services/plum/base_blocks.rb

Overview

Engine-level "base" blocks: a small universal palette that exists on every site regardless of theme. Themes can add their own blocks and can override a base block by declaring the same handle (see Plum::BlockLibrary for the merge/override rules). Keeping these in the engine means switching themes never orphans content built from universal sections, and a bare theme still gives owners a usable palette.

Each definition matches the theme block shape (handle/label/fields), and each has a matching Liquid partial keyed by handle. Field values are exposed to the partial under block exactly like theme blocks.

Constant Summary collapse

DEFINITIONS =
[
  {
    "handle" => "hero", "label" => "Hero",
    "fields" => [
      { "handle" => "heading", "type" => "text", "label" => "Heading" },
      { "handle" => "subheading", "type" => "textarea", "label" => "Subheading" },
      { "handle" => "image", "type" => "image", "label" => "Image" },
      { "handle" => "button_label", "type" => "text", "label" => "Button Label" },
      { "handle" => "button_url", "type" => "text", "label" => "Button URL" }
    ]
  },
  {
    "handle" => "rich_text", "label" => "Rich Text",
    "fields" => [
      { "handle" => "body", "type" => "rich_text", "label" => "Body" }
    ]
  },
  {
    "handle" => "image", "label" => "Image",
    "fields" => [
      { "handle" => "image", "type" => "image", "label" => "Image" },
      { "handle" => "caption", "type" => "text", "label" => "Caption" }
    ]
  },
  {
    "handle" => "image_text", "label" => "Image + Text",
    "fields" => [
      { "handle" => "heading", "type" => "text", "label" => "Heading" },
      { "handle" => "body", "type" => "rich_text", "label" => "Body" },
      { "handle" => "image", "type" => "image", "label" => "Image" },
      { "handle" => "image_position", "type" => "select", "label" => "Image Position",
        "options" => [ { "label" => "Left", "value" => "left" }, { "label" => "Right", "value" => "right" } ] }
    ]
  },
  {
    "handle" => "gallery", "label" => "Gallery",
    "fields" => [
      { "handle" => "heading", "type" => "text", "label" => "Heading" },
      { "handle" => "image_one", "type" => "image", "label" => "Image One" },
      { "handle" => "image_two", "type" => "image", "label" => "Image Two" },
      { "handle" => "image_three", "type" => "image", "label" => "Image Three" }
    ]
  },
  {
    "handle" => "cta", "label" => "Call to Action",
    "fields" => [
      { "handle" => "heading", "type" => "text", "label" => "Heading" },
      { "handle" => "text", "type" => "textarea", "label" => "Text" },
      { "handle" => "button_label", "type" => "text", "label" => "Button Label" },
      { "handle" => "button_url", "type" => "text", "label" => "Button URL" }
    ]
  },
  {
    "handle" => "button", "label" => "Button",
    "fields" => [
      { "handle" => "label", "type" => "text", "label" => "Label" },
      { "handle" => "url", "type" => "text", "label" => "URL" }
    ]
  },
  {
    "handle" => "spacer", "label" => "Spacer",
    "fields" => [
      { "handle" => "size", "type" => "select", "label" => "Size",
        "options" => [ { "label" => "Small", "value" => "small" }, { "label" => "Medium", "value" => "medium" }, { "label" => "Large", "value" => "large" } ] }
    ]
  }
].freeze
TEMPLATES =
{
  "hero" => <<~LIQUID,
  "rich_text" => <<~LIQUID,
  "image" => <<~LIQUID,
  "image_text" => <<~LIQUID,
  "gallery" => <<~LIQUID,
  "cta" => <<~LIQUID,
  "button" => <<~LIQUID,
  "spacer" => <<~LIQUID
    <div class="plum-block plum-block-spacer plum-spacer-{{ block.size | default: 'medium' }}"></div>
  LIQUID
}.freeze

Class Method Summary collapse

Class Method Details

.definition(handle) ⇒ Object



153
154
155
# File 'app/services/plum/base_blocks.rb', line 153

def definition(handle)
  DEFINITIONS.find { |definition| definition["handle"] == handle.to_s }
end

.definitionsObject



149
150
151
# File 'app/services/plum/base_blocks.rb', line 149

def definitions
  DEFINITIONS
end

.template(handle) ⇒ Object



157
158
159
# File 'app/services/plum/base_blocks.rb', line 157

def template(handle)
  TEMPLATES[handle.to_s]
end