Module: Prmd::CLI::Render

Extended by:
Base
Defined in:
lib/prmd/cli/render.rb

Overview

‘render’ command module.

Class Method Summary collapse

Methods included from Base

execute, make_parser, noop_execute, parse_options, run

Class Method Details

.execute(options = {}) ⇒ void

This method returns an undefined value.

Executes the ‘render’ command.

Examples:

Usage

Prmd::CLI::Render.execute(argv: ['schema/api.json'],
                          template: 'my_template.md.erb',
                          output_file: 'schema/api.md')

Parameters:

  • options (Hash<Symbol, Object>) (defaults to: {})


40
41
42
43
44
45
# File 'lib/prmd/cli/render.rb', line 40

def self.execute(options = {})
  filename = options.fetch(:argv).first
  _, data = try_read(filename)
  schema = Prmd::Schema.new(data)
  write_result Prmd.render(schema, options), options
end

.make_parser(options = {}) ⇒ OptionParser

Returns a OptionParser for parsing ‘render’ command options.

Parameters:

  • options (Hash<Symbol, Object>) (defaults to: {})

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/prmd/cli/render.rb', line 14

def self.make_parser(options = {})
  binname = options.fetch(:bin, 'prmd')

  OptionParser.new do |opts|
    opts.banner = "#{binname} render [options] <combined schema>"
    opts.on('-p', '--prepend header,overview', Array, 'Prepend files to output') do |p|
      yield :prepend, p
    end
    opts.on('-t', '--template templates', String, 'Use alternate template') do |t|
      yield :template, t
    end
    opts.on('-o', '--output-file FILENAME', String, 'File to write result to') do |n|
      yield :output_file, n
    end
  end
end