Class: Jazzy::SourceDeclaration::Type
- Inherits:
-
Object
- Object
- Jazzy::SourceDeclaration::Type
- Defined in:
- lib/jazzy/source_declaration/type.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- MARKDOWN_KIND =
'document.markdown'
- TYPES =
{ # Markdown MARKDOWN_KIND => { jazzy: 'Guide', dash: 'Guide', }.freeze, 'Overview' => { jazzy: nil, dash: 'Section', }.freeze, # Objective-C 'sourcekitten.source.lang.objc.decl.unexposed' => { jazzy: 'Unexposed', dash: 'Unexposed', }.freeze, 'sourcekitten.source.lang.objc.decl.category' => { jazzy: 'Category', dash: 'Extension', global: true, }.freeze, 'sourcekitten.source.lang.objc.decl.class' => { jazzy: 'Class', dash: 'Class', global: true, }.freeze, 'sourcekitten.source.lang.objc.decl.constant' => { jazzy: 'Constant', dash: 'Constant', global: true, }.freeze, 'sourcekitten.source.lang.objc.decl.enum' => { jazzy: 'Enumeration', url: 'Enum', dash: 'Enum', global: true, }.freeze, 'sourcekitten.source.lang.objc.decl.enumcase' => { jazzy: 'Enumeration Case', dash: 'Case', }.freeze, 'sourcekitten.source.lang.objc.decl.initializer' => { jazzy: 'Initializer', dash: 'Initializer', }.freeze, 'sourcekitten.source.lang.objc.decl.method.class' => { jazzy: 'Class Method', dash: 'Method', }.freeze, 'sourcekitten.source.lang.objc.decl.method.instance' => { jazzy: 'Instance Method', dash: 'Method', }.freeze, 'sourcekitten.source.lang.objc.decl.property' => { jazzy: 'Property', dash: 'Property', }.freeze, 'sourcekitten.source.lang.objc.decl.protocol' => { jazzy: 'Protocol', dash: 'Protocol', global: true, }.freeze, 'sourcekitten.source.lang.objc.decl.typedef' => { jazzy: 'Type Definition', dash: 'Type', global: true, }.freeze, 'sourcekitten.source.lang.objc.mark' => { jazzy: 'Mark', dash: 'Mark', }.freeze, 'sourcekitten.source.lang.objc.decl.function' => { jazzy: 'Function', dash: 'Function', global: true, }.freeze, 'sourcekitten.source.lang.objc.decl.struct' => { jazzy: 'Structure', url: 'Struct', dash: 'Struct', global: true, }.freeze, 'sourcekitten.source.lang.objc.decl.union' => { jazzy: 'Union', dash: 'Union', global: true, }.freeze, 'sourcekitten.source.lang.objc.decl.field' => { jazzy: 'Field', dash: 'Field', }.freeze, 'sourcekitten.source.lang.objc.decl.ivar' => { jazzy: 'Instance Variable', dash: 'Ivar', }.freeze, 'sourcekitten.source.lang.objc.module.import' => { jazzy: 'Module', dash: 'Module', }.freeze, # Swift 'source.lang.swift.decl.actor' => { jazzy: 'Actor', dash: 'Actor', global: true, }.freeze, 'source.lang.swift.decl.function.accessor.address' => { jazzy: 'Addressor', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.accessor.didset' => { jazzy: 'didSet Observer', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.accessor.getter' => { jazzy: 'Getter', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.accessor.mutableaddress' => { jazzy: 'Mutable Addressor', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.accessor.setter' => { jazzy: 'Setter', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.accessor.willset' => { jazzy: 'willSet Observer', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.operator' => { jazzy: 'Operator', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.operator.infix' => { jazzy: 'Infix Operator', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.operator.postfix' => { jazzy: 'Postfix Operator', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.operator.prefix' => { jazzy: 'Prefix Operator', dash: 'Function', }.freeze, 'source.lang.swift.decl.function.method.class' => { jazzy: 'Class Method', dash: 'Method', }.freeze, 'source.lang.swift.decl.var.class' => { jazzy: 'Class Variable', dash: 'Variable', }.freeze, 'source.lang.swift.decl.class' => { jazzy: 'Class', dash: 'Class', global: true, }.freeze, 'source.lang.swift.decl.function.constructor' => { jazzy: 'Initializer', dash: 'Constructor', }.freeze, 'source.lang.swift.decl.function.destructor' => { jazzy: 'Deinitializer', dash: 'Method', }.freeze, 'source.lang.swift.decl.var.global' => { jazzy: 'Global Variable', dash: 'Global', global: true, }.freeze, 'source.lang.swift.decl.enumcase' => { jazzy: 'Enumeration Case', dash: 'Case', }.freeze, 'source.lang.swift.decl.enumelement' => { jazzy: 'Enumeration Element', dash: 'Element', }.freeze, 'source.lang.swift.decl.enum' => { jazzy: 'Enumeration', url: 'Enum', dash: 'Enum', global: true, }.freeze, 'source.lang.swift.decl.extension' => { jazzy: 'Extension', dash: 'Extension', global: true, }.freeze, 'source.lang.swift.decl.extension.class' => { jazzy: 'Class Extension', dash: 'Extension', global: true, }.freeze, 'source.lang.swift.decl.extension.enum' => { jazzy: 'Enumeration Extension', dash: 'Extension', global: true, }.freeze, 'source.lang.swift.decl.extension.protocol' => { jazzy: 'Protocol Extension', dash: 'Extension', global: true, }.freeze, 'source.lang.swift.decl.extension.struct' => { jazzy: 'Structure Extension', dash: 'Extension', global: true, }.freeze, 'source.lang.swift.decl.function.free' => { jazzy: 'Function', dash: 'Function', global: true, }.freeze, 'source.lang.swift.decl.function.method.instance' => { jazzy: 'Instance Method', dash: 'Method', }.freeze, 'source.lang.swift.decl.var.instance' => { jazzy: 'Instance Variable', dash: 'Property', }.freeze, 'source.lang.swift.decl.var.local' => { jazzy: 'Local Variable', dash: 'Variable', }.freeze, 'source.lang.swift.decl.var.parameter' => { jazzy: 'Parameter', dash: 'Parameter', }.freeze, 'source.lang.swift.decl.protocol' => { jazzy: 'Protocol', dash: 'Protocol', global: true, }.freeze, 'source.lang.swift.decl.function.method.static' => { jazzy: 'Static Method', dash: 'Method', }.freeze, 'source.lang.swift.decl.var.static' => { jazzy: 'Static Variable', dash: 'Variable', }.freeze, 'source.lang.swift.decl.struct' => { jazzy: 'Structure', url: 'Struct', dash: 'Struct', global: true, }.freeze, 'source.lang.swift.decl.function.subscript' => { jazzy: 'Subscript', dash: 'Method', }.freeze, 'source.lang.swift.decl.typealias' => { jazzy: 'Type Alias', url: 'Typealias', dash: 'Alias', global: true, }.freeze, 'source.lang.swift.decl.generic_type_param' => { jazzy: 'Generic Type Parameter', dash: 'Parameter', }.freeze, 'source.lang.swift.decl.associatedtype' => { jazzy: 'Associated Type', dash: 'Alias', }.freeze, }.freeze
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #dash_type ⇒ Object
- #declaration? ⇒ Boolean
- #equals ⇒ Object
- #extension? ⇒ Boolean
-
#fixup_kind(kind, declaration) ⇒ Object
Improve kind from full declaration.
- #generic_type_param? ⇒ Boolean
-
#global? ⇒ Boolean
kinds that are ‘global’ and should get their own pages with –separate-global-declarations.
- #hash ⇒ Object
-
#initialize(kind, declaration = nil) ⇒ Type
constructor
A new instance of Type.
- #mark? ⇒ Boolean
- #markdown? ⇒ Boolean
- #name ⇒ Object
- #name_controlled_manually? ⇒ Boolean
- #objc_category? ⇒ Boolean
- #objc_class? ⇒ Boolean
- #objc_enum? ⇒ Boolean
- #objc_mark? ⇒ Boolean
- #objc_typedef? ⇒ Boolean
- #objc_unexposed? ⇒ Boolean
- #param? ⇒ Boolean
- #plural_name ⇒ Object
- #plural_url_name ⇒ Object
- #should_document? ⇒ Boolean
- #swift_enum_case? ⇒ Boolean
- #swift_enum_element? ⇒ Boolean
- #swift_extensible? ⇒ Boolean
- #swift_extension? ⇒ Boolean
- #swift_global_function? ⇒ Boolean
-
#swift_mark? ⇒ Boolean
covers MARK: TODO: FIXME: comments.
- #swift_protocol? ⇒ Boolean
- #swift_type? ⇒ Boolean
- #swift_typealias? ⇒ Boolean
- #swift_variable? ⇒ Boolean
-
#task_mark?(name) ⇒ Boolean
mark that should start a new task section.
-
#url_name ⇒ Object
name to use for type subdirectory in URLs for back-compatibility.
Constructor Details
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
13 14 15 |
# File 'lib/jazzy/source_declaration/type.rb', line 13 def kind @kind end |
Class Method Details
.all ⇒ Object
9 10 11 |
# File 'lib/jazzy/source_declaration/type.rb', line 9 def self.all TYPES.keys.map { |k| new(k) }.reject { |t| t.name.nil? } end |
.markdown ⇒ Object
172 173 174 |
# File 'lib/jazzy/source_declaration/type.rb', line 172 def self.markdown Type.new(MARKDOWN_KIND) end |
Instance Method Details
#==(other) ⇒ Object
185 186 187 |
# File 'lib/jazzy/source_declaration/type.rb', line 185 def ==(other) other && kind == other.kind end |
#dash_type ⇒ Object
33 34 35 |
# File 'lib/jazzy/source_declaration/type.rb', line 33 def dash_type @type && @type[:dash] end |
#declaration? ⇒ Boolean
117 118 119 120 |
# File 'lib/jazzy/source_declaration/type.rb', line 117 def declaration? kind.start_with?('source.lang.swift.decl', 'sourcekitten.source.lang.objc.decl') end |
#equals ⇒ Object
184 |
# File 'lib/jazzy/source_declaration/type.rb', line 184 alias equals == |
#extension? ⇒ Boolean
122 123 124 |
# File 'lib/jazzy/source_declaration/type.rb', line 122 def extension? swift_extension? || objc_category? end |
#fixup_kind(kind, declaration) ⇒ Object
Improve kind from full declaration
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jazzy/source_declaration/type.rb', line 22 def fixup_kind(kind, declaration) if kind == 'source.lang.swift.decl.class' && declaration.include?( '<syntaxtype.keyword>actor</syntaxtype.keyword>', ) 'source.lang.swift.decl.actor' else kind end end |
#generic_type_param? ⇒ Boolean
154 155 156 |
# File 'lib/jazzy/source_declaration/type.rb', line 154 def generic_type_param? kind == 'source.lang.swift.decl.generic_type_param' end |
#global? ⇒ Boolean
kinds that are ‘global’ and should get their own pages with –separate-global-declarations
43 44 45 |
# File 'lib/jazzy/source_declaration/type.rb', line 43 def global? @type && @type[:global] end |
#hash ⇒ Object
180 181 182 |
# File 'lib/jazzy/source_declaration/type.rb', line 180 def hash kind.hash end |
#mark? ⇒ Boolean
76 77 78 |
# File 'lib/jazzy/source_declaration/type.rb', line 76 def mark? objc_mark? || swift_mark? end |
#markdown? ⇒ Boolean
176 177 178 |
# File 'lib/jazzy/source_declaration/type.rb', line 176 def markdown? kind == MARKDOWN_KIND end |
#name ⇒ Object
37 38 39 |
# File 'lib/jazzy/source_declaration/type.rb', line 37 def name @type && @type[:jazzy] end |
#name_controlled_manually? ⇒ Boolean
52 53 54 55 56 57 |
# File 'lib/jazzy/source_declaration/type.rb', line 52 def name_controlled_manually? !kind.start_with?('source') # "'source'.lang..." for Swift # or "'source'kitten.source..." for Objective-C # but not "Overview" for navigation groups. end |
#objc_category? ⇒ Boolean
93 94 95 |
# File 'lib/jazzy/source_declaration/type.rb', line 93 def objc_category? kind == 'sourcekitten.source.lang.objc.decl.category' end |
#objc_class? ⇒ Boolean
97 98 99 |
# File 'lib/jazzy/source_declaration/type.rb', line 97 def objc_class? kind == 'sourcekitten.source.lang.objc.decl.class' end |
#objc_enum? ⇒ Boolean
85 86 87 |
# File 'lib/jazzy/source_declaration/type.rb', line 85 def objc_enum? kind == 'sourcekitten.source.lang.objc.decl.enum' end |
#objc_mark? ⇒ Boolean
67 68 69 |
# File 'lib/jazzy/source_declaration/type.rb', line 67 def objc_mark? kind == 'sourcekitten.source.lang.objc.mark' end |
#objc_typedef? ⇒ Boolean
89 90 91 |
# File 'lib/jazzy/source_declaration/type.rb', line 89 def objc_typedef? kind == 'sourcekitten.source.lang.objc.decl.typedef' end |
#objc_unexposed? ⇒ Boolean
162 163 164 |
# File 'lib/jazzy/source_declaration/type.rb', line 162 def objc_unexposed? kind == 'sourcekitten.source.lang.objc.decl.unexposed' end |
#param? ⇒ Boolean
147 148 149 150 151 152 |
# File 'lib/jazzy/source_declaration/type.rb', line 147 def param? # SourceKit strangely categorizes initializer parameters as local # variables, so both kinds represent a parameter in jazzy. kind == 'source.lang.swift.decl.var.parameter' || kind == 'source.lang.swift.decl.var.local' end |
#plural_name ⇒ Object
59 60 61 |
# File 'lib/jazzy/source_declaration/type.rb', line 59 def plural_name name.pluralize end |
#plural_url_name ⇒ Object
63 64 65 |
# File 'lib/jazzy/source_declaration/type.rb', line 63 def plural_url_name url_name.pluralize end |
#should_document? ⇒ Boolean
113 114 115 |
# File 'lib/jazzy/source_declaration/type.rb', line 113 def should_document? declaration? && !param? && !generic_type_param? end |
#swift_enum_case? ⇒ Boolean
105 106 107 |
# File 'lib/jazzy/source_declaration/type.rb', line 105 def swift_enum_case? kind == 'source.lang.swift.decl.enumcase' end |
#swift_enum_element? ⇒ Boolean
109 110 111 |
# File 'lib/jazzy/source_declaration/type.rb', line 109 def swift_enum_element? kind == 'source.lang.swift.decl.enumelement' end |
#swift_extensible? ⇒ Boolean
130 131 132 133 |
# File 'lib/jazzy/source_declaration/type.rb', line 130 def swift_extensible? kind =~ /^source\.lang\.swift\.decl\.(class|struct|protocol|enum|actor)$/ end |
#swift_extension? ⇒ Boolean
126 127 128 |
# File 'lib/jazzy/source_declaration/type.rb', line 126 def swift_extension? kind =~ /^source\.lang\.swift\.decl\.extension.*/ end |
#swift_global_function? ⇒ Boolean
143 144 145 |
# File 'lib/jazzy/source_declaration/type.rb', line 143 def swift_global_function? kind == 'source.lang.swift.decl.function.free' end |
#swift_mark? ⇒ Boolean
covers MARK: TODO: FIXME: comments
72 73 74 |
# File 'lib/jazzy/source_declaration/type.rb', line 72 def swift_mark? kind == 'source.lang.swift.syntaxtype.comment.mark' end |
#swift_protocol? ⇒ Boolean
135 136 137 |
# File 'lib/jazzy/source_declaration/type.rb', line 135 def swift_protocol? kind == 'source.lang.swift.decl.protocol' end |
#swift_type? ⇒ Boolean
101 102 103 |
# File 'lib/jazzy/source_declaration/type.rb', line 101 def swift_type? kind.include? 'swift' end |
#swift_typealias? ⇒ Boolean
139 140 141 |
# File 'lib/jazzy/source_declaration/type.rb', line 139 def swift_typealias? kind == 'source.lang.swift.decl.typealias' end |
#swift_variable? ⇒ Boolean
158 159 160 |
# File 'lib/jazzy/source_declaration/type.rb', line 158 def swift_variable? kind.start_with?('source.lang.swift.decl.var') end |
#task_mark?(name) ⇒ Boolean
mark that should start a new task section
81 82 83 |
# File 'lib/jazzy/source_declaration/type.rb', line 81 def task_mark?(name) objc_mark? || (swift_mark? && name.start_with?('MARK: ')) end |
#url_name ⇒ Object
name to use for type subdirectory in URLs for back-compatibility
48 49 50 |
# File 'lib/jazzy/source_declaration/type.rb', line 48 def url_name @type && (@type[:url] || @type[:jazzy]) end |