jazzy 0.9.6 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  Both Swift and Objective-C projects are supported.
10
10
 
11
- *Objective-C support was recently added, so please report any issues you find.*
11
+ *SwiftPM support was recently added, so please report any issues you find.*
12
12
 
13
13
  Instead of parsing your source files, `jazzy` hooks into [Clang][clang] and
14
14
  [SourceKit][sourcekit] to use the [AST][ast] representation of your code and
@@ -23,9 +23,11 @@ unacceptable behavior to [info@realm.io](mailto:info@realm.io).
23
23
 
24
24
  ## Requirements
25
25
 
26
- * A version of [Xcode][xcode] capable of building the project you wish to
27
- document. It must be installed in a location indexed by Spotlight for the
28
- `--swift-version` configuration option to succeed.
26
+ You need development tools to build the project you wish to document. Jazzy supports
27
+ both [Xcode][xcode] and [Swift Package Manager][spm] projects.
28
+
29
+ Jazzy expects to be running on __macOS__. See [below](#linux) for tips to run Jazzy
30
+ on Linux.
29
31
 
30
32
  ## Installation
31
33
 
@@ -41,8 +43,9 @@ common problems.
41
43
  Run `jazzy` from your command line. Run `jazzy -h` for a list of additional options.
42
44
 
43
45
  If your Swift module is the first thing to build, and it builds fine when running
44
- `xcodebuild` without any arguments from the root of your project, then just running
45
- `jazzy` (without any arguments) from the root of your project should succeed too!
46
+ `xcodebuild` or `swift build` without any arguments from the root of your project, then
47
+ just running `jazzy` (without any arguments) from the root of your project should
48
+ succeed too!
46
49
 
47
50
  You can set options for your project’s documentation in a configuration file,
48
51
  `.jazzy.yaml` by default. For a detailed explanation and an exhaustive list of
@@ -83,13 +86,22 @@ jazzy \
83
86
  --github_url https://github.com/realm/realm-cocoa \
84
87
  --github-file-prefix https://github.com/realm/realm-cocoa/tree/v0.96.2 \
85
88
  --module-version 0.96.2 \
86
- --xcodebuild-arguments -scheme,RealmSwift \
89
+ --build-tool-arguments -scheme,RealmSwift \
87
90
  --module RealmSwift \
88
91
  --root-url https://realm.io/docs/swift/0.96.2/api/ \
89
92
  --output docs/swift_output \
90
93
  --theme docs/themes
91
94
  ```
92
95
 
96
+ This is how docs are generated for a project that uses the Swift Package Manager:
97
+
98
+ ```shell
99
+ jazzy \
100
+ --module DeckOfPlayingCards \
101
+ --swift-build-tool spm \
102
+ --build-tool-arguments -Xswiftc,-swift-version,-Xswiftc,5
103
+ ```
104
+
93
105
  ### Objective-C
94
106
 
95
107
  To generate documentation for Objective-C headers, you must pass the following
@@ -116,7 +128,7 @@ jazzy \
116
128
  --github_url https://github.com/realm/realm-cocoa \
117
129
  --github-file-prefix https://github.com/realm/realm-cocoa/tree/v2.2.0 \
118
130
  --module-version 2.2.0 \
119
- --xcodebuild-arguments --objc,Realm/Realm.h,--,-x,objective-c,-isysroot,$(xcrun --show-sdk-path),-I,$(pwd) \
131
+ --build-tool-arguments --objc,Realm/Realm.h,--,-x,objective-c,-isysroot,$(xcrun --show-sdk-path),-I,$(pwd) \
120
132
  --module Realm \
121
133
  --root-url https://realm.io/docs/objc/2.2.0/api/ \
122
134
  --output docs/objc_output \
@@ -138,6 +150,33 @@ jazzy \
138
150
  --module AFNetworking
139
151
  ```
140
152
 
153
+ ### Mixed Objective-C / Swift
154
+
155
+ *This feature is new and has some rough edges.*
156
+
157
+ To generate documentation for a mixed Swift and Objective-C project you must first
158
+ generate two [SourceKitten][sourcekitten] files: one for Swift and one for Objective-C.
159
+
160
+ Then pass these files to Jazzy together using `--sourcekitten-sourcefile`.
161
+
162
+ #### Example
163
+
164
+ This is how docs are generated from an Xcode project for a module containing both
165
+ Swift and Objective-C files:
166
+
167
+ ```shell
168
+ # Generate Swift SourceKitten output
169
+ sourcekitten doc -- -workspace MyProject.xcworkspace -scheme MyScheme > swiftDoc.json
170
+
171
+ # Generate Objective-C SourceKitten output
172
+ sourcekitten doc --objc $(pwd)/MyProject/MyProject.h \
173
+ -- -x objective-c -isysroot $(xcrun --show-sdk-path --sdk iphonesimulator) \
174
+ -I $(pwd) -fmodules > objcDoc.json
175
+
176
+ # Feed both outputs to Jazzy as a comma-separated list
177
+ jazzy --sourcekitten-sourcefile swiftDoc.json,objcDoc.json
178
+ ```
179
+
141
180
  ### Themes
142
181
 
143
182
  Three themes are provided with jazzy: `apple` (default), `fullwidth` and `jony`.
@@ -233,9 +272,27 @@ For example to use Xcode 9.4:
233
272
  jazzy --swift-version 4.1.2
234
273
  ```
235
274
 
275
+ ## Linux
276
+
277
+ Jazzy uses [SourceKitten][sourcekitten] to communicate with the Swift build
278
+ environment and compiler. The `sourcekitten` binary included in the Jazzy gem
279
+ is built for macOS and so does not run on other operating systems.
280
+
281
+ To use Jazzy on Linux you first need to install and build `sourcekitten`
282
+ following instructions from [SourceKitten's GitHub repository][sourcekitten].
283
+
284
+ Then to generate documentation for a SwiftPM project, instead of running just
285
+ `jazzy` do:
286
+ ```shell
287
+ sourcekitten doc --spm > doc.json
288
+ jazzy --sourcekitten-sourcefile doc.json
289
+ ```
290
+
291
+ We hope to improve this process in the future.
292
+
236
293
  ## Troubleshooting
237
294
 
238
- #### Swift
295
+ ### Swift
239
296
 
240
297
  **Only extensions are listed in the documentation?**
241
298
 
@@ -253,7 +310,7 @@ Check the `--min-acl` setting -- see [above](#controlling-what-is-documented).
253
310
  environment variable to point to the Xcode you want before running Jazzy
254
311
  without the `--swift-version` flag.
255
312
 
256
- #### Installation Problems
313
+ ### Installation Problems
257
314
 
258
315
  **Can't find header files / clang**
259
316
 
@@ -268,6 +325,14 @@ The path of your active Xcode installation must not contain spaces. So
268
325
  but `/Applications/Xcode 10.2.app/` is not. This restriction applies only
269
326
  when *installing* Jazzy, not running it.
270
327
 
328
+ ### MacOS Before 10.14.4
329
+
330
+ Starting with Jazzy 0.10.0, if you see an error similar to `dyld: Symbol not found: _$s11SubSequenceSlTl` then you need to install the [Swift 5 Runtime Support for Command Line Tools](https://support.apple.com/kb/DL1998).
331
+
332
+ Alternatively, you can:
333
+ * Update to macOS 10.14.4 or later; or
334
+ * Install Xcode 10.2 or later at `/Applications/Xcode.app`.
335
+
271
336
  ## Development
272
337
 
273
338
  Please review jazzy's [contributing guidelines](https://github.com/realm/jazzy/blob/master/CONTRIBUTING.md) when submitting pull requests.
@@ -293,7 +358,7 @@ Instructions to build SourceKitten from source can be found at
293
358
  - Leverage modern HTML templating ([Mustache][mustache])
294
359
  - Leverage the power and accuracy of the [Clang AST][ast] and [SourceKit][sourcekit]
295
360
  - Support for Dash docsets
296
- - Support Swift and Objective-C (*mixed projects are a work in progress*)
361
+ - Support Swift and Objective-C
297
362
 
298
363
  ## License
299
364
 
@@ -318,3 +383,4 @@ read [our blog](https://realm.io/news) or say hi on twitter
318
383
  [SourceKitten]: https://github.com/jpsim/SourceKitten "SourceKitten"
319
384
  [bundler]: https://rubygems.org/gems/bundler
320
385
  [mustache]: https://mustache.github.io "Mustache"
386
+ [spm]: https://swift.org/package-manager/ "Swift Package Manager"
data/Rakefile CHANGED
@@ -104,7 +104,7 @@ begin
104
104
  task :sourcekitten do
105
105
  sk_dir = 'SourceKitten'
106
106
  Dir.chdir(sk_dir) do
107
- `swift build -c release -Xswiftc -static-stdlib`
107
+ `swift build -c release`
108
108
  end
109
109
  FileUtils.cp_r "#{sk_dir}/.build/release/sourcekitten", 'bin'
110
110
  end
data/bin/sourcekitten CHANGED
Binary file
data/jazzy.gemspec CHANGED
@@ -17,13 +17,13 @@ Gem::Specification.new do |spec|
17
17
  spec.files = `git ls-files`.split($/)
18
18
  spec.executables << 'jazzy'
19
19
 
20
- spec.add_runtime_dependency 'cocoapods', '~> 1.5.3'
21
- spec.add_runtime_dependency 'mustache', '~> 1.1.0'
20
+ spec.add_runtime_dependency 'cocoapods', '~> 1.5'
21
+ spec.add_runtime_dependency 'mustache', '~> 1.1'
22
22
  spec.add_runtime_dependency 'open4'
23
- spec.add_runtime_dependency 'redcarpet', '~> 3.4.0'
23
+ spec.add_runtime_dependency 'redcarpet', '~> 3.4'
24
24
  spec.add_runtime_dependency 'rouge', ['>= 2.0.6', '< 4.0']
25
- spec.add_runtime_dependency 'sass', '~> 3.6.0'
26
- spec.add_runtime_dependency 'sqlite3', '~> 1.3.13'
25
+ spec.add_runtime_dependency 'sassc', '~> 2.1'
26
+ spec.add_runtime_dependency 'sqlite3', '~> 1.3'
27
27
  spec.add_runtime_dependency 'xcinvoke', '~> 0.3.0'
28
28
 
29
29
  spec.add_development_dependency 'bundler', '~> 1.7'
data/lib/jazzy/config.rb CHANGED
@@ -2,7 +2,6 @@ require 'optparse'
2
2
  require 'pathname'
3
3
  require 'uri'
4
4
 
5
- require 'jazzy/doc'
6
5
  require 'jazzy/podspec_documenter'
7
6
  require 'jazzy/source_declaration/access_control_level'
8
7
 
@@ -80,6 +79,14 @@ module Jazzy
80
79
  @all_config_attrs << Attribute.new(name, **opts)
81
80
  end
82
81
 
82
+ def self.alias_config_attr(name, forward, **opts)
83
+ alias_method name.to_s, forward.to_s
84
+ alias_method "#{name}=", "#{forward}="
85
+ alias_method "#{name}_configured", "#{forward}_configured"
86
+ alias_method "#{name}_configured=", "#{forward}_configured="
87
+ @all_config_attrs << Attribute.new(name, **opts)
88
+ end
89
+
83
90
  class << self
84
91
  attr_reader :all_config_attrs
85
92
  end
@@ -95,6 +102,14 @@ module Jazzy
95
102
  Pathname(Dir[abs_path][0] || abs_path) # Use existing filesystem spelling
96
103
  end
97
104
 
105
+ def hide_swift?
106
+ hide_declarations == 'swift'
107
+ end
108
+
109
+ def hide_objc?
110
+ hide_declarations == 'objc'
111
+ end
112
+
98
113
  # ──────── Build ────────
99
114
 
100
115
  # rubocop:disable Layout/AlignParameters
@@ -136,9 +151,9 @@ module Jazzy
136
151
  command_line: '--hide-declarations [objc|swift] ',
137
152
  description: 'Hide declarations in the specified language. Given that ' \
138
153
  'generating Swift docs only generates Swift declarations, ' \
139
- 'this is only really useful to display just the Swift ' \
140
- 'declarations & names when generating docs for an ' \
141
- 'Objective-C framework.',
154
+ 'this is useful for hiding a specific interface for ' \
155
+ 'either Objective-C or mixed Objective-C and Swift ' \
156
+ 'projects.',
142
157
  default: ''
143
158
 
144
159
  config_attr :config_file,
@@ -147,15 +162,21 @@ module Jazzy
147
162
  'Default: .jazzy.yaml in source directory or ancestor'],
148
163
  parse: ->(cf) { expand_path(cf) }
149
164
 
150
- config_attr :xcodebuild_arguments,
151
- command_line: ['-x', '--xcodebuild-arguments arg1,arg2,…argN', Array],
152
- description: 'Arguments to forward to xcodebuild',
165
+ config_attr :build_tool_arguments,
166
+ command_line: ['-b', '--build-tool-arguments arg1,arg2,…argN', Array],
167
+ description: 'Arguments to forward to xcodebuild, swift build, or ' \
168
+ 'sourcekitten.',
153
169
  default: []
154
170
 
171
+ alias_config_attr :xcodebuild_arguments, :build_tool_arguments,
172
+ command_line: ['-x', '--xcodebuild-arguments arg1,arg2,…argN', Array],
173
+ description: 'Back-compatibility alias for build_tool_arguments.'
174
+
155
175
  config_attr :sourcekitten_sourcefile,
156
- command_line: ['-s', '--sourcekitten-sourcefile FILEPATH'],
157
- description: 'File generated from sourcekitten output to parse',
158
- parse: ->(s) { expand_path(s) }
176
+ command_line: ['-s', '--sourcekitten-sourcefile filepath1,…filepathN',
177
+ Array],
178
+ description: 'File(s) generated from sourcekitten output to parse',
179
+ parse: ->(paths) { paths.map { |path| expand_path(path) } }
159
180
 
160
181
  config_attr :source_directory,
161
182
  command_line: '--source-directory DIRPATH',
@@ -193,6 +214,20 @@ module Jazzy
193
214
  end
194
215
  end
195
216
 
217
+ SWIFT_BUILD_TOOLS = %w[spm xcodebuild].freeze
218
+
219
+ config_attr :swift_build_tool,
220
+ command_line: "--swift-build-tool #{SWIFT_BUILD_TOOLS.join(' | ')}",
221
+ description: 'Control whether Jazzy uses Swift Package Manager or '\
222
+ 'xcodebuild to build the module to be documented. By '\
223
+ 'default it uses xcodebuild if there is a .xcodeproj '\
224
+ 'file in the source directory.',
225
+ parse: ->(tool) do
226
+ return tool.to_sym if SWIFT_BUILD_TOOLS.include?(tool)
227
+ raise "Unsupported swift_build_tool #{tool}, "\
228
+ "supported values: #{SWIFT_BUILD_TOOLS.join(', ')}"
229
+ end
230
+
196
231
  # ──────── Metadata ────────
197
232
 
198
233
  config_attr :author_name,
@@ -213,9 +248,16 @@ module Jazzy
213
248
 
214
249
  config_attr :version,
215
250
  command_line: '--module-version VERSION',
216
- description: 'module version. will be used when generating docset',
251
+ description: 'Version string to use as part of the the default docs '\
252
+ 'title and inside the docset.',
217
253
  default: '1.0'
218
254
 
255
+ config_attr :title,
256
+ command_line: '--title TITLE',
257
+ description: 'Title to display at the top of each page, overriding the '\
258
+ 'default generated from module name and version.',
259
+ default: ''
260
+
219
261
  config_attr :copyright,
220
262
  command_line: '--copyright COPYRIGHT_MARKDOWN',
221
263
  description: 'copyright markdown rendered at the bottom of the docs pages'
data/lib/jazzy/doc.rb CHANGED
@@ -8,10 +8,11 @@ require 'jazzy/jazzy_markdown'
8
8
 
9
9
  module Jazzy
10
10
  class Doc < Mustache
11
+ include Config::Mixin
12
+
11
13
  self.template_name = 'doc'
12
14
 
13
15
  def copyright
14
- config = Config.instance
15
16
  copyright = config.copyright || (
16
17
  # Fake date is used to keep integration tests consistent
17
18
  date = ENV['JAZZY_FAKE_DATE'] || DateTime.now.strftime('%Y-%m-%d')
@@ -28,15 +29,27 @@ module Jazzy
28
29
  end
29
30
 
30
31
  def objc_first?
31
- Config.instance.objc_mode && Config.instance.hide_declarations != 'objc'
32
- end
33
-
34
- def language
35
- objc_first? ? 'Objective-C' : 'Swift'
32
+ config.objc_mode && config.hide_declarations != 'objc'
36
33
  end
37
34
 
38
35
  def language_stub
39
36
  objc_first? ? 'objc' : 'swift'
40
37
  end
38
+
39
+ def module_version
40
+ config.version_configured ? config.version : nil
41
+ end
42
+
43
+ def docs_title
44
+ if config.title_configured
45
+ config.title
46
+ elsif config.version_configured
47
+ # Fake version for integration tests
48
+ version = ENV['JAZZY_FAKE_MODULE_VERSION'] || config.version
49
+ "#{config.module_name} #{version} Docs"
50
+ else
51
+ "#{config.module_name} Docs"
52
+ end
53
+ end
41
54
  end
42
55
  end
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'mustache'
3
3
  require 'pathname'
4
- require 'sass'
4
+ require 'sassc'
5
5
 
6
6
  require 'jazzy/config'
7
7
  require 'jazzy/doc'
@@ -53,23 +53,16 @@ module Jazzy
53
53
  # @param [Config] options
54
54
  # @return [SourceModule] the documented source module
55
55
  def self.build(options)
56
- if options.sourcekitten_sourcefile
57
- stdout = options.sourcekitten_sourcefile.read
56
+ if options.sourcekitten_sourcefile_configured
57
+ stdout = '[' + options.sourcekitten_sourcefile.map(&:read)
58
+ .join(',') + ']'
59
+ elsif options.podspec_configured
60
+ pod_documenter = PodspecDocumenter.new(options.podspec)
61
+ stdout = pod_documenter.sourcekitten_output(options)
58
62
  else
59
- if options.podspec_configured
60
- pod_documenter = PodspecDocumenter.new(options.podspec)
61
- stdout = pod_documenter.sourcekitten_output(options)
62
- else
63
- stdout = Dir.chdir(options.source_directory) do
64
- arguments = SourceKitten.arguments_from_options(options)
65
- SourceKitten.run_sourcekitten(arguments)
66
- end
67
- end
68
- unless $?.success?
69
- warn 'Please pass in xcodebuild arguments using -x'
70
- warn 'If build arguments are correct, please file an issue on ' \
71
- 'https://github.com/realm/jazzy/issues'
72
- exit $?.exitstatus || 1
63
+ stdout = Dir.chdir(options.source_directory) do
64
+ arguments = SourceKitten.arguments_from_options(options)
65
+ SourceKitten.run_sourcekitten(arguments)
73
66
  end
74
67
  end
75
68
 
@@ -95,10 +88,9 @@ module Jazzy
95
88
  def self.each_doc(output_dir, docs, &block)
96
89
  docs.each do |doc|
97
90
  next unless doc.render_as_page?
98
- # Assuming URL is relative to documentation root:
99
- path = output_dir + (doc.url || "#{doc.name}.html")
91
+ # Filepath is relative to documentation root:
92
+ path = output_dir + doc.filepath
100
93
  block.call(doc, path)
101
- next if doc.name == 'index'
102
94
  each_doc(
103
95
  output_dir,
104
96
  doc.children,
@@ -198,8 +190,7 @@ module Jazzy
198
190
  assets_directory = Config.instance.theme_directory + 'assets'
199
191
  FileUtils.cp_r(assets_directory.children, destination)
200
192
  Pathname.glob(destination + 'css/**/*.scss').each do |scss|
201
- contents = scss.read
202
- css = Sass::Engine.new(contents, syntax: :scss).render
193
+ css = SassC::Engine.new(scss.read).render
203
194
  css_filename = scss.sub(/\.scss$/, '')
204
195
  css_filename.open('w') { |f| f.write(css) }
205
196
  FileUtils.rm scss
@@ -339,6 +330,7 @@ module Jazzy
339
330
  name: item.name,
340
331
  abstract: abstract,
341
332
  declaration: item.display_declaration,
333
+ language: item.display_language,
342
334
  other_language_declaration: item.display_other_language_declaration,
343
335
  usr: item.usr,
344
336
  dash_type: item.type.dash_type,
@@ -78,7 +78,7 @@ module Jazzy
78
78
  'searchIndex (name, type, path);')
79
79
  source_module.all_declarations.select(&:type).each do |doc|
80
80
  db.execute('INSERT OR IGNORE INTO searchIndex(name, type, path) ' \
81
- 'VALUES (?, ?, ?);', [doc.name, doc.type.dash_type, doc.url])
81
+ 'VALUES (?, ?, ?);', [doc.name, doc.type.dash_type, doc.filepath])
82
82
  end
83
83
  end
84
84
  end
@@ -1,3 +1,3 @@
1
1
  module Jazzy
2
- VERSION = '0.9.6'.freeze unless defined? Jazzy::VERSION
2
+ VERSION = '0.12.0'.freeze unless defined? Jazzy::VERSION
3
3
  end
@@ -3,6 +3,9 @@ require 'rouge'
3
3
  module Jazzy
4
4
  # This module helps highlight code
5
5
  module Highlighter
6
+ SWIFT = 'swift'.freeze
7
+ OBJC = 'objective_c'.freeze
8
+
6
9
  class Formatter < Rouge::Formatters::HTML
7
10
  def initialize(language)
8
11
  @language = language
@@ -16,16 +19,15 @@ module Jazzy
16
19
  end
17
20
  end
18
21
 
19
- # What Rouge calls the language
20
- def self.default_language
21
- if Config.instance.objc_mode
22
- 'objective_c'
23
- else
24
- 'swift'
25
- end
22
+ def self.highlight_swift(source)
23
+ highlight(source, SWIFT)
24
+ end
25
+
26
+ def self.highlight_objc(source)
27
+ highlight(source, OBJC)
26
28
  end
27
29
 
28
- def self.highlight(source, language = default_language)
30
+ def self.highlight(source, language)
29
31
  source && Rouge.highlight(source, language, Formatter.new(language))
30
32
  end
31
33
  end