Module: JsonSchemaDocs::Helpers

Included in:
Generator, Parser, Renderer
Defined in:
lib/json-schema-docs/helpers.rb

Constant Summary collapse

SLUGIFY_PRETTY_REGEXP =
Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#templatesObject

Returns the value of attribute templates.



9
10
11
# File 'lib/json-schema-docs/helpers.rb', line 9

def templates
  @templates
end

Instance Method Details

#include(filename, opts = {}) ⇒ Object



17
18
19
20
21
# 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) ⇒ Object



23
24
25
26
27
# 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) ⇒ Object



33
34
35
# File 'lib/json-schema-docs/helpers.rb', line 33

def schemata(name)
  @parsed_schema[name]
end

#slugify(str) ⇒ Object



11
12
13
14
15
# 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

#typesObject



29
30
31
# File 'lib/json-schema-docs/helpers.rb', line 29

def types
  @parsed_schema.keys
end