Class: Gem::Commands::SkeletonCommand::TemplateRenderer
- Inherits:
-
Object
- Object
- Gem::Commands::SkeletonCommand::TemplateRenderer
- Defined in:
- lib/rubygems/commands/skeleton_command.rb
Instance Attribute Summary collapse
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
Instance Method Summary collapse
- #get_binding ⇒ Object
-
#initialize(gem_name) ⇒ TemplateRenderer
constructor
A new instance of TemplateRenderer.
- #render(template, target_file = nil) ⇒ Object
Constructor Details
#initialize(gem_name) ⇒ TemplateRenderer
Returns a new instance of TemplateRenderer.
65 66 67 68 |
# File 'lib/rubygems/commands/skeleton_command.rb', line 65 def initialize(gem_name) @gem_name = gem_name @templates_dir = File.(File.join(File.dirname(__FILE__), '..', '..', '..', 'templates')) end |
Instance Attribute Details
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
63 64 65 |
# File 'lib/rubygems/commands/skeleton_command.rb', line 63 def gem_name @gem_name end |
Instance Method Details
#get_binding ⇒ Object
70 71 72 |
# File 'lib/rubygems/commands/skeleton_command.rb', line 70 def get_binding binding end |
#render(template, target_file = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rubygems/commands/skeleton_command.rb', line 74 def render(template, target_file = nil) source_text = File.read("#{File.join(@templates_dir, template)}") source_object = ERB.new(source_text) result = source_object.result(get_binding) if target_file File.open(File.join(gem_name, target_file), 'w') do |f| f.write(result) end else result end end |