class Arc42Pandoc::ApiaryBuilder

Public Class Methods

new() click to toggle source
# File lib/arc42-pandoc/apiary/apiary_builder.rb, line 7
def initialize

end

Public Instance Methods

create(output, options = {}) click to toggle source
# File lib/arc42-pandoc/apiary/apiary_builder.rb, line 11
def create(output, options = {})
  options = sanatize_options(options)

  template = find_template(options[:template], options[:language])
  abort "The template is not available for the language '#{options[:language]}'. Check 'apiary list' for available templates." unless File.file?(template)

  ruyml = Ruyml::Data.new(options)
  ruyml.render_file(template, output)
end
list() click to toggle source
# File lib/arc42-pandoc/apiary/apiary_builder.rb, line 21
def list
  files = Dir[File.join(dirname, 'templates', '**/*')].select { |file| File.file?(file) }
  chunks = files.group_by { |file| file.split('/')[-2] }

  chunks.each { |lang, templates|
    puts "Templates available for language '#{lang}': \n  * #{templates.map { |t| t.split('/')[-1] }.join("\n  * ")}\n\n"
  }
end

Private Instance Methods

dirname() click to toggle source
# File lib/arc42-pandoc/apiary/apiary_builder.rb, line 37
def dirname
  File.dirname(__FILE__)
end
find_template(template, language) click to toggle source
# File lib/arc42-pandoc/apiary/apiary_builder.rb, line 32
def find_template(template, language)
  template = template.split('.')[0]
  File.join(dirname, 'templates', language.to_s, "#{template}.md")
end
sanatize_options(options) click to toggle source
# File lib/arc42-pandoc/apiary/apiary_builder.rb, line 41
def sanatize_options(options)
  options = Map[options]
  options[:language] = :en if options[:language].nil?
  options[:title] = '' if options[:title].nil?
  options[:apiroot] = '' if options[:apiroot].nil?
  options[:template] = 'basic' if options[:template].nil?

  options
end