hanami-mailer 1.3.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,135 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/mailer/template"
4
-
5
- module Hanami
6
- module Mailer
7
- module Rendering
8
- # Find templates for a mailer
9
- #
10
- # @api private
11
- # @since 0.1.0
12
- #
13
- # @see Mailer::Template
14
- class TemplatesFinder
15
- # Default format
16
- #
17
- # @api private
18
- # @since 0.1.0
19
- FORMAT = "*"
20
-
21
- # Default template engines
22
- #
23
- # @api private
24
- # @since 0.1.0
25
- ENGINES = "*"
26
-
27
- # Recursive pattern
28
- #
29
- # @api private
30
- # @since 0.1.0
31
- RECURSIVE = "**"
32
-
33
- # Initialize a finder
34
- #
35
- # @param mailer [Class] the mailer class
36
- #
37
- # @api private
38
- # @since 0.1.0
39
- def initialize(mailer)
40
- @mailer = mailer
41
- end
42
-
43
- # Find all the associated templates to the mailer.
44
- # It recursively looks for templates under the root path of the mailer,
45
- # that are matching the template name
46
- #
47
- # @return [Hash] the templates
48
- #
49
- # @api private
50
- # @since 0.1.0
51
- #
52
- # @see Hanami::Mailer::Dsl#root
53
- # @see Hanami::Mailer::Dsl#templates
54
- #
55
- # @example
56
- # require 'hanami/mailer'
57
- #
58
- # module Mailers
59
- # class Welcome
60
- # include Hanami::Mailer
61
- # end
62
- # end
63
- #
64
- # Mailers::Welcome.root # => "/path/to/templates"
65
- # Mailers::Welcome.templates # => {[:html] => "welcome"}
66
- #
67
- # # This mailer has a template:
68
- # #
69
- # # "/path/to/templates/welcome.html.erb"
70
- #
71
- # Hanami::Mailer::Rendering::TemplatesFinder.new(Mailers::Welcome).find
72
- # # => [#<Hanami::Mailer::Template:0x007f8a0a86a970 ... @file="/path/to/templates/welcome.html.erb">]
73
- def find
74
- templates = Hash[]
75
- _find.map do |template|
76
- name = File.basename(template)
77
- format = (name.split(".")[-2]).to_sym
78
- templates[format] = Mailer::Template.new(template)
79
- end
80
- templates
81
- end
82
-
83
- protected
84
-
85
- # @api private
86
- # @since 0.1.0
87
- def _find(lookup = search_path)
88
- Dir.glob("#{[root, lookup, template_name].join(separator)}.#{format}.#{engines}")
89
- end
90
-
91
- # @api private
92
- # @since 0.1.0
93
- def template_name
94
- Rendering::TemplateName.new(@mailer.template, @mailer.configuration.namespace).to_s
95
- end
96
-
97
- # @api private
98
- # @since 0.1.0
99
- def root
100
- @mailer.configuration.root
101
- end
102
-
103
- # @api private
104
- # @since 0.1.0
105
- def search_path
106
- recursive
107
- end
108
-
109
- # @api private
110
- # @since 0.1.0
111
- def recursive
112
- RECURSIVE
113
- end
114
-
115
- # @api private
116
- # @since 0.1.0
117
- def separator
118
- ::File::SEPARATOR
119
- end
120
-
121
- # @api private
122
- # @since 0.1.0
123
- def format
124
- FORMAT
125
- end
126
-
127
- # @api private
128
- # @since 0.1.0
129
- def engines
130
- ENGINES
131
- end
132
- end
133
- end
134
- end
135
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "tilt"
4
-
5
- module Hanami
6
- module Mailer
7
- # A logic-less template.
8
- #
9
- # @api private
10
- # @since 0.1.0
11
- #
12
- # TODO this is identical to Hanami::View, consider to move into Hanami::Utils
13
- class Template
14
- def initialize(template, encoding = Encoding::UTF_8)
15
- @_template = Tilt.new(template, default_encoding: encoding)
16
- end
17
-
18
- # Render the template within the context of the given scope.
19
- #
20
- # @param scope [Class] the rendering scope
21
- # @param locals [Hash] set of objects passed to the constructor
22
- #
23
- # @return [String] the output of the rendering process
24
- #
25
- # @api private
26
- # @since 0.1.0
27
- def render(scope = Object.new, locals = {})
28
- @_template.render(scope, locals)
29
- end
30
-
31
- # Get the path to the template
32
- #
33
- # @return [String] the pathname
34
- #
35
- # @api private
36
- # @since 0.1.0
37
- def file
38
- @_template.file
39
- end
40
- end
41
- end
42
- end