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.
14 15 16 |
# File 'lib/jazzy/source_declaration/type.rb', line 14 def kind @kind end |
Class Method Details
.all ⇒ Object
10 11 12 |
# File 'lib/jazzy/source_declaration/type.rb', line 10 def self.all TYPES.keys.map { |k| new(k) }.reject { |t| t.name.nil? } end |
.markdown ⇒ Object
179 180 181 |
# File 'lib/jazzy/source_declaration/type.rb', line 179 def self.markdown Type.new(MARKDOWN_KIND) end |
.overview ⇒ Object
169 170 171 |
# File 'lib/jazzy/source_declaration/type.rb', line 169 def self.overview Type.new(OVERVIEW_KIND) end |
Instance Method Details
#==(other) ⇒ Object
192 193 194 |
# File 'lib/jazzy/source_declaration/type.rb', line 192 def ==(other) other && kind == other.kind end |
#dash_type ⇒ Object
34 35 36 |
# File 'lib/jazzy/source_declaration/type.rb', line 34 def dash_type @type && @type[:dash] end |
#declaration? ⇒ Boolean
118 119 120 121 |
# File 'lib/jazzy/source_declaration/type.rb', line 118 def declaration? kind.start_with?('source.lang.swift.decl', 'sourcekitten.source.lang.objc.decl') end |
#equals ⇒ Object
191 |
# File 'lib/jazzy/source_declaration/type.rb', line 191 alias equals == |
#extension? ⇒ Boolean
123 124 125 |
# File 'lib/jazzy/source_declaration/type.rb', line 123 def extension? swift_extension? || objc_category? end |
#fixup_kind(kind, declaration) ⇒ Object
Improve kind from full declaration
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jazzy/source_declaration/type.rb', line 23 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
155 156 157 |
# File 'lib/jazzy/source_declaration/type.rb', line 155 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
44 45 46 |
# File 'lib/jazzy/source_declaration/type.rb', line 44 def global? @type && @type[:global] end |
#hash ⇒ Object
187 188 189 |
# File 'lib/jazzy/source_declaration/type.rb', line 187 def hash kind.hash end |
#mark? ⇒ Boolean
77 78 79 |
# File 'lib/jazzy/source_declaration/type.rb', line 77 def mark? objc_mark? || swift_mark? end |
#markdown? ⇒ Boolean
183 184 185 |
# File 'lib/jazzy/source_declaration/type.rb', line 183 def markdown? kind == MARKDOWN_KIND end |
#name ⇒ Object
38 39 40 |
# File 'lib/jazzy/source_declaration/type.rb', line 38 def name @type && @type[:jazzy] end |
#name_controlled_manually? ⇒ Boolean
53 54 55 56 57 58 |
# File 'lib/jazzy/source_declaration/type.rb', line 53 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
94 95 96 |
# File 'lib/jazzy/source_declaration/type.rb', line 94 def objc_category? kind == 'sourcekitten.source.lang.objc.decl.category' end |
#objc_class? ⇒ Boolean
98 99 100 |
# File 'lib/jazzy/source_declaration/type.rb', line 98 def objc_class? kind == 'sourcekitten.source.lang.objc.decl.class' end |
#objc_enum? ⇒ Boolean
86 87 88 |
# File 'lib/jazzy/source_declaration/type.rb', line 86 def objc_enum? kind == 'sourcekitten.source.lang.objc.decl.enum' end |
#objc_mark? ⇒ Boolean
68 69 70 |
# File 'lib/jazzy/source_declaration/type.rb', line 68 def objc_mark? kind == 'sourcekitten.source.lang.objc.mark' end |
#objc_typedef? ⇒ Boolean
90 91 92 |
# File 'lib/jazzy/source_declaration/type.rb', line 90 def objc_typedef? kind == 'sourcekitten.source.lang.objc.decl.typedef' end |
#objc_unexposed? ⇒ Boolean
163 164 165 |
# File 'lib/jazzy/source_declaration/type.rb', line 163 def objc_unexposed? kind == 'sourcekitten.source.lang.objc.decl.unexposed' end |
#overview? ⇒ Boolean
173 174 175 |
# File 'lib/jazzy/source_declaration/type.rb', line 173 def overview? kind == OVERVIEW_KIND end |
#param? ⇒ Boolean
148 149 150 151 152 153 |
# File 'lib/jazzy/source_declaration/type.rb', line 148 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
60 61 62 |
# File 'lib/jazzy/source_declaration/type.rb', line 60 def plural_name name.pluralize end |
#plural_url_name ⇒ Object
64 65 66 |
# File 'lib/jazzy/source_declaration/type.rb', line 64 def plural_url_name url_name.pluralize end |
#should_document? ⇒ Boolean
114 115 116 |
# File 'lib/jazzy/source_declaration/type.rb', line 114 def should_document? declaration? && !param? && !generic_type_param? end |
#swift_enum_case? ⇒ Boolean
106 107 108 |
# File 'lib/jazzy/source_declaration/type.rb', line 106 def swift_enum_case? kind == 'source.lang.swift.decl.enumcase' end |
#swift_enum_element? ⇒ Boolean
110 111 112 |
# File 'lib/jazzy/source_declaration/type.rb', line 110 def swift_enum_element? kind == 'source.lang.swift.decl.enumelement' end |
#swift_extensible? ⇒ Boolean
131 132 133 134 |
# File 'lib/jazzy/source_declaration/type.rb', line 131 def swift_extensible? kind =~ /^source\.lang\.swift\.decl\.(class|struct|protocol|enum|actor)$/ end |
#swift_extension? ⇒ Boolean
127 128 129 |
# File 'lib/jazzy/source_declaration/type.rb', line 127 def swift_extension? kind =~ /^source\.lang\.swift\.decl\.extension.*/ end |
#swift_global_function? ⇒ Boolean
144 145 146 |
# File 'lib/jazzy/source_declaration/type.rb', line 144 def swift_global_function? kind == 'source.lang.swift.decl.function.free' end |
#swift_mark? ⇒ Boolean
covers MARK: TODO: FIXME: comments
73 74 75 |
# File 'lib/jazzy/source_declaration/type.rb', line 73 def swift_mark? kind == 'source.lang.swift.syntaxtype.comment.mark' end |
#swift_protocol? ⇒ Boolean
136 137 138 |
# File 'lib/jazzy/source_declaration/type.rb', line 136 def swift_protocol? kind == 'source.lang.swift.decl.protocol' end |
#swift_type? ⇒ Boolean
102 103 104 |
# File 'lib/jazzy/source_declaration/type.rb', line 102 def swift_type? kind.include? 'swift' end |
#swift_typealias? ⇒ Boolean
140 141 142 |
# File 'lib/jazzy/source_declaration/type.rb', line 140 def swift_typealias? kind == 'source.lang.swift.decl.typealias' end |
#swift_variable? ⇒ Boolean
159 160 161 |
# File 'lib/jazzy/source_declaration/type.rb', line 159 def swift_variable? kind.start_with?('source.lang.swift.decl.var') end |
#task_mark?(name) ⇒ Boolean
mark that should start a new task section
82 83 84 |
# File 'lib/jazzy/source_declaration/type.rb', line 82 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
49 50 51 |
# File 'lib/jazzy/source_declaration/type.rb', line 49 def url_name @type && (@type[:url] || @type[:jazzy]) end |