Module: JsonSchemaDocs::Helpers
Constant Summary collapse
- SLUGIFY_PRETTY_REGEXP =
Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze
Instance Attribute Summary collapse
-
#templates ⇒ Object
Returns the value of attribute templates.
Instance Method Summary collapse
- #include(filename, opts = {}) ⇒ Object
- #markdownify(string) ⇒ Object
- #schemata(name) ⇒ Object
- #slugify(str) ⇒ Object
- #types ⇒ Object
Instance Attribute Details
#templates ⇒ Object
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: [: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 = [: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 |
#types ⇒ Object
29 30 31 |
# File 'lib/json-schema-docs/helpers.rb', line 29 def types @parsed_schema.keys end |