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
-
#format_type(field) ⇒ Object
Do you think I am proud of this? I am not.
- #graphql_enum_types ⇒ Object
- #graphql_input_object_types ⇒ Object
- #graphql_interface_types ⇒ Object
- #graphql_mutation_types ⇒ Object
- #graphql_object_types ⇒ Object
- #graphql_scalar_types ⇒ Object
- #graphql_union_types ⇒ Object
- #include(filename, opts = {}) ⇒ Object
- #markdown(string) ⇒ Object
- #slugify(str) ⇒ 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
#format_type(field) ⇒ Object
Do you think I am proud of this? I am not.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/graphql-docs/helpers.rb', line 25 def format_type(field) type_path = name_slug = nil type_name = '' if field['type']['kind'] == 'NON_NULL' if !field['type']['ofType']['ofType'].nil? # we're going to be a list...but what kind?! type_name << '[' if !field['type']['ofType']['ofType']['ofType'].nil? type_path = field['type']['ofType']['ofType']['ofType']['kind'] type_name << field['type']['ofType']['ofType']['ofType']['name'] name_slug = field['type']['ofType']['ofType']['ofType']['name'] # A required list of required items: [Blah!]! if field['type']['ofType']['ofType']['kind'] == 'NON_NULL' type_name << '!' end else # A required list of non-required items: [Blah]! type_path = field['type']['ofType']['ofType']['kind'] type_name << field['type']['ofType']['ofType']['name'] name_slug = field['type']['ofType']['ofType']['name'] end type_name << ']' type_name << '!' else type_path = field['type']['ofType']['kind'] type_name << field['type']['ofType']['name'] name_slug = field['type']['ofType']['name'] # Simple non-null item: Blah! type_name << '!' end elsif field['type']['kind'] == 'LIST' type_name << '[' if field['type']['ofType']['kind'] == 'NON_NULL' type_path = field['type']['ofType']['ofType']['kind'] type_name << field['type']['ofType']['ofType']['name'] name_slug = field['type']['ofType']['ofType']['name'] # Nullable list of non-null items: [Blah!] type_name << '!' else # Nullable list of nullable items: [Blah] type_path = field['type']['ofType']['kind'] type_name << field['type']['ofType']['name'] name_slug = field['type']['ofType']['name'] end type_name << ']' else # Simple nullable item: Blah type_path = field['type']['kind'] type_name << field['type']['name'] name_slug = field['type']['name'] end [type_path.downcase, type_name, name_slug.downcase] end |
#graphql_enum_types ⇒ Object
93 94 95 |
# File 'lib/graphql-docs/helpers.rb', line 93 def graphql_enum_types @parsed_schema['enum_types'] || [] end |
#graphql_input_object_types ⇒ Object
101 102 103 |
# File 'lib/graphql-docs/helpers.rb', line 101 def graphql_input_object_types @parsed_schema['input_object_types'] || [] end |
#graphql_interface_types ⇒ Object
89 90 91 |
# File 'lib/graphql-docs/helpers.rb', line 89 def graphql_interface_types @parsed_schema['interface_types'] || [] end |
#graphql_mutation_types ⇒ Object
81 82 83 |
# File 'lib/graphql-docs/helpers.rb', line 81 def graphql_mutation_types @parsed_schema['mutation_types'] || [] end |
#graphql_object_types ⇒ Object
85 86 87 |
# File 'lib/graphql-docs/helpers.rb', line 85 def graphql_object_types @parsed_schema['object_types'] || [] end |
#graphql_scalar_types ⇒ Object
105 106 107 |
# File 'lib/graphql-docs/helpers.rb', line 105 def graphql_scalar_types @parsed_schema['scalar_types'] || [] end |
#graphql_union_types ⇒ Object
97 98 99 |
# File 'lib/graphql-docs/helpers.rb', line 97 def graphql_union_types @parsed_schema['union_types'] || [] 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: [:base_url], classes: [:classes] }.merge(opts) template.result(OpenStruct.new(opts.merge(helper_methods)).instance_eval { binding }) end |
#markdown(string) ⇒ Object
19 20 21 22 |
# File 'lib/graphql-docs/helpers.rb', line 19 def markdown(string) return '' if string.nil? CommonMarker.render_html(string, :DEFAULT) 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 |