Class: Txbr::EmailTemplateComponent

Inherits:
Object
  • Object
show all
Defined in:
lib/txbr/email_template_component.rb

Constant Summary collapse

ASSIGNMENTS =
%w(project_slug resource_slug translation_enabled)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(liquid_template) ⇒ EmailTemplateComponent

Returns a new instance of EmailTemplateComponent.



7
8
9
# File 'lib/txbr/email_template_component.rb', line 7

def initialize(liquid_template)
  @liquid_template = liquid_template
end

Instance Attribute Details

#liquid_templateObject (readonly)

Returns the value of attribute liquid_template.



5
6
7
# File 'lib/txbr/email_template_component.rb', line 5

def liquid_template
  @liquid_template
end

Instance Method Details

#assignmentsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/txbr/email_template_component.rb', line 26

def assignments
  @assignments ||= {}.tap do |assgn|
    liquid_template.root.nodelist.each do |node|
      case node
        when Liquid::Assign
          to = node.instance_variable_get(:@to)

          if ASSIGNMENTS.include?(to)
            from = node.instance_variable_get(:@from).name
            assgn[to] = from
          end
      end
    end
  end
end

#project_slugObject



11
12
13
14
# File 'lib/txbr/email_template_component.rb', line 11

def project_slug
  # blow up with KeyError if not found
  assignments.fetch('project_slug')
end

#resource_slugObject



16
17
18
19
# File 'lib/txbr/email_template_component.rb', line 16

def resource_slug
  # blow up with KeyError if not found
  assignments.fetch('resource_slug')
end

#stringsObject



42
43
44
45
46
# File 'lib/txbr/email_template_component.rb', line 42

def strings
  @strings ||= StringsManifest.new.tap do |manifest|
    extract_strings_from(liquid_template.root, manifest)
  end
end

#translation_enabled?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/txbr/email_template_component.rb', line 21

def translation_enabled?
  # translation is disabled by default
  assignments.fetch('translation_enabled', true)
end