lib/capitate/plugins/templates.rb in capitate-0.2.11 vs lib/capitate/plugins/templates.rb in capitate-0.2.13

- old
+ new

@@ -1,8 +1,8 @@ module Capitate::Plugins::Templates - # Load template. If extension is erb will be evaluated with binding. + # Load template. If the extension is .erb will be evaluated with binding. # # You can add to the list of places we search for templates by setting: # # set :templates_dirs, [ "path/to/templates1", "/path/to/templates2" ] # @@ -15,13 +15,14 @@ # ==== Options # +path+:: If starts with '/', absolute path, otherwise relative path to templates dir # +override_binding+:: Binding to override, otherwise uses current (task) binding # # ==== Examples - # template.load("memcached/memcached.monitrc.erb") - # put template.load("memcached/memcached.monitrc.erb"), "/tmp/memcached.monitrc" + # template.load("memcached/memcached.monitrc.erb") => "This is the text of eval'ed template found at ..." # + # put template.load("memcached/memcached.monitrc.erb"), "/tmp/memcached.monitrc" # Uploads eval'ed template to remote /tmp/ directory + # def load(path, override_binding = nil) template_dirs_found = template_dirs.select { |dir| File.exist?("#{dir}/#{path}") } # Not found anywhere, throw error if template_dirs_found.empty? @@ -67,13 +68,20 @@ end protected - # Load all possible places for templates + # Load all possible places for templates. + # + # Returns: + # * the <tt>:templates_dirs</tt> setting (if set) + # * the current directory + # * the <tt>:project_root</tt> setting (if set) + # * the gem templates path + # def template_dirs - @template_dir ||= begin + @template_dirs ||= begin template_dirs = [] template_dirs += fetch(:templates_dirs) if exists?(:templates_dirs) template_dirs << "." template_dirs << project_root if exists?(:project_root) template_dirs << gem_templates_root @@ -86,13 +94,14 @@ File.expand_path(File.dirname(__FILE__) + "/../../templates") end # Get full template path from relative path. # - # Something like <tt>monit/monit.cnf => /usr/lib/..../capitate/lib/templates/monit/monit.cnf</tt>. - # # ==== Options # +template_path+:: Relative path + # + # ==== Examples + # gem_template_path("monit/monit.cnf") => /usr/lib/..../capitate/lib/templates/monit/monit.cnf # def gem_template_path(template_path) File.join(gem_templates_root, template_path) end \ No newline at end of file