Module: GraphQLDocs::Helpers
Constant Summary collapse
- SLUGIFY_PRETTY_REGEXP =
Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze
Instance Attribute Summary collapse
-
#templates ⇒ Object
Returns the value of attribute templates.
Instance Method Summary collapse
- #graphql_directive_types ⇒ Object
- #graphql_enum_types ⇒ Object
- #graphql_input_object_types ⇒ Object
- #graphql_interface_types ⇒ Object
- #graphql_mutation_types ⇒ Object
- #graphql_object_types ⇒ Object
- #graphql_operation_types ⇒ Object
- #graphql_root_types ⇒ Object
- #graphql_scalar_types ⇒ Object
- #graphql_union_types ⇒ Object
- #include(filename, opts = {}) ⇒ Object
- #markdownify(string) ⇒ Object
- #slugify(str) ⇒ Object
- #split_into_metadata_and_contents(contents, parse: true) ⇒ Object
- #yaml?(contents) ⇒ Boolean
- #yaml_split(contents) ⇒ Object
Instance Attribute Details
#templates ⇒ Object
Returns the value of attribute templates.
10 11 12 |
# File 'lib/graphql-docs/helpers.rb', line 10 def templates @templates end |
Instance Method Details
#graphql_directive_types ⇒ Object
67 68 69 |
# File 'lib/graphql-docs/helpers.rb', line 67 def graphql_directive_types @parsed_schema[:directive_types] || [] end |
#graphql_enum_types ⇒ Object
51 52 53 |
# File 'lib/graphql-docs/helpers.rb', line 51 def graphql_enum_types @parsed_schema[:enum_types] || [] end |
#graphql_input_object_types ⇒ Object
59 60 61 |
# File 'lib/graphql-docs/helpers.rb', line 59 def graphql_input_object_types @parsed_schema[:input_object_types] || [] end |
#graphql_interface_types ⇒ Object
47 48 49 |
# File 'lib/graphql-docs/helpers.rb', line 47 def graphql_interface_types @parsed_schema[:interface_types] || [] end |
#graphql_mutation_types ⇒ Object
39 40 41 |
# File 'lib/graphql-docs/helpers.rb', line 39 def graphql_mutation_types @parsed_schema[:mutation_types] || [] end |
#graphql_object_types ⇒ Object
43 44 45 |
# File 'lib/graphql-docs/helpers.rb', line 43 def graphql_object_types @parsed_schema[:object_types] || [] end |
#graphql_operation_types ⇒ Object
35 36 37 |
# File 'lib/graphql-docs/helpers.rb', line 35 def graphql_operation_types @parsed_schema[:operation_types] || [] end |
#graphql_root_types ⇒ Object
31 32 33 |
# File 'lib/graphql-docs/helpers.rb', line 31 def graphql_root_types @parsed_schema[:root_types] || [] end |
#graphql_scalar_types ⇒ Object
63 64 65 |
# File 'lib/graphql-docs/helpers.rb', line 63 def graphql_scalar_types @parsed_schema[:scalar_types] || [] end |
#graphql_union_types ⇒ Object
55 56 57 |
# File 'lib/graphql-docs/helpers.rb', line 55 def graphql_union_types @parsed_schema[:union_types] || [] end |
#include(filename, opts = {}) ⇒ Object
18 19 20 21 22 |
# File 'lib/graphql-docs/helpers.rb', line 18 def include(filename, opts = {}) template = fetch_include(filename) opts = { base_url: @options[:base_url], classes: @options[:classes] }.merge(opts) template.result(OpenStruct.new(opts.merge(helper_methods)).instance_eval { binding }) end |
#markdownify(string) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/graphql-docs/helpers.rb', line 24 def markdownify(string) return '' if string.nil? type = @options[:pipeline_config][:context][:unsafe] ? :UNSAFE : :DEFAULT ::CommonMarker.render_html(string, type).strip end |
#slugify(str) ⇒ Object
12 13 14 15 16 |
# File 'lib/graphql-docs/helpers.rb', line 12 def slugify(str) slug = str.gsub(SLUGIFY_PRETTY_REGEXP, '-') slug.gsub!(/^\-|\-$/i, '') slug.downcase end |
#split_into_metadata_and_contents(contents, parse: true) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/graphql-docs/helpers.rb', line 71 def (contents, parse: true) pieces = yaml_split(contents) 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 YAML.safe_load(pieces[2]) || {} else pieces[2] end rescue Exception => e # rubocop:disable Lint/RescueException raise "Could not parse YAML for #{name}: #{e.}" end [, pieces[4]] end |
#yaml?(contents) ⇒ Boolean
88 89 90 |
# File 'lib/graphql-docs/helpers.rb', line 88 def yaml?(contents) contents =~ /\A-{3,5}\s*$/ end |
#yaml_split(contents) ⇒ Object
92 93 94 |
# File 'lib/graphql-docs/helpers.rb', line 92 def yaml_split(contents) contents.split(/^(-{5}|-{3})[ \t]*\r?\n?/, 3) end |