Class: Plum::BlockLibrary

Inherits:
Object
  • Object
show all
Defined in:
app/services/plum/block_library.rb

Overview

The merged block palette available to an entry: engine-level base blocks (Plum::BaseBlocks) plus the active theme's own blocks. A theme block overrides a base block with the same handle, so a theme can both add new sections and customize universal ones. This is the single resolution point used by the block editor (Plum::BlockEditorConfig) and the renderer (Plum::BuilderRenderer).

Instance Method Summary collapse

Constructor Details

#initialize(theme = nil) ⇒ BlockLibrary

Returns a new instance of BlockLibrary.



8
9
10
# File 'app/services/plum/block_library.rb', line 8

def initialize(theme = nil)
  @theme = theme
end

Instance Method Details

#definition(handle) ⇒ Object



20
21
22
23
# File 'app/services/plum/block_library.rb', line 20

def definition(handle)
  handle = handle.to_s
  (@theme && @theme.block_definition(handle)) || BaseBlocks.definition(handle)
end

#definitionsObject

Base blocks first, then theme blocks override (by handle) or append.



13
14
15
16
17
18
# File 'app/services/plum/block_library.rb', line 13

def definitions
  merged = {}
  BaseBlocks.definitions.each { |definition| merged[definition["handle"]] = definition }
  Array(@theme&.blocks).each { |definition| merged[definition["handle"]] = definition }
  merged.values
end

#template(handle) ⇒ Object

The Liquid source for a block. Theme partial wins; otherwise the base block.



26
27
28
29
# File 'app/services/plum/block_library.rb', line 26

def template(handle)
  handle = handle.to_s
  (@theme && @theme.block_template(handle)) || BaseBlocks.template(handle)
end