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.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.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
- #generic_type_param? ⇒ Boolean
-
#global? ⇒ Boolean
kinds that are ‘global’ and should get their own pages with –separate-global-declarations.
- #hash ⇒ Object
-
#initialize(kind) ⇒ 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
#initialize(kind) ⇒ Type
Returns a new instance of Type.
15 16 17 18 |
# File 'lib/jazzy/source_declaration/type.rb', line 15 def initialize(kind) @kind = kind @type = TYPES[kind] end |
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
158 159 160 |
# File 'lib/jazzy/source_declaration/type.rb', line 158 def self.markdown Type.new(MARKDOWN_KIND) end |
.overview ⇒ Object
152 153 154 |
# File 'lib/jazzy/source_declaration/type.rb', line 152 def self.overview Type.new('Overview') end |
Instance Method Details
#==(other) ⇒ Object
171 172 173 |
# File 'lib/jazzy/source_declaration/type.rb', line 171 def ==(other) other && kind == other.kind end |
#dash_type ⇒ Object
20 21 22 |
# File 'lib/jazzy/source_declaration/type.rb', line 20 def dash_type @type && @type[:dash] end |
#declaration? ⇒ Boolean
104 105 106 107 |
# File 'lib/jazzy/source_declaration/type.rb', line 104 def declaration? kind.start_with?('source.lang.swift.decl', 'sourcekitten.source.lang.objc.decl') end |
#equals ⇒ Object
170 |
# File 'lib/jazzy/source_declaration/type.rb', line 170 alias equals == |
#extension? ⇒ Boolean
109 110 111 |
# File 'lib/jazzy/source_declaration/type.rb', line 109 def extension? swift_extension? || objc_category? end |
#generic_type_param? ⇒ Boolean
140 141 142 |
# File 'lib/jazzy/source_declaration/type.rb', line 140 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
30 31 32 |
# File 'lib/jazzy/source_declaration/type.rb', line 30 def global? @type && @type[:global] end |
#hash ⇒ Object
166 167 168 |
# File 'lib/jazzy/source_declaration/type.rb', line 166 def hash kind.hash end |
#mark? ⇒ Boolean
63 64 65 |
# File 'lib/jazzy/source_declaration/type.rb', line 63 def mark? objc_mark? || swift_mark? end |
#markdown? ⇒ Boolean
162 163 164 |
# File 'lib/jazzy/source_declaration/type.rb', line 162 def markdown? kind == MARKDOWN_KIND end |
#name ⇒ Object
24 25 26 |
# File 'lib/jazzy/source_declaration/type.rb', line 24 def name @type && @type[:jazzy] end |
#name_controlled_manually? ⇒ Boolean
39 40 41 42 43 44 |
# File 'lib/jazzy/source_declaration/type.rb', line 39 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
80 81 82 |
# File 'lib/jazzy/source_declaration/type.rb', line 80 def objc_category? kind == 'sourcekitten.source.lang.objc.decl.category' end |
#objc_class? ⇒ Boolean
84 85 86 |
# File 'lib/jazzy/source_declaration/type.rb', line 84 def objc_class? kind == 'sourcekitten.source.lang.objc.decl.class' end |
#objc_enum? ⇒ Boolean
72 73 74 |
# File 'lib/jazzy/source_declaration/type.rb', line 72 def objc_enum? kind == 'sourcekitten.source.lang.objc.decl.enum' end |
#objc_mark? ⇒ Boolean
54 55 56 |
# File 'lib/jazzy/source_declaration/type.rb', line 54 def objc_mark? kind == 'sourcekitten.source.lang.objc.mark' end |
#objc_typedef? ⇒ Boolean
76 77 78 |
# File 'lib/jazzy/source_declaration/type.rb', line 76 def objc_typedef? kind == 'sourcekitten.source.lang.objc.decl.typedef' end |
#objc_unexposed? ⇒ Boolean
148 149 150 |
# File 'lib/jazzy/source_declaration/type.rb', line 148 def objc_unexposed? kind == 'sourcekitten.source.lang.objc.decl.unexposed' end |
#param? ⇒ Boolean
133 134 135 136 137 138 |
# File 'lib/jazzy/source_declaration/type.rb', line 133 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
46 47 48 |
# File 'lib/jazzy/source_declaration/type.rb', line 46 def plural_name name.pluralize end |
#plural_url_name ⇒ Object
50 51 52 |
# File 'lib/jazzy/source_declaration/type.rb', line 50 def plural_url_name url_name.pluralize end |
#should_document? ⇒ Boolean
100 101 102 |
# File 'lib/jazzy/source_declaration/type.rb', line 100 def should_document? declaration? && !param? && !generic_type_param? end |
#swift_enum_case? ⇒ Boolean
92 93 94 |
# File 'lib/jazzy/source_declaration/type.rb', line 92 def swift_enum_case? kind == 'source.lang.swift.decl.enumcase' end |
#swift_enum_element? ⇒ Boolean
96 97 98 |
# File 'lib/jazzy/source_declaration/type.rb', line 96 def swift_enum_element? kind == 'source.lang.swift.decl.enumelement' end |
#swift_extensible? ⇒ Boolean
117 118 119 |
# File 'lib/jazzy/source_declaration/type.rb', line 117 def swift_extensible? kind =~ /^source\.lang\.swift\.decl\.(class|struct|protocol|enum)$/ end |
#swift_extension? ⇒ Boolean
113 114 115 |
# File 'lib/jazzy/source_declaration/type.rb', line 113 def swift_extension? kind =~ /^source\.lang\.swift\.decl\.extension.*/ end |
#swift_global_function? ⇒ Boolean
129 130 131 |
# File 'lib/jazzy/source_declaration/type.rb', line 129 def swift_global_function? kind == 'source.lang.swift.decl.function.free' end |
#swift_mark? ⇒ Boolean
covers MARK: TODO: FIXME: comments
59 60 61 |
# File 'lib/jazzy/source_declaration/type.rb', line 59 def swift_mark? kind == 'source.lang.swift.syntaxtype.comment.mark' end |
#swift_protocol? ⇒ Boolean
121 122 123 |
# File 'lib/jazzy/source_declaration/type.rb', line 121 def swift_protocol? kind == 'source.lang.swift.decl.protocol' end |
#swift_type? ⇒ Boolean
88 89 90 |
# File 'lib/jazzy/source_declaration/type.rb', line 88 def swift_type? kind.include? 'swift' end |
#swift_typealias? ⇒ Boolean
125 126 127 |
# File 'lib/jazzy/source_declaration/type.rb', line 125 def swift_typealias? kind == 'source.lang.swift.decl.typealias' end |
#swift_variable? ⇒ Boolean
144 145 146 |
# File 'lib/jazzy/source_declaration/type.rb', line 144 def swift_variable? kind.start_with?('source.lang.swift.decl.var') end |
#task_mark?(name) ⇒ Boolean
mark that should start a new task section
68 69 70 |
# File 'lib/jazzy/source_declaration/type.rb', line 68 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
35 36 37 |
# File 'lib/jazzy/source_declaration/type.rb', line 35 def url_name @type && (@type[:url] || @type[:jazzy]) end |