Skip to content

Commit

Permalink
Make the new features as configurable options.
Browse files Browse the repository at this point in the history
  • Loading branch information
andersio committed Apr 16, 2017
1 parent d0d0063 commit 1208a44
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
20 changes: 20 additions & 0 deletions lib/jazzy/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ def expand_path(path)
'https://github.com/realm/realm-cocoa/tree/v0.87.1)'

# ──────── Doc generation options ────────
config_attr :extension_constraints_as_mark,
command_line: '--extension-constraints',
description: 'Treat extension constraints as `MARK: `.',
default: true

config_attr :collapse_extensions,
command_line: '--collapse-extensions',
description: 'Collapse consecutive extensions of the same constraint.',
default: true

config_attr :specialize_reactive_extensions,
command_line: '--reactive-extensions',
description: 'Specialize reactive extensions, instead of having an umbrella `Reactive` entry.',
default: true

config_attr :collapse_signal_protocols,
command_line: '--collapse-signal-protocols',
description: 'Collapse `SignalProtocol` and `SignalProducerProtocol` into the concrete types.',
default: true

config_attr :disable_search,
command_line: '--disable-search',
description: ['Avoid generating a search index. '\
Expand Down
22 changes: 15 additions & 7 deletions lib/jazzy/sourcekitten.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ def self.make_source_declarations(docs, parent = nil, extension_mark = nil)
if declaration.type.mark?
mark = SourceMark.new(doc['key.name'])

if matches = /RAC\_EXTENSION\s([a-zA-Z0-9]+)\sSTART/.match(mark.name)
if Config.instance.extension_constraints_as_mark &&
matches = /RAC\_EXTENSION\s([a-zA-Z0-9]+)\sSTART/.match(mark.name)
rac_extension_base = matches[1]
next
elsif rac_extension_base &&
Expand Down Expand Up @@ -437,15 +438,16 @@ def self.make_source_declarations(docs, parent = nil, extension_mark = nil)

#results = /where\sBase\s?\:\s?([a-zA-Z0-9]+)\s?/.match(constraint)
if matches = /where(.+)\{/.match(bytes)
if doc['key.name'] == 'Reactive' &&
if Config.instance.specialize_reactive_extensions &&
doc['key.name'] == 'Reactive' &&
base_matches = /Base\s?\:\s?([a-zA-Z0-9]+)/.match(matches[1])
declaration.type = SourceDeclaration::Type.new('source.lang.swift.decl.reactivecocoaextension')
declaration.name = base_matches[1]
declaration.typename = 'Reactive<' + base_matches[1] + '>.Type'
else
elsif Config.instance.extension_constraints_as_mark
extension_mark = SourceMark.new(matches[1].strip, true)
end
else
elsif Config.instance.extension_constraints_as_mark
extension_mark = SourceMark.new('', true)
end
end
Expand Down Expand Up @@ -523,9 +525,11 @@ def self.mergeable_objc?(decl, root_decls)
def self.deduplication_key(decl, root_decls)
if decl.type.swift_extensible? || decl.type.swift_extension?
# Collapse the signal protocols into the concrete type.
if decl.name == 'Signal' || decl.name == 'SignalProtocol'
if (decl.name == 'Signal' || decl.name == 'SignalProtocol') &&
Config.instance.collapse_signal_protocols
['ras.Signal']
elsif decl.name == 'SignalProducer' || decl.name == 'SignalProducerProtocol'
elsif (decl.name == 'SignalProducer' || decl.name == 'SignalProducerProtocol') &&
Config.instance.collapse_signal_protocols
['ras.SignalProducer']
else
[decl.usr, decl.name]
Expand All @@ -543,7 +547,11 @@ def self.deduplication_key(decl, root_decls)
def self.merge_declarations(decls)
extensions, typedecls = decls.partition { |d| d.type.extension? }

collapsing_signal_protocol = typedecls.any? { |decl| decl.name == 'SignalProtocol' || decl.name == 'SignalProducerProtocol' }
collapsing_signal_protocol = false

if Config.instance.collapse_signal_protocols
collapsing_signal_protocol = typedecls.any? { |decl| decl.name == 'SignalProtocol' || decl.name == 'SignalProducerProtocol' }
end

if !collapsing_signal_protocol && typedecls.size > 1
unless typedecls.all? { |decl| decl.type.reactivecocoa_extension? }
Expand Down

0 comments on commit 1208a44

Please sign in to comment.