lib/graphql-docs/helpers.rb in graphql-docs-1.9.1 vs lib/graphql-docs/helpers.rb in graphql-docs-2.0.0

- old
+ new

@@ -8,11 +8,11 @@ attr_accessor :templates def slugify(str) slug = str.gsub(SLUGIFY_PRETTY_REGEXP, '-') - slug.gsub!(%r!^\-|\-$!i, '') + slug.gsub!(/^\-|\-$/i, '') slug.downcase end def include(filename, opts = {}) template = fetch_include(filename) @@ -20,10 +20,11 @@ template.result(OpenStruct.new(opts.merge(helper_methods)).instance_eval { binding }) end def markdownify(string) return '' if string.nil? + type = @options[:pipeline_config][:context][:unsafe] ? :UNSAFE : :DEFAULT ::CommonMarker.render_html(string, type).strip end def graphql_root_types @@ -65,31 +66,27 @@ def graphql_directive_types @parsed_schema[:directive_types] || [] end def split_into_metadata_and_contents(contents, parse: true) - 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 + raise "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." if pieces.size < 4 + # Parse begin - if parse - meta = YAML.load(pieces[2]) || {} - else - meta = pieces[2] - end + meta = if parse + YAML.safe_load(pieces[2]) || {} + else + pieces[2] + end 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) + def yaml?(contents) contents =~ /\A-{3,5}\s*$/ end def yaml_split(contents) contents.split(/^(-{5}|-{3})[ \t]*\r?\n?/, 3) @@ -112,9 +109,10 @@ @helper_methods = {} Helpers.instance_methods.each do |name| next if name == :helper_methods + @helper_methods[name] = method(name) end @helper_methods end