Module: GraphQLDocs::Helpers

Included in:
Generator, Renderer
Defined in:
lib/graphql-docs/helpers.rb

Constant Summary collapse

SLUGIFY_PRETTY_REGEXP =
Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#templatesObject

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_typesObject



35
36
37
# File 'lib/graphql-docs/helpers.rb', line 35

def graphql_enum_types
  @parsed_schema['enum_types']
end

#graphql_input_object_typesObject



43
44
45
# File 'lib/graphql-docs/helpers.rb', line 43

def graphql_input_object_types
  @parsed_schema['input_object_types']
end

#graphql_interface_typesObject



31
32
33
# File 'lib/graphql-docs/helpers.rb', line 31

def graphql_interface_types
  @parsed_schema['interface_types']
end

#graphql_mutation_typesObject



23
24
25
# File 'lib/graphql-docs/helpers.rb', line 23

def graphql_mutation_types
  @parsed_schema['mutation_types']
end

#graphql_object_typesObject



27
28
29
# File 'lib/graphql-docs/helpers.rb', line 27

def graphql_object_types
  @parsed_schema['object_types']
end

#graphql_scalar_typesObject



47
48
49
# File 'lib/graphql-docs/helpers.rb', line 47

def graphql_scalar_types
  @parsed_schema['scalar_types']
end

#graphql_union_typesObject



39
40
41
# File 'lib/graphql-docs/helpers.rb', line 39

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: @options[:base_url] }.merge(opts)
  template.result(OpenStruct.new(opts.merge(helper_methods)).instance_eval { binding })
end

#markdown(string) ⇒ Object



19
20
21
# File 'lib/graphql-docs/helpers.rb', line 19

def markdown(string)
  GitHub::Markdown.render(string || 'n/a')
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