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_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_scalar_types ⇒ Object
- #graphql_union_types ⇒ Object
- #has_yaml?(contents) ⇒ Boolean
- #include(filename, opts = {}) ⇒ Object
- #markdownify(string) ⇒ Object
- #slugify(str) ⇒ Object
- #split_into_metadata_and_contents(contents) ⇒ Object
- #yaml_split(contents) ⇒ Object
Instance Attribute Details
#templates ⇒ Object
Returns the value of attribute templates.
5 6 7 |
# File 'lib/graphql-docs/helpers.rb', line 5 def templates @templates end |
Instance Method Details
#graphql_enum_types ⇒ Object
40 41 42 |
# File 'lib/graphql-docs/helpers.rb', line 40 def graphql_enum_types @parsed_schema[:enum_types] || [] end |
#graphql_input_object_types ⇒ Object
48 49 50 |
# File 'lib/graphql-docs/helpers.rb', line 48 def graphql_input_object_types @parsed_schema[:input_object_types] || [] end |
#graphql_interface_types ⇒ Object
36 37 38 |
# File 'lib/graphql-docs/helpers.rb', line 36 def graphql_interface_types @parsed_schema[:interface_types] || [] end |
#graphql_mutation_types ⇒ Object
28 29 30 |
# File 'lib/graphql-docs/helpers.rb', line 28 def graphql_mutation_types @parsed_schema[:mutation_types] || [] end |
#graphql_object_types ⇒ Object
32 33 34 |
# File 'lib/graphql-docs/helpers.rb', line 32 def graphql_object_types @parsed_schema[:object_types] || [] end |
#graphql_operation_types ⇒ Object
24 25 26 |
# File 'lib/graphql-docs/helpers.rb', line 24 def graphql_operation_types @parsed_schema[:operation_types] || [] end |
#graphql_scalar_types ⇒ Object
52 53 54 |
# File 'lib/graphql-docs/helpers.rb', line 52 def graphql_scalar_types @parsed_schema[:scalar_types] || [] end |
#graphql_union_types ⇒ Object
44 45 46 |
# File 'lib/graphql-docs/helpers.rb', line 44 def graphql_union_types @parsed_schema[:union_types] || [] end |
#has_yaml?(contents) ⇒ Boolean
73 74 75 |
# File 'lib/graphql-docs/helpers.rb', line 73 def has_yaml?(contents) contents =~ /\A-{3,5}\s*$/ end |
#include(filename, opts = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/graphql-docs/helpers.rb', line 13 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
19 20 21 22 |
# File 'lib/graphql-docs/helpers.rb', line 19 def markdownify(string) return '' if string.nil? ::CommonMarker.render_html(string, :DEFAULT).strip end |
#slugify(str) ⇒ Object
7 8 9 10 11 |
# File 'lib/graphql-docs/helpers.rb', line 7 def slugify(str) slug = str.gsub(SLUGIFY_PRETTY_REGEXP, '-') slug.gsub!(%r!^\-|\-$!i, '') slug.downcase end |
#split_into_metadata_and_contents(contents) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/graphql-docs/helpers.rb', line 56 def (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 = YAML.load(pieces[2]) || {} rescue Exception => e # rubocop:disable Lint/RescueException raise "Could not parse YAML for #{name}: #{e.}" end [, pieces[4]] end |
#yaml_split(contents) ⇒ Object
77 78 79 |
# File 'lib/graphql-docs/helpers.rb', line 77 def yaml_split(contents) contents.split(/^(-{5}|-{3})[ \t]*\r?\n?/, 3) end |