sleeping_king_studios-docs 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/CODE_OF_CONDUCT.md +132 -0
  4. data/LICENSE +22 -0
  5. data/README.md +101 -0
  6. data/lib/sleeping_king_studios/docs/commands/generate.rb +268 -0
  7. data/lib/sleeping_king_studios/docs/commands/generators/base.rb +97 -0
  8. data/lib/sleeping_king_studios/docs/commands/generators/data_generator.rb +68 -0
  9. data/lib/sleeping_king_studios/docs/commands/generators/reference_generator.rb +59 -0
  10. data/lib/sleeping_king_studios/docs/commands/generators.rb +15 -0
  11. data/lib/sleeping_king_studios/docs/commands/installation/install_jekyll.rb +273 -0
  12. data/lib/sleeping_king_studios/docs/commands/installation/install_templates.rb +125 -0
  13. data/lib/sleeping_king_studios/docs/commands/installation/install_workflow.rb +121 -0
  14. data/lib/sleeping_king_studios/docs/commands/installation.rb +15 -0
  15. data/lib/sleeping_king_studios/docs/commands/parse.rb +51 -0
  16. data/lib/sleeping_king_studios/docs/commands/write_file.rb +89 -0
  17. data/lib/sleeping_king_studios/docs/commands.rb +14 -0
  18. data/lib/sleeping_king_studios/docs/data/base.rb +48 -0
  19. data/lib/sleeping_king_studios/docs/data/class_object.rb +119 -0
  20. data/lib/sleeping_king_studios/docs/data/constant_object.rb +161 -0
  21. data/lib/sleeping_king_studios/docs/data/metadata.rb +196 -0
  22. data/lib/sleeping_king_studios/docs/data/method_object.rb +555 -0
  23. data/lib/sleeping_king_studios/docs/data/module_object.rb +234 -0
  24. data/lib/sleeping_king_studios/docs/data/namespace_object.rb +375 -0
  25. data/lib/sleeping_king_studios/docs/data/root_object.rb +40 -0
  26. data/lib/sleeping_king_studios/docs/data/see_tags/base.rb +35 -0
  27. data/lib/sleeping_king_studios/docs/data/see_tags/class_method_tag.rb +99 -0
  28. data/lib/sleeping_king_studios/docs/data/see_tags/constant_tag.rb +60 -0
  29. data/lib/sleeping_king_studios/docs/data/see_tags/definition_tag.rb +52 -0
  30. data/lib/sleeping_king_studios/docs/data/see_tags/instance_method_tag.rb +69 -0
  31. data/lib/sleeping_king_studios/docs/data/see_tags/link_tag.rb +53 -0
  32. data/lib/sleeping_king_studios/docs/data/see_tags/namespace_item_tag.rb +56 -0
  33. data/lib/sleeping_king_studios/docs/data/see_tags/reference_tag.rb +92 -0
  34. data/lib/sleeping_king_studios/docs/data/see_tags/text_tag.rb +30 -0
  35. data/lib/sleeping_king_studios/docs/data/see_tags/unstructured_tag.rb +37 -0
  36. data/lib/sleeping_king_studios/docs/data/see_tags.rb +101 -0
  37. data/lib/sleeping_king_studios/docs/data/types/grammar.treetop +49 -0
  38. data/lib/sleeping_king_studios/docs/data/types/key_value_type.rb +54 -0
  39. data/lib/sleeping_king_studios/docs/data/types/parameterized_type.rb +57 -0
  40. data/lib/sleeping_king_studios/docs/data/types/parser.rb +143 -0
  41. data/lib/sleeping_king_studios/docs/data/types/type.rb +100 -0
  42. data/lib/sleeping_king_studios/docs/data/types.rb +19 -0
  43. data/lib/sleeping_king_studios/docs/data.rb +29 -0
  44. data/lib/sleeping_king_studios/docs/errors/file_already_exists.rb +22 -0
  45. data/lib/sleeping_king_studios/docs/errors/file_error.rb +30 -0
  46. data/lib/sleeping_king_studios/docs/errors/file_not_found.rb +22 -0
  47. data/lib/sleeping_king_studios/docs/errors/invalid_directory.rb +22 -0
  48. data/lib/sleeping_king_studios/docs/errors/invalid_file.rb +22 -0
  49. data/lib/sleeping_king_studios/docs/errors.rb +19 -0
  50. data/lib/sleeping_king_studios/docs/registry.rb +22 -0
  51. data/lib/sleeping_king_studios/docs/registry_query.rb +93 -0
  52. data/lib/sleeping_king_studios/docs/tasks/base.rb +20 -0
  53. data/lib/sleeping_king_studios/docs/tasks/generate.rb +39 -0
  54. data/lib/sleeping_king_studios/docs/tasks/installation/install_jekyll.rb +67 -0
  55. data/lib/sleeping_king_studios/docs/tasks/installation/install_templates.rb +39 -0
  56. data/lib/sleeping_king_studios/docs/tasks/installation/install_workflow.rb +53 -0
  57. data/lib/sleeping_king_studios/docs/tasks/installation.rb +8 -0
  58. data/lib/sleeping_king_studios/docs/tasks/update.rb +35 -0
  59. data/lib/sleeping_king_studios/docs/tasks.rb +14 -0
  60. data/lib/sleeping_king_studios/docs/templates/config.yml.erb +22 -0
  61. data/lib/sleeping_king_studios/docs/templates/deploy-pages.yml.erb +67 -0
  62. data/lib/sleeping_king_studios/docs/templates/includes/breadcrumbs.md +7 -0
  63. data/lib/sleeping_king_studios/docs/templates/includes/reference/attribute.md +23 -0
  64. data/lib/sleeping_king_studios/docs/templates/includes/reference/attributes/heading.md +15 -0
  65. data/lib/sleeping_king_studios/docs/templates/includes/reference/class.md +27 -0
  66. data/lib/sleeping_king_studios/docs/templates/includes/reference/constant.md +8 -0
  67. data/lib/sleeping_king_studios/docs/templates/includes/reference/constants/heading.md +6 -0
  68. data/lib/sleeping_king_studios/docs/templates/includes/reference/constants/inherited.md +4 -0
  69. data/lib/sleeping_king_studios/docs/templates/includes/reference/constants/overview.md +60 -0
  70. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/breadcrumbs.md +21 -0
  71. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/class_attributes.md +9 -0
  72. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/class_methods.md +9 -0
  73. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/constants.md +9 -0
  74. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/constructor.md +12 -0
  75. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/definitions.md +23 -0
  76. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/details.md +34 -0
  77. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/instance_attributes.md +9 -0
  78. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/instance_methods.md +17 -0
  79. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/overview.md +74 -0
  80. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/subclasses.md +10 -0
  81. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/class_attributes.md +10 -0
  82. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/class_methods.md +10 -0
  83. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/constants.md +10 -0
  84. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/instance_attributes.md +10 -0
  85. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/instance_methods.md +10 -0
  86. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/overview.md +41 -0
  87. data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents.md +27 -0
  88. data/lib/sleeping_king_studios/docs/templates/includes/reference/method.md +27 -0
  89. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/aliases.md +4 -0
  90. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/heading.md +14 -0
  91. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/inherited.md +4 -0
  92. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/overload.md +18 -0
  93. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/overloads.md +12 -0
  94. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/overview.md +41 -0
  95. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/parameters.md +31 -0
  96. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/post_overview.md +51 -0
  97. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/raises.md +14 -0
  98. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/return_types.md +9 -0
  99. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/returns.md +14 -0
  100. data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/yields.md +42 -0
  101. data/lib/sleeping_king_studios/docs/templates/includes/reference/module.md +23 -0
  102. data/lib/sleeping_king_studios/docs/templates/includes/reference/namespace.md +33 -0
  103. data/lib/sleeping_king_studios/docs/templates/includes/reference/parent_link.md +6 -0
  104. data/lib/sleeping_king_studios/docs/templates/includes/reference/reference_link.md +7 -0
  105. data/lib/sleeping_king_studios/docs/templates/includes/reference/see_link.md +7 -0
  106. data/lib/sleeping_king_studios/docs/templates/includes/reference/type.md +14 -0
  107. data/lib/sleeping_king_studios/docs/templates/includes/reference/type_list.md +4 -0
  108. data/lib/sleeping_king_studios/docs/templates/includes/reference/types/array_type.md +1 -0
  109. data/lib/sleeping_king_studios/docs/templates/includes/reference/types/hash_type.md +1 -0
  110. data/lib/sleeping_king_studios/docs/templates/includes/reference/types/ordered_type.md +1 -0
  111. data/lib/sleeping_king_studios/docs/templates/pages/index.md.erb +22 -0
  112. data/lib/sleeping_king_studios/docs/templates/pages/reference.md.erb +14 -0
  113. data/lib/sleeping_king_studios/docs/templates/pages/versions.md.erb +13 -0
  114. data/lib/sleeping_king_studios/docs/version.rb +59 -0
  115. data/lib/sleeping_king_studios/docs.rb +27 -0
  116. metadata +243 -0
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sleeping_king_studios/docs/data/see_tags'
4
+
5
+ module SleepingKingStudios::Docs::Data::SeeTags
6
+ # Data object representing a @see tag with a class method link.
7
+ class ClassMethodTag < SleepingKingStudios::Docs::Data::SeeTags::NamespaceItemTag # rubocop:disable Layout/LineLength
8
+ DEFINITION_PREFIX =
9
+ '(::)?[[:upper:]][[:alnum:]]*(::[[:upper:]][[:alnum:]]*)*'
10
+ private_constant :DEFINITION_PREFIX
11
+
12
+ METHOD_SUFFIX =
13
+ '([[[:lower:]][[:digit:]]_\+\-\*\/\[\]\<\>])+[=?]'
14
+ private_constant :METHOD_SUFFIX
15
+
16
+ CLASS_METHOD_PATTERN =
17
+ /\A(#{DEFINITION_PREFIX})?\.#{METHOD_SUFFIX}?\z/
18
+ private_constant :CLASS_METHOD_PATTERN
19
+
20
+ LEGACY_CLASS_METHOD_PATTERN =
21
+ /\A(#{DEFINITION_PREFIX})?::([[[:lower:]][[:digit:]]_])+\z/
22
+ private_constant :LEGACY_CLASS_METHOD_PATTERN
23
+
24
+ class << self
25
+ # Checks if the given tag object is a reference to a class method.
26
+ #
27
+ # @param native [YARD::Tags::Tag] the tag object.
28
+ #
29
+ # @return [true, false] true if the tag object is a reference; otherwise
30
+ # false.
31
+ def match?(native)
32
+ name = native.name.sub(/\.\z/, '')
33
+
34
+ name.match?(CLASS_METHOD_PATTERN) ||
35
+ name.match?(LEGACY_CLASS_METHOD_PATTERN)
36
+ end
37
+ alias matches? match?
38
+ end
39
+
40
+ # @return [true, false] true if the referenced class method is an attribute;
41
+ # otherwise false.
42
+ def attribute?
43
+ return @attribute unless @attribute.nil?
44
+
45
+ return @attribute = false unless exists?
46
+
47
+ native_method = registry.find do |obj|
48
+ obj.type == :method &&
49
+ obj.scope == :class &&
50
+ obj.path == normalized_path
51
+ end
52
+
53
+ @attribute = native_method.is_attribute?
54
+ end
55
+
56
+ # @return [String] the reference type.
57
+ def type
58
+ attribute? ? 'class-attribute' : 'class-method'
59
+ end
60
+
61
+ private
62
+
63
+ def normalized_path
64
+ return @normalized_path if @normalized_path
65
+
66
+ @normalized_path = absolute_path? ? reference : qualified_path
67
+
68
+ return @normalized_path if @normalized_path.include?('.')
69
+
70
+ @normalized_path = @normalized_path.reverse.sub('::', '.').reverse
71
+ end
72
+
73
+ def query_registry(name)
74
+ registry_query.class_method_exists?(name)
75
+ end
76
+
77
+ def split_legacy_reference
78
+ scoped = relative_path? ? qualified_path : reference
79
+ segments = scoped.split('::')
80
+ @reference_name = segments.pop
81
+ @namespace = segments.join('::')
82
+ end
83
+
84
+ def split_method_reference
85
+ scoped = relative_path? ? qualified_path : reference
86
+ segments = scoped.split('.')
87
+ @reference_name = segments.pop
88
+ @namespace = segments.last
89
+ end
90
+
91
+ def split_reference
92
+ if reference.include?('.')
93
+ split_method_reference
94
+ else
95
+ split_legacy_reference
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sleeping_king_studios/docs/data/see_tags'
4
+
5
+ module SleepingKingStudios::Docs::Data::SeeTags
6
+ # Data object representing a @see tag with a constant link.
7
+ class ConstantTag < SleepingKingStudios::Docs::Data::SeeTags::NamespaceItemTag
8
+ DEFINITION_PREFIX =
9
+ '(::)?[[:upper:]][[:alnum:]]*(::[[:upper:]][[:alnum:]]*)*'
10
+ private_constant :DEFINITION_PREFIX
11
+
12
+ CONSTANT_PATTERN =
13
+ /\A((#{DEFINITION_PREFIX})?::)?[[:upper:]]([[[:upper:]][[:digit:]]_])*\z/
14
+
15
+ private_constant :CONSTANT_PATTERN
16
+
17
+ class << self
18
+ # Checks if the given tag object is a reference to a constant.
19
+ #
20
+ # @param native [YARD::Tags::Tag] the tag object.
21
+ #
22
+ # @return [true, false] true if the tag object is a reference; otherwise
23
+ # false.
24
+ def match?(native)
25
+ native.name.sub(/\.\z/, '').match?(CONSTANT_PATTERN)
26
+ end
27
+ alias matches? match?
28
+ end
29
+
30
+ # @return [String] the label used to generate the reference link.
31
+ def reference
32
+ @reference ||= super.sub(/\A::/, '')
33
+ end
34
+ alias label reference
35
+
36
+ # @return [String] the reference type.
37
+ def type
38
+ 'constant'
39
+ end
40
+
41
+ private
42
+
43
+ def query_registry(name)
44
+ registry_query.constant_exists?(name)
45
+ end
46
+
47
+ def relative_path?
48
+ return @relative_path = false if native.name.start_with?('::')
49
+
50
+ super
51
+ end
52
+
53
+ def split_reference
54
+ scoped = relative_path? ? qualified_path : reference
55
+ segments = scoped.split('::')
56
+ @reference_name = segments.pop
57
+ @namespace = segments.join('::')
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sleeping_king_studios/docs/data/see_tags'
4
+
5
+ module SleepingKingStudios::Docs::Data::SeeTags
6
+ # Data object representing a @see tag with a definition link.
7
+ class DefinitionTag < SleepingKingStudios::Docs::Data::SeeTags::ReferenceTag
8
+ DEFINITION_PATTERN =
9
+ /\A(::)?[[:upper:]][[:alnum:]]*(::[[:upper:]][[:alnum:]]*)*\z/
10
+ private_constant :DEFINITION_PATTERN
11
+
12
+ class << self
13
+ # Checks if the given tag object is a reference to a class or module.
14
+ #
15
+ # @param native [YARD::Tags::Tag] the tag object.
16
+ #
17
+ # @return [true, false] true if the tag object is a reference; otherwise
18
+ # false.
19
+ def match?(native)
20
+ native.name.sub(/\.\z/, '').match?(DEFINITION_PATTERN)
21
+ end
22
+ alias matches? match?
23
+ end
24
+
25
+ # @return [String, nil] the path used to generate the reference link.
26
+ def path
27
+ return slugify_path(qualified_path) if relative_path?
28
+
29
+ return slugify_path(reference) if absolute_path?
30
+
31
+ nil
32
+ end
33
+
34
+ # @return [String] the label used to generate the reference link.
35
+ def reference
36
+ @reference ||= super.sub(/\A::/, '')
37
+ end
38
+ alias label reference
39
+
40
+ private
41
+
42
+ def query_registry(name)
43
+ registry_query.definition_exists?(name)
44
+ end
45
+
46
+ def relative_path?
47
+ return false if native.name.start_with?('::')
48
+
49
+ super
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sleeping_king_studios/docs/data/see_tags'
4
+
5
+ module SleepingKingStudios::Docs::Data::SeeTags
6
+ # Data object representing a @see tag with an instance method link.
7
+ class InstanceMethodTag < SleepingKingStudios::Docs::Data::SeeTags::NamespaceItemTag # rubocop:disable Layout/LineLength
8
+ DEFINITION_PREFIX =
9
+ '(::)?[[:upper:]][[:alnum:]]*(::[[:upper:]][[:alnum:]]*)*'
10
+ private_constant :DEFINITION_PREFIX
11
+
12
+ METHOD_SUFFIX =
13
+ '([[[:lower:]][[:digit:]]_\+\-\*\/\[\]\<\>])+[=?]'
14
+ private_constant :METHOD_SUFFIX
15
+
16
+ INSTANCE_METHOD_PATTERN =
17
+ /\A(#{DEFINITION_PREFIX})?##{METHOD_SUFFIX}?\z/
18
+ private_constant :INSTANCE_METHOD_PATTERN
19
+
20
+ class << self
21
+ # Checks if the given tag object is a reference to an instance method.
22
+ #
23
+ # @param native [YARD::Tags::Tag] the tag object.
24
+ #
25
+ # @return [true, false] true if the tag object is a reference; otherwise
26
+ # false.
27
+ def match?(native)
28
+ native.name.sub(/\.\z/, '').match?(INSTANCE_METHOD_PATTERN)
29
+ end
30
+ alias matches? match?
31
+ end
32
+
33
+ # @return [true, false] true if the referenced class method is an attribute;
34
+ # otherwise false.
35
+ def attribute?
36
+ return @attribute unless @attribute.nil?
37
+
38
+ return @attribute = false unless exists?
39
+
40
+ method_path = absolute_path? ? reference : qualified_path
41
+
42
+ native_method = registry.find do |obj|
43
+ obj.type == :method &&
44
+ obj.scope == :instance &&
45
+ obj.path == method_path
46
+ end
47
+
48
+ @attribute = native_method.is_attribute?
49
+ end
50
+
51
+ # @return [String] the reference type.
52
+ def type
53
+ attribute? ? 'instance-attribute' : 'instance-method'
54
+ end
55
+
56
+ private
57
+
58
+ def query_registry(name)
59
+ registry_query.instance_method_exists?(name)
60
+ end
61
+
62
+ def split_reference
63
+ scoped = relative_path? ? qualified_path : reference
64
+ segments = scoped.split('#')
65
+ @reference_name = segments.pop
66
+ @namespace = segments.last
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sleeping_king_studios/docs/data/see_tags'
4
+
5
+ module SleepingKingStudios::Docs::Data::SeeTags
6
+ # Data object representing a @see tag with a link.
7
+ class LinkTag < SleepingKingStudios::Docs::Data::SeeTags::Base
8
+ # Pattern used to match external links. YARD seems to use the presence of a
9
+ # protocol to identify a link, so "http://foo" is a valid link, but
10
+ # "www.example.com" is not.
11
+ LINK_PATTERN = %r{\A\w+://\w+}
12
+ private_constant :LINK_PATTERN
13
+
14
+ class << self
15
+ # Checks if the given tag object is a link.
16
+ #
17
+ # @param native [YARD::Tags::Tag] the tag object.
18
+ #
19
+ # @return [true, false] true if the tag object is a link; otherwise false.
20
+ def match?(native)
21
+ native.name.match?(LINK_PATTERN)
22
+ end
23
+ alias matches? match?
24
+ end
25
+
26
+ # Generates a JSON-compatible representation of the tag.
27
+ #
28
+ # Returns a Hash with the following keys:
29
+ #
30
+ # - 'label': The label used to generate the link.
31
+ # - 'path': The path used to generate the link.
32
+ # - 'text': The text to display for the tag.
33
+ # - 'type': The string 'link'.
34
+ def as_json
35
+ {
36
+ 'label' => label,
37
+ 'path' => path,
38
+ 'text' => text,
39
+ 'type' => 'link'
40
+ }
41
+ end
42
+
43
+ # @return [String] the label used to generate the link.
44
+ def label
45
+ path
46
+ end
47
+
48
+ # @return [String] the path used to generate the link.
49
+ def path
50
+ @path ||= native.name.sub(/\.\z/, '')
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sleeping_king_studios/docs/data/see_tags'
4
+
5
+ module SleepingKingStudios::Docs::Data::SeeTags
6
+ # Data object representing a @see tag with a constant or method link.
7
+ #
8
+ # @abstract
9
+ class NamespaceItemTag < SleepingKingStudios::Docs::Data::SeeTags::ReferenceTag # rubocop:disable Layout/LineLength
10
+ # (see SleepingKingStudios::Docs::Data::SeeTags::Base#initialize)
11
+ def initialize(native:, parent:)
12
+ super
13
+
14
+ split_reference
15
+ end
16
+
17
+ # @return [true, false] true if the constant is defined by the tagged
18
+ # object; otherwise false.
19
+ def local?
20
+ return @local unless @local.nil?
21
+
22
+ @local = namespace == parent.name.to_s
23
+ end
24
+
25
+ # @return [String, nil] the path used to generate the reference link.
26
+ def path
27
+ return "##{type}-#{slugify(reference_name)}" if local?
28
+
29
+ return "#{namespace_path}##{type}-#{slugify(reference_name)}" if exists?
30
+
31
+ nil
32
+ end
33
+
34
+ # @return [String] the reference type.
35
+ def type
36
+ 'reference'
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader \
42
+ :namespace,
43
+ :reference_name
44
+
45
+ def namespace_path
46
+ return '/' if namespace.empty?
47
+
48
+ slugify_path(namespace)
49
+ end
50
+
51
+ def split_reference
52
+ @namespace = ''
53
+ @reference_name = ''
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sleeping_king_studios/docs/data/see_tags'
4
+
5
+ module SleepingKingStudios::Docs::Data::SeeTags
6
+ # Data object representing a @see tag with a reference link.
7
+ #
8
+ # @abstract
9
+ class ReferenceTag < SleepingKingStudios::Docs::Data::SeeTags::Base
10
+ SEPARATORS = ['::', '.', '#'].freeze
11
+ private_constant :SEPARATORS
12
+
13
+ # Generates a JSON-compatible representation of the tag.
14
+ #
15
+ # Returns a Hash with the following keys:
16
+ #
17
+ # - 'label': The label used to generate the reference link.
18
+ # - 'path': The path used to generate the reference link.
19
+ # - 'text': The text to display for the tag.
20
+ # - 'type': The string 'reference'.
21
+ def as_json
22
+ {
23
+ 'label' => label,
24
+ 'path' => path,
25
+ 'text' => text,
26
+ 'type' => 'reference'
27
+ }
28
+ end
29
+
30
+ # Checks if the referenced code object exists in the registry.
31
+ #
32
+ # @return [true, false] true if the referenced code object exists; otherwise
33
+ # false.
34
+ def exists?
35
+ relative_path? || absolute_path?
36
+ end
37
+
38
+ # @return [String, nil] the path used to generate the reference link.
39
+ def path
40
+ nil
41
+ end
42
+
43
+ # @return [String] the label used to generate the reference link.
44
+ def reference
45
+ @reference ||= native.name.sub(/\.\z/, '')
46
+ end
47
+ alias label reference
48
+
49
+ private
50
+
51
+ def absolute_path?
52
+ return @absolute_path unless @absolute_path.nil?
53
+
54
+ @absolute_path = query_registry(reference)
55
+ end
56
+
57
+ def query_registry(_)
58
+ false
59
+ end
60
+
61
+ def registry_query
62
+ @registry_query ||=
63
+ SleepingKingStudios::Docs::RegistryQuery.new(registry:)
64
+ end
65
+
66
+ def qualified_path
67
+ return @qualified_path if @qualified_path
68
+
69
+ if SEPARATORS.any? { |sep| reference.start_with?(sep) }
70
+ return @qualified_path = "#{parent.path}#{reference}"
71
+ end
72
+
73
+ @qualified_path = "#{parent.path}::#{reference}"
74
+ end
75
+
76
+ def relative_path?
77
+ return @relative_path unless @relative_path.nil?
78
+
79
+ return @relative_path = false if parent.root?
80
+
81
+ @relative_path = query_registry(qualified_path)
82
+ end
83
+
84
+ def slugify_path(path)
85
+ path
86
+ .sub(/\A::/, '')
87
+ .split('::')
88
+ .map { |str| slugify(str) }
89
+ .join('/')
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sleeping_king_studios/docs/data/see_tags'
4
+
5
+ module SleepingKingStudios::Docs::Data::SeeTags
6
+ # Data object representing a plain text @see tag.
7
+ class TextTag < SleepingKingStudios::Docs::Data::SeeTags::Base
8
+ class << self
9
+ # Checks if the given tag object is plain text.
10
+ #
11
+ # @param native [YARD::Tags::Tag] the tag object.
12
+ #
13
+ # @return [true, false] true if the tag object is plain text; otherwise
14
+ # false.
15
+ def match?(native)
16
+ native.name == '_'
17
+ end
18
+ alias matches? match?
19
+ end
20
+
21
+ # Generates a JSON-compatible representation of the tag.
22
+ #
23
+ # Returns a Hash with the following keys:
24
+ #
25
+ # - 'text': The text to display for the tag.
26
+ def as_json
27
+ { 'text' => text }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sleeping_king_studios/docs/data/see_tags'
4
+
5
+ module SleepingKingStudios::Docs::Data::SeeTags
6
+ # Data object representing an unstructured @see tag.
7
+ class UnstructuredTag < SleepingKingStudios::Docs::Data::SeeTags::Base
8
+ class << self
9
+ # @overload match?(native)
10
+ # Always returns true.
11
+ #
12
+ # @param native [YARD::Tags::Tag] the tag object.
13
+ #
14
+ # @return [true] true for all tags.
15
+ def match?(_native)
16
+ true
17
+ end
18
+ alias matches? match?
19
+ end
20
+
21
+ # Generates a JSON-compatible representation of the tag.
22
+ #
23
+ # Returns a Hash with the following keys:
24
+ #
25
+ # - 'text': The text to display for the tag.
26
+ def as_json
27
+ { 'text' => text }
28
+ end
29
+
30
+ # The text to display when rendering the tag.
31
+ #
32
+ # @return [String] the text to display.
33
+ def text
34
+ @text ||= "#{native.name} #{native.text}".strip
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sleeping_king_studios/docs/data'
4
+
5
+ module SleepingKingStudios::Docs::Data
6
+ # Namespace for objects representing YARD @see tags.
7
+ module SeeTags
8
+ autoload :Base,
9
+ 'sleeping_king_studios/docs/data/see_tags/base'
10
+ autoload :ClassMethodTag,
11
+ 'sleeping_king_studios/docs/data/see_tags/class_method_tag'
12
+ autoload :ConstantTag,
13
+ 'sleeping_king_studios/docs/data/see_tags/constant_tag'
14
+ autoload :DefinitionTag,
15
+ 'sleeping_king_studios/docs/data/see_tags/definition_tag'
16
+ autoload :InstanceMethodTag,
17
+ 'sleeping_king_studios/docs/data/see_tags/instance_method_tag'
18
+ autoload :LinkTag,
19
+ 'sleeping_king_studios/docs/data/see_tags/link_tag'
20
+ autoload :NamespaceItemTag,
21
+ 'sleeping_king_studios/docs/data/see_tags/namespace_item_tag'
22
+ autoload :ReferenceTag,
23
+ 'sleeping_king_studios/docs/data/see_tags/reference_tag'
24
+ autoload :TextTag,
25
+ 'sleeping_king_studios/docs/data/see_tags/text_tag'
26
+ autoload :UnstructuredTag,
27
+ 'sleeping_king_studios/docs/data/see_tags/unstructured_tag'
28
+
29
+ class << self
30
+ # Creates a wrapper object for the given @see tag.
31
+ #
32
+ # @param native [YARD::Tags::Tag] the YARD object representing the @see
33
+ # tag.
34
+ # @param parent [YARD::Tags::Tag] the YARD object representing the parent
35
+ # object, which contains the @see tag.
36
+ #
37
+ # @return [SleepingKingStudios::Docs::Data::SeeTags::Base] the wrapped
38
+ # object representing the @see tag.
39
+ def build(native:, parent:)
40
+ build_text_tag(native:, parent:) ||
41
+ build_link_tag(native:, parent:) ||
42
+ build_constant_tag(native:, parent:) ||
43
+ build_class_method_tag(native:, parent:) ||
44
+ build_definition_tag(native:, parent:) ||
45
+ build_instance_method_tag(native:, parent:) ||
46
+ build_unstructured_tag(native:, parent:)
47
+ end
48
+
49
+ private
50
+
51
+ def build_class_method_tag(native:, parent:)
52
+ return unless ClassMethodTag.match?(native)
53
+
54
+ ClassMethodTag.new(native:, parent:)
55
+ end
56
+
57
+ def build_constant_tag(native:, parent:)
58
+ return unless ConstantTag.match?(native)
59
+
60
+ # Special check for ambiguous definitions, e.g. HTTP, NASA.
61
+ constant_tag = ConstantTag.new(native:, parent:)
62
+
63
+ return constant_tag if constant_tag.exists?
64
+
65
+ definition_tag = DefinitionTag.new(native:, parent:)
66
+
67
+ # If neither the constant nor the definition exists, and the format
68
+ # matches a constant, assume it is a constant.
69
+ definition_tag.exists? ? definition_tag : constant_tag
70
+ end
71
+
72
+ def build_definition_tag(native:, parent:)
73
+ return unless DefinitionTag.match?(native)
74
+
75
+ DefinitionTag.new(native:, parent:)
76
+ end
77
+
78
+ def build_link_tag(native:, parent:)
79
+ return unless LinkTag.match?(native)
80
+
81
+ LinkTag.new(native:, parent:)
82
+ end
83
+
84
+ def build_instance_method_tag(native:, parent:)
85
+ return unless InstanceMethodTag.match?(native)
86
+
87
+ InstanceMethodTag.new(native:, parent:)
88
+ end
89
+
90
+ def build_text_tag(native:, parent:)
91
+ return unless TextTag.match?(native)
92
+
93
+ TextTag.new(native:, parent:)
94
+ end
95
+
96
+ def build_unstructured_tag(native:, parent:)
97
+ UnstructuredTag.new(native:, parent:)
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,49 @@
1
+ grammar TypesSpecifierList
2
+ rule type_list
3
+ type ',\s+'r type_list / type
4
+ end
5
+
6
+ rule type
7
+ parameterized_type / ordered_type / key_value_type / identifier_with_whitespace
8
+ end
9
+
10
+ # Parameterized types.
11
+
12
+ rule key_value_type
13
+ identifier_with_whitespace '{' type_list '\s*=>\s*'r type_list '}'
14
+ end
15
+
16
+ rule ordered_type
17
+ identifier_with_whitespace '<(' type_list ')>'
18
+ end
19
+
20
+ rule parameterized_type
21
+ identifier_with_whitespace '<' type_list '>'
22
+ end
23
+
24
+ # Identifiers.
25
+
26
+ rule identifier_with_whitespace
27
+ '\s*'r identifier '\s*'r
28
+ end
29
+
30
+ rule identifier
31
+ class_method / instance_method / literal
32
+ end
33
+
34
+ rule class_method
35
+ '.' method_name
36
+ end
37
+
38
+ rule instance_method
39
+ '#' method_name
40
+ end
41
+
42
+ rule literal
43
+ '[^#\. ,=\<\>\(\)\{\}]+'r
44
+ end
45
+
46
+ rule method_name
47
+ literal / '<<' / '<=>' / '<=' / '<' / '===' / '==' / '>=' / '>>' / '>'
48
+ end
49
+ end