Class: Bundlegem::TemplateManager
- Inherits:
-
Object
- Object
- Bundlegem::TemplateManager
- Defined in:
- lib/bundlegem/template_manager.rb
Overview
This class handles the logic for finding templates in the user’s dir, the gem’s builtin templates (and on the web some day)
Class Method Summary collapse
- .create_new_template(template_name) ⇒ Object
-
.file_in_source?(target) ⇒ Boolean
Get’s path to ‘target’ from within the gem’s “templates” folder within the gem’s source.
-
.find_in_source_paths(target) ⇒ Object
EDIT: Reworked from Thor to not rely on Thor (or do so much unneeded stuff).
- .get_default_template_name ⇒ Object
- .get_internal_template_location ⇒ Object
- .get_template_src(options) ⇒ Object
- .template_exists_within_repo?(template_name) ⇒ Boolean
Class Method Details
.create_new_template(template_name) ⇒ Object
12 13 14 |
# File 'lib/bundlegem/template_manager.rb', line 12 def create_new_template(template_name) end |
.file_in_source?(target) ⇒ Boolean
Get’s path to ‘target’ from within the gem’s “templates” folder within the gem’s source
52 53 54 55 |
# File 'lib/bundlegem/template_manager.rb', line 52 def file_in_source?(target) src_in_source_path = "#{File.dirname(__FILE__)}/templates/#{target}" File.exist?(src_in_source_path) end |
.find_in_source_paths(target) ⇒ Object
EDIT: Reworked from Thor to not rely on Thor (or do so much unneeded stuff)
44 45 46 47 48 |
# File 'lib/bundlegem/template_manager.rb', line 44 def find_in_source_paths(target) src_in_source_path = "#{File.dirname(__FILE__)}/templates/#{target}" return src_in_source_path if File.exist?(src_in_source_path) target # failed, hopefully full path to a user specified gem template file end |
.get_default_template_name ⇒ Object
17 18 19 |
# File 'lib/bundlegem/template_manager.rb', line 17 def get_default_template_name "newgem" end |
.get_internal_template_location ⇒ Object
33 34 35 |
# File 'lib/bundlegem/template_manager.rb', line 33 def get_internal_template_location File.("#{File.dirname(__FILE__)}/templates") end |
.get_template_src(options) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bundlegem/template_manager.rb', line 21 def get_template_src() template_name = ["template"].nil? ? get_default_template_name : ["template"] if template_exists_within_repo?(template_name) template_location = get_internal_template_location else template_location = File.("~/.bundlegem/templates") end template_src = "#{template_location}/#{template_name}" end |
.template_exists_within_repo?(template_name) ⇒ Boolean
37 38 39 |
# File 'lib/bundlegem/template_manager.rb', line 37 def template_exists_within_repo?(template_name) TemplateManager.file_in_source?(template_name) end |