Class: JAXB2Ruby::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/jaxb2ruby/template.rb

Overview

:nodoc:

Constant Summary collapse

HEADING =
"#\n# Auto-generated by jaxb2ruby v<%= VERSION %> on <%= Time.now %>\n# https://github.com/sshaw/jaxb2ruby\n#\n"
PATHS =
Hash[
      Dir[File.expand_path(__FILE__ + "/../../templates/*.erb")].map do |path|
[File.basename(path, ".erb"), path]
DEFAULT =

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Template

Returns a new instance of Template.



20
21
22
23
24
25
26
# File 'lib/jaxb2ruby/template.rb', line 20

def initialize(name = nil)
  # If it's not a named template assume it's a path
  path = PATHS[name] || name || DEFAULT
  @__erb = ERB.new(HEADING + File.read(path), nil, "<>%-")
rescue => e
  raise Error, "cannot load class template: #{e}"
end

Instance Method Details

#build(klass) ⇒ Object



28
29
30
31
# File 'lib/jaxb2ruby/template.rb', line 28

def build(klass)
  @class = klass
  @__erb.result(binding)
end