Class: Decidim::Admin::FakeNewsletter

Inherits:
Object
  • Object
show all
Defined in:
decidim-admin/app/models/decidim/admin/fake_newsletter.rb

Overview

This class is used to generate fake newsletters and data to preview newsletter templates.

Instance Method Summary collapse

Constructor Details

#initialize(organization, manifest) ⇒ FakeNewsletter

Returns a new instance of FakeNewsletter.


8
9
10
11
# File 'decidim-admin/app/models/decidim/admin/fake_newsletter.rb', line 8

def initialize(organization, manifest)
  @organization = organization
  @manifest = manifest
end

Instance Method Details

#idObject


13
14
15
# File 'decidim-admin/app/models/decidim/admin/fake_newsletter.rb', line 13

def id
  1
end

#sent_atObject


40
41
42
# File 'decidim-admin/app/models/decidim/admin/fake_newsletter.rb', line 40

def sent_at
  nil
end

#subjectObject


34
35
36
37
38
# File 'decidim-admin/app/models/decidim/admin/fake_newsletter.rb', line 34

def subject
  organization.available_locales.inject({}) do |acc, locale|
    acc.update(locale => "Lorem ipsum")
  end
end

#templateObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'decidim-admin/app/models/decidim/admin/fake_newsletter.rb', line 17

def template
  @template ||= Decidim::ContentBlock.new(
    in_preview: true,
    manifest_name: manifest.name,
    scope_name: :newsletter_template,
    settings: manifest.settings.attributes.inject({}) do |acc, (name, attrs)|
      value = if attrs.preview.respond_to?(:call)
                attrs.preview.call
              else
                attrs.preview
              end

      acc.update(name => value)
    end
  )
end