lib/graphql-docs/renderer.rb in graphql-docs-0.1.0 vs lib/graphql-docs/renderer.rb in graphql-docs-0.1.1
- old
+ new
@@ -1,14 +1,20 @@
require 'html/pipeline'
require 'extended-markdown-filter'
-require 'page-toc-filter'
module GraphQLDocs
class Renderer
- def initialize(options)
+ include Helpers
+
+ def initialize(options, parsed_schema)
@options = options
+ @parsed_schema = parsed_schema
+ unless @options[:templates][:default].nil?
+ @graphql_default_layout = ERB.new(File.read(@options[:templates][:default]))
+ end
+
@pipeline_config = @options[:pipeline_config]
filters = @pipeline_config[:pipeline].map do |f|
if filter?(f)
f
@@ -25,11 +31,14 @@
end
@pipeline = HTML::Pipeline.new(filters, @pipeline_config[:context])
end
- def render(string)
- @pipeline.to_html(string)
+ def render(type, name, contents)
+ contents = @pipeline.to_html(contents)
+ return contents if @graphql_default_layout.nil?
+ opts = { contents: contents, type: type, name: name}.merge(helper_methods)
+ @graphql_default_layout.result(OpenStruct.new(opts).instance_eval { binding })
end
private
def filter_key(s)