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
- OVERVIEW_KIND =
'Overview'- MARKDOWN_KIND =
'document.markdown'- TYPES =
{ # Markdown MARKDOWN_KIND => { jazzy: 'Guide', dash: 'Guide', }.freeze, # Group/Overview OVERVIEW_KIND => { 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, 'source.lang.swift.decl.macro' => { jazzy: 'Macro', dash: 'Macro', }.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
- #overview? ⇒ 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.
15 16 17 |
# File 'lib/jazzy/source_declaration/type.rb', line 15 def kind @kind end |
Class Method Details
.all ⇒ Object
11 12 13 |
# File 'lib/jazzy/source_declaration/type.rb', line 11 def self.all TYPES.keys.map { |k| new(k) }.reject { |t| t.name.nil? } end |
.markdown ⇒ Object
180 181 182 |
# File 'lib/jazzy/source_declaration/type.rb', line 180 def self.markdown Type.new(MARKDOWN_KIND) end |
.overview ⇒ Object
170 171 172 |
# File 'lib/jazzy/source_declaration/type.rb', line 170 def self.overview Type.new(OVERVIEW_KIND) end |
Instance Method Details
#==(other) ⇒ Object
193 194 195 |
# File 'lib/jazzy/source_declaration/type.rb', line 193 def ==(other) other && kind == other.kind end |
#dash_type ⇒ Object
35 36 37 |
# File 'lib/jazzy/source_declaration/type.rb', line 35 def dash_type @type && @type[:dash] end |
#declaration? ⇒ Boolean
119 120 121 122 |
# File 'lib/jazzy/source_declaration/type.rb', line 119 def declaration? kind.start_with?('source.lang.swift.decl', 'sourcekitten.source.lang.objc.decl') end |
#equals ⇒ Object
192 |
# File 'lib/jazzy/source_declaration/type.rb', line 192 alias equals == |
#extension? ⇒ Boolean
124 125 126 |
# File 'lib/jazzy/source_declaration/type.rb', line 124 def extension? swift_extension? || objc_category? end |
#fixup_kind(kind, declaration) ⇒ Object
Improve kind from full declaration
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jazzy/source_declaration/type.rb', line 24 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
156 157 158 |
# File 'lib/jazzy/source_declaration/type.rb', line 156 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
45 46 47 |
# File 'lib/jazzy/source_declaration/type.rb', line 45 def global? @type && @type[:global] end |
#hash ⇒ Object
188 189 190 |
# File 'lib/jazzy/source_declaration/type.rb', line 188 def hash kind.hash end |
#mark? ⇒ Boolean
78 79 80 |
# File 'lib/jazzy/source_declaration/type.rb', line 78 def mark? objc_mark? || swift_mark? end |
#markdown? ⇒ Boolean
184 185 186 |
# File 'lib/jazzy/source_declaration/type.rb', line 184 def markdown? kind == MARKDOWN_KIND end |
#name ⇒ Object
39 40 41 |
# File 'lib/jazzy/source_declaration/type.rb', line 39 def name @type && @type[:jazzy] end |
#name_controlled_manually? ⇒ Boolean
54 55 56 57 58 59 |
# File 'lib/jazzy/source_declaration/type.rb', line 54 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
95 96 97 |
# File 'lib/jazzy/source_declaration/type.rb', line 95 def objc_category? kind == 'sourcekitten.source.lang.objc.decl.category' end |
#objc_class? ⇒ Boolean
99 100 101 |
# File 'lib/jazzy/source_declaration/type.rb', line 99 def objc_class? kind == 'sourcekitten.source.lang.objc.decl.class' end |
#objc_enum? ⇒ Boolean
87 88 89 |
# File 'lib/jazzy/source_declaration/type.rb', line 87 def objc_enum? kind == 'sourcekitten.source.lang.objc.decl.enum' end |
#objc_mark? ⇒ Boolean
69 70 71 |
# File 'lib/jazzy/source_declaration/type.rb', line 69 def objc_mark? kind == 'sourcekitten.source.lang.objc.mark' end |
#objc_typedef? ⇒ Boolean
91 92 93 |
# File 'lib/jazzy/source_declaration/type.rb', line 91 def objc_typedef? kind == 'sourcekitten.source.lang.objc.decl.typedef' end |
#objc_unexposed? ⇒ Boolean
164 165 166 |
# File 'lib/jazzy/source_declaration/type.rb', line 164 def objc_unexposed? kind == 'sourcekitten.source.lang.objc.decl.unexposed' end |
#overview? ⇒ Boolean
174 175 176 |
# File 'lib/jazzy/source_declaration/type.rb', line 174 def overview? kind == OVERVIEW_KIND end |
#param? ⇒ Boolean
149 150 151 152 153 154 |
# File 'lib/jazzy/source_declaration/type.rb', line 149 def param? # SourceKit strangely categorizes initializer parameters as local # variables, so both kinds represent a parameter in jazzy. ['source.lang.swift.decl.var.parameter', 'source.lang.swift.decl.var.local'].include?(kind) end |
#plural_name ⇒ Object
61 62 63 |
# File 'lib/jazzy/source_declaration/type.rb', line 61 def plural_name name.pluralize end |
#plural_url_name ⇒ Object
65 66 67 |
# File 'lib/jazzy/source_declaration/type.rb', line 65 def plural_url_name url_name.pluralize end |
#should_document? ⇒ Boolean
115 116 117 |
# File 'lib/jazzy/source_declaration/type.rb', line 115 def should_document? declaration? && !param? && !generic_type_param? end |
#swift_enum_case? ⇒ Boolean
107 108 109 |
# File 'lib/jazzy/source_declaration/type.rb', line 107 def swift_enum_case? kind == 'source.lang.swift.decl.enumcase' end |
#swift_enum_element? ⇒ Boolean
111 112 113 |
# File 'lib/jazzy/source_declaration/type.rb', line 111 def swift_enum_element? kind == 'source.lang.swift.decl.enumelement' end |
#swift_extensible? ⇒ Boolean
132 133 134 135 |
# File 'lib/jazzy/source_declaration/type.rb', line 132 def swift_extensible? kind =~ /^source\.lang\.swift\.decl\.(class|struct|protocol|enum|actor)$/ end |
#swift_extension? ⇒ Boolean
128 129 130 |
# File 'lib/jazzy/source_declaration/type.rb', line 128 def swift_extension? kind =~ /^source\.lang\.swift\.decl\.extension.*/ end |
#swift_global_function? ⇒ Boolean
145 146 147 |
# File 'lib/jazzy/source_declaration/type.rb', line 145 def swift_global_function? kind == 'source.lang.swift.decl.function.free' end |
#swift_mark? ⇒ Boolean
covers MARK: TODO: FIXME: comments
74 75 76 |
# File 'lib/jazzy/source_declaration/type.rb', line 74 def swift_mark? kind == 'source.lang.swift.syntaxtype.comment.mark' end |
#swift_protocol? ⇒ Boolean
137 138 139 |
# File 'lib/jazzy/source_declaration/type.rb', line 137 def swift_protocol? kind == 'source.lang.swift.decl.protocol' end |
#swift_type? ⇒ Boolean
103 104 105 |
# File 'lib/jazzy/source_declaration/type.rb', line 103 def swift_type? kind.include? 'swift' end |
#swift_typealias? ⇒ Boolean
141 142 143 |
# File 'lib/jazzy/source_declaration/type.rb', line 141 def swift_typealias? kind == 'source.lang.swift.decl.typealias' end |
#swift_variable? ⇒ Boolean
160 161 162 |
# File 'lib/jazzy/source_declaration/type.rb', line 160 def swift_variable? kind.start_with?('source.lang.swift.decl.var') end |
#task_mark?(name) ⇒ Boolean
mark that should start a new task section
83 84 85 |
# File 'lib/jazzy/source_declaration/type.rb', line 83 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
50 51 52 |
# File 'lib/jazzy/source_declaration/type.rb', line 50 def url_name @type && (@type[:url] || @type[:jazzy]) end |