module JsonSchemaDocs::Helpers

Constants

SLUGIFY_PRETTY_REGEXP

Attributes

templates[RW]

Public Instance Methods

include(filename, opts = {}) click to toggle source
# File lib/json-schema-docs/helpers.rb, line 17
def include(filename, opts = {})
  template = fetch_include(filename)
  opts = { base_url: @options[:base_url] }.merge(opts)
  template.result(OpenStruct.new(opts.merge(helper_methods)).instance_eval { binding })
end
markdownify(string) click to toggle source
# File lib/json-schema-docs/helpers.rb, line 23
def markdownify(string)
  return '' if string.nil?
  type = @options[:pipeline_config][:context][:unsafe] ? :UNSAFE : :DEFAULT
  ::CommonMarker.render_html(string, type).strip
end
schemata(name) click to toggle source
# File lib/json-schema-docs/helpers.rb, line 33
def schemata(name)
  @parsed_schema[name]
end
slugify(str) click to toggle source
# File lib/json-schema-docs/helpers.rb, line 11
def slugify(str)
  slug = str.gsub(SLUGIFY_PRETTY_REGEXP, '-')
  slug.gsub!(%r!^\-|\-$!i, '')
  slug.downcase
end
types() click to toggle source
# File lib/json-schema-docs/helpers.rb, line 29
def types
  @parsed_schema.keys
end

Private Instance Methods

fetch_include(filename) click to toggle source
# File lib/json-schema-docs/helpers.rb, line 39
def fetch_include(filename)
  @templates ||= {}

  return @templates[filename] unless @templates[filename].nil?

  contents = File.read(File.join(@options[:templates][:includes], filename))

  @templates[filename] = ERB.new(contents, nil, '-')
end
helper_methods() click to toggle source
# File lib/json-schema-docs/helpers.rb, line 49
def helper_methods
  return @helper_methods if defined?(@helper_methods)

  @helper_methods = {}

  Helpers.instance_methods.each do |name|
    next if name == :helper_methods
    @helper_methods[name] = method(name)
  end

  @helper_methods
end