Class: RoboPigeon::Extensions::Template
- Inherits:
-
Object
- Object
- RoboPigeon::Extensions::Template
- Defined in:
- lib/robopigeon/extend/template.rb
Constant Summary collapse
- TEMPLATE_PATH =
File.('../templates/', __FILE__).freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#template ⇒ Object
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
- #extension_name_lower ⇒ Object
- #extension_name_upper ⇒ Object
- #render_to(path) ⇒ Object
- #user_email ⇒ Object
- #user_name ⇒ Object
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/robopigeon/extend/template.rb', line 7 def name @name end |
#template ⇒ Object
Returns the value of attribute template.
7 8 9 |
# File 'lib/robopigeon/extend/template.rb', line 7 def template @template end |
Class Method Details
.render(name, path, template = 'default') ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/robopigeon/extend/template.rb', line 9 def self.render(name, path, template='default') to_render = new to_render.name = name to_render.template = template raise "No template with name #{template}" unless File.directory?("#{TEMPLATE_PATH}/#{template}") to_render.render_to(path) end |
Instance Method Details
#extension_name_lower ⇒ Object
37 38 39 |
# File 'lib/robopigeon/extend/template.rb', line 37 def extension_name_lower name.downcase end |
#extension_name_upper ⇒ Object
41 42 43 |
# File 'lib/robopigeon/extend/template.rb', line 41 def extension_name_upper name.capitalize end |
#render_to(path) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/robopigeon/extend/template.rb', line 18 def render_to(path) cwd = FileUtils.pwd base = File.("#{path}/robopigeon_#{name}") FileUtils.cd "#{TEMPLATE_PATH}/#{template}" FileUtils.mkdir_p base.to_s Dir.glob('{**{,/*/**},.*}') do |file| new_filename = file.gsub('extension', name).gsub('.erb', '') if File.directory?(file) FileUtils.mkdir("#{base}/#{new_filename}") unless File.exist? "#{base}/#{new_filename}" puts "Created directory #{base}/#{new_filename}" else content = ERB.new(File.read(file)).result(binding) File.write("#{base}/#{new_filename}", content) puts "Created #{base}/#{new_filename}" end end FileUtils.cd cwd end |
#user_email ⇒ Object
45 46 47 |
# File 'lib/robopigeon/extend/template.rb', line 45 def user_email `git config user.email`.strip end |
#user_name ⇒ Object
49 50 51 |
# File 'lib/robopigeon/extend/template.rb', line 49 def user_name `git config user.name`.strip end |