Method: Webapidoc.partial

Defined in:
lib/webapidoc/base.rb

.partial(template) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/webapidoc/base.rb', line 8

def self.partial(template)
  # rails like _ templates, simple injection
  template = template.to_s.split('/')
  template[ template.length - 1 ] = '_' + template[ template.length - 1 ]
  template = template.join('/')
  inFile = @@docDir + "/" + template + ".md"

  if !File.exists?(inFile)
    inFile = inFile + ".erb"
  end

  if !File.exists?(inFile)
    puts "partial not found: #{inFile}"
    return
  end

  # read partials contents and inject it
  ERB.new(File.open(inFile, 'r').read).result(binding)

end