Class: GraphQLDocs::Renderer
- Inherits:
-
Object
- Object
- GraphQLDocs::Renderer
- Includes:
- Helpers
- Defined in:
- lib/graphql-docs/renderer.rb
Overview
Renders documentation content into HTML.
The Renderer takes parsed schema content and converts it to HTML using html-pipeline. It applies markdown processing, emoji support, and other filters, then wraps the result in the default layout template.
Constant Summary
Constants included from Helpers
Helpers::SLUGIFY_PRETTY_REGEXP
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Attributes included from Helpers
Instance Method Summary collapse
-
#initialize(parsed_schema, options) ⇒ Renderer
constructor
Initializes a new Renderer instance.
-
#render(contents, type: nil, name: nil, filename: nil) ⇒ String?
Renders content into complete HTML with layout.
-
#to_html(string, context: {}) ⇒ String
private
Converts a string to HTML using html-pipeline.
Methods included from Helpers
#graphql_directive_types, #graphql_enum_types, #graphql_input_object_types, #graphql_interface_types, #graphql_mutation_types, #graphql_object_types, #graphql_operation_types, #graphql_query_types, #graphql_root_types, #graphql_scalar_types, #graphql_union_types, #include, #markdownify, #slugify, #split_into_metadata_and_contents, #yaml?, #yaml_split
Constructor Details
#initialize(parsed_schema, options) ⇒ Renderer
Initializes a new Renderer instance.
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 |
# File 'lib/graphql-docs/renderer.rb', line 39 def initialize(parsed_schema, ) @parsed_schema = parsed_schema @options = @graphql_default_layout = ERB.new(File.read(@options[:templates][:default])) unless @options[:templates][:default].nil? @pipeline_config = @options[:pipeline_config] || {} pipeline = @pipeline_config[:pipeline] || {} context = @pipeline_config[:context] || {} filters = pipeline.map do |f| if filter?(f) f else key = filter_key(f) filter = HTML::Pipeline.constants.find { |c| c.downcase == key } # possibly a custom filter if filter.nil? Kernel.const_get(f) else HTML::Pipeline.const_get(filter) end end end @pipeline = HTML::Pipeline.new(filters, context) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
31 32 33 |
# File 'lib/graphql-docs/renderer.rb', line 31 def @options end |
Instance Method Details
#render(contents, type: nil, name: nil, filename: nil) ⇒ String?
Renders content into complete HTML with layout.
This method converts the content through the html-pipeline filters and wraps it in the default layout template. If the method returns nil, no file will be written.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/graphql-docs/renderer.rb', line 80 def render(contents, type: nil, name: nil, filename: nil) # Include all options (like Generator does) to support YAML frontmatter variables like title opts = @options.merge({type: type, name: name, filename: filename}).merge(helper_methods) contents = to_html(contents, context: {filename: filename}) return contents if @graphql_default_layout.nil? opts[:content] = contents @graphql_default_layout.result(OpenStruct.new(opts).instance_eval { binding }) end |
#to_html(string, context: {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a string to HTML using html-pipeline.
98 99 100 |
# File 'lib/graphql-docs/renderer.rb', line 98 def to_html(string, context: {}) @pipeline.to_html(string, context) end |