Class: Lotus::Generators::Mailer Private

Inherits:
Abstract
  • Object
show all
Defined in:
lib/lotus/generators/mailer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

Constant Summary collapse

TXT_FORMAT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

'.txt'.freeze
HTML_FORMAT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

'.html'.freeze
DEFAULT_ENGINE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

'erb'.freeze
DEFAULT_FROM =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

"'<from>'".freeze
DEFAULT_TO =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

"'<to>'".freeze
DEFAULT_SUBJECT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0

"'Hello'".freeze

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Mailer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Mailer.

Since:

  • 0.5.0



36
37
38
39
40
41
# File 'lib/lotus/generators/mailer.rb', line 36

def initialize(command)
  super

  @mailer_name = Utils::String.new(name).classify
  cli.class.source_root(source)
end

Instance Method Details

#__template_path(format) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



101
102
103
# File 'lib/lotus/generators/mailer.rb', line 101

def __template_path(format)
  core_root.join('mailers', 'templates', "#{ name }#{ format }.#{ DEFAULT_ENGINE }")
end

#_html_template_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



95
96
97
# File 'lib/lotus/generators/mailer.rb', line 95

def _html_template_path
  __template_path(HTML_FORMAT)
end

#_mailer_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



77
78
79
# File 'lib/lotus/generators/mailer.rb', line 77

def _mailer_path
  core_root.join('mailers', "#{ name }.rb").to_s
end

#_mailer_spec_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



83
84
85
# File 'lib/lotus/generators/mailer.rb', line 83

def _mailer_spec_path
  spec_root.join(::File.basename(Dir.getwd), 'mailers', "#{ name }_spec.rb")
end

#_txt_template_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



89
90
91
# File 'lib/lotus/generators/mailer.rb', line 89

def _txt_template_path
  __template_path(TXT_FORMAT)
end

#assert_mailer!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



69
70
71
72
73
# File 'lib/lotus/generators/mailer.rb', line 69

def assert_mailer!
  if @mailer_name.nil? || @mailer_name.empty?
    raise Lotus::Commands::Generate::Error.new("Missing mailer name")
  end
end

#nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



107
108
109
# File 'lib/lotus/generators/mailer.rb', line 107

def name
  Utils::String.new(app_name || super).underscore
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lotus/generators/mailer.rb', line 45

def start
  assert_mailer!

  opts = {
    mailer:  @mailer_name,
    from:    DEFAULT_FROM,
    to:      DEFAULT_TO,
    subject: DEFAULT_SUBJECT,
  }

  templates = {
    'mailer_spec.rb.tt' => _mailer_spec_path,
    'mailer.rb.tt'      => _mailer_path,
    'template.txt.tt'   => _txt_template_path,
    'template.html.tt'  => _html_template_path,
  }

  templates.each do |src, dst|
    cli.template(source.join(src), target.join(dst), opts)
  end
end