Module: Decidim::Design::AnnouncementHelper

Defined in:
decidim-design/app/helpers/decidim/design/announcement_helper.rb

Instance Method Summary collapse

Instance Method Details

#announcement_sectionsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'decidim-design/app/helpers/decidim/design/announcement_helper.rb', line 6

def announcement_sections
  [
    {
      id: "callout_class",
      contents: [
        {
          type: :text,
          values: ["This attribute applies an status to the announcement. By default, it uses secondary color."]
        },
        {
          type: :table,
          options: { headings: ["Announcement", "Callout class"] },
          items: announcement_table(
            { text: "I am an announcement", callout_class: nil },
            { text: "I am an announcement", callout_class: "alert" },
            { text: "I am an announcement", callout_class: "warning" },
            { text: "I am an announcement", callout_class: "success" }
          ),
          cell_snippet: {
            cell: "decidim/announcement",
            args: ["I am an annoucement"]
          }
        }
      ]
    },
    {
      id: "plain_text_vs_hash",
      contents: [
        {
          type: :text,
          values: ["You can provide as first argument both a plain text and a hash object"]
        },
        {
          type: :table,
          options: { headings: %w(Announcement Argument) },
          items: announcement_table(
            { text: "I am just plain text", argument: '"I am just plain text"' },
            { text: { title: "This is the title", body: "This is the body" }, argument: '{ title: "This is the title", body: "This is the body" }' }
          ),
          cell_snippet: {
            cell: "decidim/announcement",
            args: [{ title: "This is the title", body: "This is the body" }]
          }
        }
      ]
    }
  ]
end

#announcement_table(*table_rows, **_opts) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'decidim-design/app/helpers/decidim/design/announcement_helper.rb', line 55

def announcement_table(*table_rows, **_opts)
  table_rows.each_with_index.map do |table_cell, _ix|
    row = []
    row << { method: :cell, args: ["decidim/announcement", table_cell[:text], { callout_class: table_cell[:callout_class] }] }
    row << table_cell[:callout_class] if table_cell[:callout_class].present?
    row << table_cell[:argument] if table_cell[:argument].present?
    row
  end
end