lotus-mailer 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,52 @@
1
+ require 'lotus/utils/string'
2
+
3
+ module Lotus
4
+ module Mailer
5
+ module Rendering
6
+ # @since 0.1.0
7
+ # @api private
8
+ #
9
+ # TODO this is identical to Lotus::View, consider to move into Lotus::Utils
10
+ class TemplateName
11
+ # @since 0.1.0
12
+ # @api private
13
+ NAMESPACE_SEPARATOR = '::'.freeze
14
+
15
+ # @since 0.1.0
16
+ # @api private
17
+ def initialize(name, namespace)
18
+ @name = name
19
+ compile!(namespace)
20
+ end
21
+
22
+ # @since 0.1.0
23
+ # @api private
24
+ def to_s
25
+ @name
26
+ end
27
+
28
+ private
29
+ # @since 0.1.0
30
+ # @api private
31
+ def compile!(namespace)
32
+ tokens(namespace) { |token| replace!(token) }
33
+ @name = Utils::String.new(@name).underscore
34
+ end
35
+
36
+ # @since 0.1.0
37
+ # @api private
38
+ def tokens(namespace)
39
+ namespace.to_s.split(NAMESPACE_SEPARATOR).each do |token|
40
+ yield token
41
+ end
42
+ end
43
+
44
+ # @since 0.1.0
45
+ # @api private
46
+ def replace!(token)
47
+ @name.gsub!(%r{\A#{ token }#{ NAMESPACE_SEPARATOR }}, '')
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,133 @@
1
+ require 'lotus/mailer/template'
2
+
3
+ module Lotus
4
+ module Mailer
5
+ module Rendering
6
+ # Find templates for a mailer
7
+ #
8
+ # @api private
9
+ # @since 0.1.0
10
+ #
11
+ # @see Mailer::Template
12
+ class TemplatesFinder
13
+ # Default format
14
+ #
15
+ # @api private
16
+ # @since 0.1.0
17
+ FORMAT = '*'.freeze
18
+
19
+ # Default template engines
20
+ #
21
+ # @api private
22
+ # @since 0.1.0
23
+ ENGINES = '*'.freeze
24
+
25
+ # Recursive pattern
26
+ #
27
+ # @api private
28
+ # @since 0.1.0
29
+ RECURSIVE = '**'.freeze
30
+
31
+ # Initialize a finder
32
+ #
33
+ # @param mailer [Class] the mailer class
34
+ #
35
+ # @api private
36
+ # @since 0.1.0
37
+ def initialize(mailer)
38
+ @mailer = mailer
39
+ end
40
+
41
+ # Find all the associated templates to the mailer.
42
+ # It recursively looks for templates under the root path of the mailer,
43
+ # that are matching the template name
44
+ #
45
+ # @return [Hash] the templates
46
+ #
47
+ # @api private
48
+ # @since 0.1.0
49
+ #
50
+ # @see Lotus::Mailer::Dsl#root
51
+ # @see Lotus::Mailer::Dsl#templates
52
+ #
53
+ # @example
54
+ # require 'lotus/mailer'
55
+ #
56
+ # module Mailers
57
+ # class Welcome
58
+ # include Lotus::Mailer
59
+ # end
60
+ # end
61
+ #
62
+ # Mailers::Welcome.root # => "/path/to/templates"
63
+ # Mailers::Welcome.templates # => {[:html] => "welcome"}
64
+ #
65
+ # # This mailer has a template:
66
+ # #
67
+ # # "/path/to/templates/welcome.html.erb"
68
+ #
69
+ # Lotus::Mailer::Rendering::TemplatesFinder.new(Mailers::Welcome).find
70
+ # # => [#<Lotus::Mailer::Template:0x007f8a0a86a970 ... @file="/path/to/templates/welcome.html.erb">]
71
+ def find
72
+ templates = Hash.new
73
+ _find.map do |template|
74
+ name = File.basename(template)
75
+ format = (( name.split(".") )[-2]).to_sym
76
+ templates[ format ] = Mailer::Template.new(template)
77
+ end
78
+ templates
79
+ end
80
+
81
+ protected
82
+
83
+ # @api private
84
+ # @since 0.1.0
85
+ def _find(lookup = search_path)
86
+ Dir.glob( "#{ [root, lookup, template_name].join(separator) }.#{ format }.#{ engines }" )
87
+ end
88
+
89
+ # @api private
90
+ # @since 0.1.0
91
+ def template_name
92
+ Rendering::TemplateName.new(@mailer.template, @mailer.configuration.namespace).to_s
93
+ end
94
+
95
+ # @api private
96
+ # @since 0.1.0
97
+ def root
98
+ @mailer.configuration.root
99
+ end
100
+
101
+ # @api private
102
+ # @since 0.1.0
103
+ def search_path
104
+ recursive
105
+ end
106
+
107
+ # @api private
108
+ # @since 0.1.0
109
+ def recursive
110
+ RECURSIVE
111
+ end
112
+
113
+ # @api private
114
+ # @since 0.1.0
115
+ def separator
116
+ ::File::SEPARATOR
117
+ end
118
+
119
+ # @api private
120
+ # @since 0.1.0
121
+ def format
122
+ FORMAT
123
+ end
124
+
125
+ # @api private
126
+ # @since 0.1.0
127
+ def engines
128
+ ENGINES
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,40 @@
1
+ require 'tilt'
2
+
3
+ module Lotus
4
+ module Mailer
5
+ # A logic-less template.
6
+ #
7
+ # @api private
8
+ # @since 0.1.0
9
+ #
10
+ # TODO this is identical to Lotus::View, consider to move into Lotus::Utils
11
+ class Template
12
+ def initialize(template)
13
+ @_template = Tilt.new(template)
14
+ end
15
+
16
+ # Render the template within the context of the given scope.
17
+ #
18
+ # @param scope [Class] the rendering scope
19
+ # @param locals [Hash] set of objects passed to the constructor
20
+ #
21
+ # @return [String] the output of the rendering process
22
+ #
23
+ # @api private
24
+ # @since 0.1.0
25
+ def render(scope = Object.new, locals = {})
26
+ @_template.render(scope, locals)
27
+ end
28
+
29
+ # Get the path to the template
30
+ #
31
+ # @return [String] the pathname
32
+ #
33
+ # @api private
34
+ # @since 0.1.0
35
+ def file
36
+ @_template.file
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,6 @@
1
1
  module Lotus
2
2
  module Mailer
3
- VERSION = '0.0.0'
3
+ # @since 0.1.0
4
+ VERSION = '0.1.0'.freeze
4
5
  end
5
6
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'lotus/mailer/version'
@@ -6,8 +5,8 @@ require 'lotus/mailer/version'
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = 'lotus-mailer'
8
7
  spec.version = Lotus::Mailer::VERSION
9
- spec.authors = ['Luca Guidi']
10
- spec.email = ['me@lucaguidi.com']
8
+ spec.authors = ['Luca Guidi', 'Ines Coelho', 'Rosa Faria']
9
+ spec.email = ['me@lucaguidi.com', 'ines.opcoelho@gmail.com', 'rosa1853@live.com']
11
10
 
12
11
  spec.summary = %q{Mail for Ruby applications.}
13
12
  spec.description = %q{Mail for Ruby applications and Lotus mailers}
@@ -26,6 +25,8 @@ Gem::Specification.new do |spec|
26
25
  spec.require_paths = ['lib']
27
26
 
28
27
  spec.add_dependency 'lotus-utils', '~> 0.5'
28
+ spec.add_dependency 'tilt', '~> 2.0', '>= 2.0.1'
29
+ spec.add_dependency 'mail', '~> 2.5'
29
30
 
30
31
  spec.add_development_dependency 'bundler', '~> 1.10'
31
32
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lotus-mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
+ - Ines Coelho
9
+ - Rosa Faria
8
10
  autorequire:
9
11
  bindir: exe
10
12
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
13
+ date: 2015-09-30 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: lotus-utils
@@ -24,6 +26,40 @@ dependencies:
24
26
  - - "~>"
25
27
  - !ruby/object:Gem::Version
26
28
  version: '0.5'
29
+ - !ruby/object:Gem::Dependency
30
+ name: tilt
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '2.0'
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 2.0.1
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.0.1
49
+ - !ruby/object:Gem::Dependency
50
+ name: mail
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.5'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.5'
27
63
  - !ruby/object:Gem::Dependency
28
64
  name: bundler
29
65
  requirement: !ruby/object:Gem::Requirement
@@ -69,6 +105,8 @@ dependencies:
69
105
  description: Mail for Ruby applications and Lotus mailers
70
106
  email:
71
107
  - me@lucaguidi.com
108
+ - ines.opcoelho@gmail.com
109
+ - rosa1853@live.com
72
110
  executables: []
73
111
  extensions: []
74
112
  extra_rdoc_files: []
@@ -76,7 +114,13 @@ files:
76
114
  - CHANGELOG.md
77
115
  - LICENSE.md
78
116
  - README.md
117
+ - lib/lotus-mailer.rb
79
118
  - lib/lotus/mailer.rb
119
+ - lib/lotus/mailer/configuration.rb
120
+ - lib/lotus/mailer/dsl.rb
121
+ - lib/lotus/mailer/rendering/template_name.rb
122
+ - lib/lotus/mailer/rendering/templates_finder.rb
123
+ - lib/lotus/mailer/template.rb
80
124
  - lib/lotus/mailer/version.rb
81
125
  - lotus-mailer.gemspec
82
126
  homepage: http://lotusrb.org
@@ -100,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
144
  version: '0'
101
145
  requirements: []
102
146
  rubyforge_project:
103
- rubygems_version: 2.4.8
147
+ rubygems_version: 2.4.5.1
104
148
  signing_key:
105
149
  specification_version: 4
106
150
  summary: Mail for Ruby applications.