lib/graphql-docs/helpers.rb in graphql-docs-1.0.0.pre2 vs lib/graphql-docs/helpers.rb in graphql-docs-1.0.0.pre3
- old
+ new
@@ -51,9 +51,34 @@
def graphql_scalar_types
@parsed_schema[:scalar_types] || []
end
+ def split_into_metadata_and_contents(contents)
+ opts = {}
+ pieces = yaml_split(contents)
+ if pieces.size < 4
+ raise RuntimeError.new(
+ "The file '#{content_filename}' appears to start with a metadata section (three or five dashes at the top) but it does not seem to be in the correct format.",
+ )
+ end
+ # Parse
+ begin
+ meta = YAML.load(pieces[2]) || {}
+ rescue Exception => e # rubocop:disable Lint/RescueException
+ raise "Could not parse YAML for #{name}: #{e.message}"
+ end
+ [meta, pieces[4]]
+ end
+
+ def has_yaml?(contents)
+ contents =~ /\A-{3,5}\s*$/
+ end
+
+ def yaml_split(contents)
+ contents.split(/^(-{5}|-{3})[ \t]*\r?\n?/, 3)
+ end
+
private
def fetch_include(filename)
@templates ||= {}