Sha256: da80a6f905eac2931c39d02bac06a50f149fec4231618ce3e0b733dd26784be7

Contents?: true

Size: 1.04 KB

Versions: 18

Compression:

Stored size: 1.04 KB

Contents

require_relative '../core/renderer'

# :nodoc:
module Prmd
  # Render helper module
  module Render
    # Retrieve the schema template
    #
    # @param [Hash<Symbol, Object>] options
    # @return (see Prmd::Template.load_template)
    def self.get_template(options)
      template = options.fetch(:template) do
        abort 'render: Template was not provided'
      end
      template_dir = File.expand_path(template)
      # to keep backward compatibility
      template_dir = File.dirname(template) unless File.directory?(template_dir)
      Prmd::Template.load_template('schema.erb', template_dir)
    end
  end

  # Render provided schema to Markdown
  #
  # @param [Prmd::Schema] schema
  # @return [String] rendered schema in Markdown
  def self.render(schema, options = {})
    renderer = Prmd::Renderer.new(template: Render.get_template(options))
    doc = ''
    if options[:prepend]
      doc <<
      options[:prepend].map { |path| File.read(path) }.join("\n") <<
      "\n"
    end
    doc << renderer.render(schema, options)
    doc
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
prmd-0.14.0 lib/prmd/commands/render.rb
prmd-0.13.0 lib/prmd/commands/render.rb
prmd-0.12.0 lib/prmd/commands/render.rb
prmd-0.11.11 lib/prmd/commands/render.rb
prmd-0.11.10 lib/prmd/commands/render.rb
prmd-0.11.9 lib/prmd/commands/render.rb
prmd-0.11.8 lib/prmd/commands/render.rb
prmd-0.11.7 lib/prmd/commands/render.rb
prmd-0.11.6 lib/prmd/commands/render.rb
prmd-0.11.5 lib/prmd/commands/render.rb
prmd-0.11.4 lib/prmd/commands/render.rb
prmd-0.11.3 lib/prmd/commands/render.rb
prmd-0.11.2 lib/prmd/commands/render.rb
prmd-0.11.1 lib/prmd/commands/render.rb
prmd-0.11.0 lib/prmd/commands/render.rb
prmd-0.10.0 lib/prmd/commands/render.rb
prmd-0.9.0 lib/prmd/commands/render.rb
prmd-0.8.0 lib/prmd/commands/render.rb