class CookieCutter::Cookie
builds a text file with specified parameters A cookie knows:
-
it’s name
-
where to save itself
Constants
- CONFIG_PATH
- OUTPUT_DIR
constants
- TEMPLATE_NAME
Attributes
name[RW]
output[RW]
overwrite[RW]
template_options[RW]
Public Class Methods
new(name, template_options = {})
click to toggle source
# File lib/cookie_cutter/cookie.rb, line 18 def initialize(name, template_options = {}) # defaults @overwrite = true @name = name @output = {} @output[:name] = name @template_options = template_options end
Public Instance Methods
assemble()
click to toggle source
# File lib/cookie_cutter/cookie.rb, line 27 def assemble _template_path = File.open(self.template_path).read output = ERB.new(_template_path).result(binding) return output end
save()
click to toggle source
# File lib/cookie_cutter/cookie.rb, line 33 def save template_output = self.assemble save_path = File.join(self.where_to_save, "#{@name}.txt") f = File.open(save_path, 'w+') f.write(template_output) end
template_path()
click to toggle source
assumption, all templates will be kept in the config directory
# File lib/cookie_cutter/cookie.rb, line 41 def template_path path = File.expand_path File.join(@template_options[CONFIG_PATH], @template_options[TEMPLATE_NAME]) # TODO fix and throw some sort of cool exception if !File.exists? path path = nil end return path end
where_to_save()
click to toggle source
if the output dir is relative, then assume relative to the current folder otherwise absolute
# File lib/cookie_cutter/cookie.rb, line 52 def where_to_save output_dir = @template_options[OUTPUT_DIR] # assume absolute full_path = output_dir if (Pathname.new(output_dir)).relative? full_path = File.expand_path(output_dir, Dir.pwd) end return full_path end