Class: Soryo::BuildCommand
Instance Attribute Summary
Attributes inherited from Command
#config
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
add_options, descendants, #get_settings_file
Constructor Details
#initialize(template, email, options) ⇒ BuildCommand
Returns a new instance of BuildCommand.
Class Method Details
.add_command(program) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/commands/buildcommand.rb', line 25
def self.add_command(program)
program.command(:build) do |c|
c.syntax "build <template> <email> <json> [options]"
c.description "Build an email using a template"
c.action do |args, options|
if args.length != 2
abort('Please enter both a template and email')
end
command = Soryo::BuildCommand.new(args[0], args[1], options)
command.build
end
self.add_options(c)
end
end
|
Instance Method Details
#build ⇒ Object
11
12
13
14
15
16
|
# File 'lib/commands/buildcommand.rb', line 11
def build
template_builder = Soryo::Template.new(@template.to_s, @email.to_hash)
final_email = template_builder.compile
save final_email
end
|
#save(email) ⇒ Object
19
20
21
22
23
|
# File 'lib/commands/buildcommand.rb', line 19
def save(email)
filename = @email.shortname + '.html'
final_email = Soryo::FileInstance.new(filename)
final_email.write(email)
end
|