Class: JsonSchemaDocs::Generator
- Inherits:
-
Object
- Object
- JsonSchemaDocs::Generator
- Includes:
- Helpers
- Defined in:
- lib/json-schema-docs/generator.rb
Constant Summary collapse
- DYNAMIC_PAGES =
i(links resource)
- STATIC_PAGES =
i(index)
Constants included from Helpers
Helpers::SLUGIFY_PRETTY_REGEXP
Instance Attribute Summary collapse
-
#parsed_schema ⇒ Object
Returns the value of attribute parsed_schema.
Attributes included from Helpers
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(parsed_schema, options) ⇒ Generator
constructor
A new instance of Generator.
Methods included from Helpers
#include, #markdownify, #schemata, #slugify, #types
Constructor Details
#initialize(parsed_schema, options) ⇒ Generator
Returns a new instance of Generator.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/json-schema-docs/generator.rb', line 13 def initialize(parsed_schema, ) @parsed_schema = parsed_schema = @renderer = [:renderer].new(@parsed_schema, ) DYNAMIC_PAGES.each do |sym| if !File.exist?([:templates][sym]) raise IOError, "`#{sym}` template #{@options[:templates][sym]} was not found" end instance_variable_set("@json_schema_#{sym}_template", ERB.new(File.read([:templates][sym]), nil, '-')) end STATIC_PAGES.each do |sym| if [:landing_pages][sym].nil? instance_variable_set("@#{sym}_landing_page", nil) elsif !File.exist?([:landing_pages][sym]) raise IOError, "`#{sym}` landing page #{@options[:landing_pages][sym]} was not found" end landing_page_contents = File.read([:landing_pages][sym]) instance_variable_set("@json_schema_#{sym}_landing_page", landing_page_contents) end end |
Instance Attribute Details
#parsed_schema ⇒ Object
Returns the value of attribute parsed_schema.
8 9 10 |
# File 'lib/json-schema-docs/generator.rb', line 8 def parsed_schema @parsed_schema end |
Instance Method Details
#generate ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/json-schema-docs/generator.rb', line 39 def generate FileUtils.rm_rf([:output_dir]) if [:delete_output] @parsed_schema.each_pair do |resource, schemata| DYNAMIC_PAGES.each do |type| layout = instance_variable_get("@json_schema_#{type}_template") opts = .merge(helper_methods) opts[:schemata_resource] = resource opts[:schemata] = schemata contents = layout.result(OpenStruct.new(opts).instance_eval { binding }) write_file(type, resource, schemata['title'], contents) end end STATIC_PAGES.each do |name| landing_page = instance_variable_get("@json_schema_#{name}_landing_page") unless landing_page.nil? write_file(:landing_page, name.to_s, nil, landing_page, trim: false) end end if [:use_default_styles] assets_dir = File.join(File.dirname(__FILE__), 'layouts', 'assets') FileUtils.mkdir_p(File.join([:output_dir], 'assets')) sass = File.join(assets_dir, 'css', 'screen.scss') system `sass --sourcemap=none #{sass}:#{@options[:output_dir]}/assets/style.css` end true end |