Module: Pressroom::BuiltInBlocks

Defined in:
lib/pressroom/built_in_blocks.rb

Overview

The seven core block types. Anything richer -- tables, checklists, embeds, attachments -- belongs in the host application or in a companion gem, not here: every built-in block is support surface forever.

Class Method Summary collapse

Class Method Details

.code(registry) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/pressroom/built_in_blocks.rb', line 63

def code(registry)
  registry.register(:code) do |b|
    b.tool "CodeTool"
    b.partial "pressroom/blocks/code"
    # Deliberately a string, not html: code is escaped, never sanitized.
    b.schema { string :code }
  end
end

.delimiter(registry) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/pressroom/built_in_blocks.rb', line 89

def delimiter(registry)
  registry.register(:delimiter) do |b|
    b.tool "Delimiter"
    b.partial "pressroom/blocks/delimiter"
    b.schema { }
  end
end

.header(registry) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/pressroom/built_in_blocks.rb', line 29

def header(registry)
  registry.register(:header) do |b|
    b.tool "Header", config: { levels: [2, 3, 4], defaultLevel: 2 }
    b.partial "pressroom/blocks/header"
    b.schema do
      html :text
      integer :level, default: 2
    end
  end
end

.image(registry) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/pressroom/built_in_blocks.rb', line 72

def image(registry)
  registry.register(:image) do |b|
    b.tool "ImageTool"
    b.partial "pressroom/blocks/image"
    b.schema do
      nested :file do
        string :url
      end
      html :caption
      boolean :withBorder
      boolean :stretched
      boolean :withBackground
    end
    b.searchable { |data| data["caption"] }
  end
end

.list(registry) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/pressroom/built_in_blocks.rb', line 40

def list(registry)
  registry.register(:list) do |b|
    b.tool "List"
    b.partial "pressroom/blocks/list"
    b.schema do
      enum :style, in: %w[ordered unordered], default: "unordered"
      tree :items, content: :html
    end
  end
end

.paragraph(registry) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/pressroom/built_in_blocks.rb', line 21

def paragraph(registry)
  registry.register(:paragraph) do |b|
    b.tool "Paragraph"
    b.partial "pressroom/blocks/paragraph"
    b.schema { html :text }
  end
end

.quote(registry) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pressroom/built_in_blocks.rb', line 51

def quote(registry)
  registry.register(:quote) do |b|
    b.tool "Quote"
    b.partial "pressroom/blocks/quote"
    b.schema do
      html :text
      html :caption
      enum :alignment, in: %w[left center], default: "left"
    end
  end
end

.register!(registry) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/pressroom/built_in_blocks.rb', line 11

def register!(registry)
  paragraph(registry)
  header(registry)
  list(registry)
  quote(registry)
  code(registry)
  image(registry)
  delimiter(registry)
end