Class: Plum::BlockEditorConfig
- Inherits:
-
Object
- Object
- Plum::BlockEditorConfig
- Defined in:
- app/services/plum/block_editor_config.rb
Overview
Translates a theme's declared blocks (theme.yml blocks:) into a
JSON-serializable config our own block editor consumes to render the block
picker and per-block field inputs. This is the seam that keeps the editor in
the engine and the block library in themes: the editor never reads a theme
directly — it reads this generated config. Theme authors write zero JS.
Shape:
{
"blocks" => [
{ "id" => "hero", "label" => "Hero", "category" => "Blocks",
"fields" => [ { "handle" => "heading", "type" => "text", "label" => "Heading" }, ... ] }
]
}
An optional allowed list (the blueprint field's blocks: whitelist) limits
which theme blocks are offered for a given field.
Constant Summary collapse
- DEFAULT_CATEGORY =
"Blocks".freeze
Instance Method Summary collapse
- #blocks ⇒ Object
-
#initialize(theme, allowed: nil) ⇒ BlockEditorConfig
constructor
A new instance of BlockEditorConfig.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(theme, allowed: nil) ⇒ BlockEditorConfig
Returns a new instance of BlockEditorConfig.
21 22 23 24 |
# File 'app/services/plum/block_editor_config.rb', line 21 def initialize(theme, allowed: nil) @theme = theme @allowed = allowed.nil? ? nil : Array(allowed).map(&:to_s) end |
Instance Method Details
#blocks ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/plum/block_editor_config.rb', line 26 def blocks definitions.map do |definition| { "id" => definition["handle"], "label" => definition["label"], "category" => definition["category"].presence || DEFAULT_CATEGORY, "fields" => Array(definition["fields"]).map { |field| field_config(field) } } end end |
#to_h ⇒ Object
37 38 39 |
# File 'app/services/plum/block_editor_config.rb', line 37 def to_h { "blocks" => blocks } end |
#to_json(*args) ⇒ Object
41 42 43 |
# File 'app/services/plum/block_editor_config.rb', line 41 def to_json(*args) to_h.to_json(*args) end |