Commit c4702eb0 authored by Eloy Duran's avatar Eloy Duran

Move the doc generator into lib/cocoapods/generators/documentation.rb

parent ad1e8fab
...@@ -6,11 +6,9 @@ module Pod ...@@ -6,11 +6,9 @@ module Pod
class Informative < StandardError class Informative < StandardError
end end
autoload :BridgeSupportGenerator, 'cocoapods/bridge_support_generator'
autoload :Command, 'cocoapods/command' autoload :Command, 'cocoapods/command'
autoload :Config, 'cocoapods/config' autoload :Config, 'cocoapods/config'
autoload :Dependency, 'cocoapods/dependency' autoload :Dependency, 'cocoapods/dependency'
autoload :DocsGenerator, 'cocoapods/docs_generator'
autoload :Downloader, 'cocoapods/downloader' autoload :Downloader, 'cocoapods/downloader'
autoload :Executable, 'cocoapods/executable' autoload :Executable, 'cocoapods/executable'
autoload :Installer, 'cocoapods/installer' autoload :Installer, 'cocoapods/installer'
...@@ -28,11 +26,11 @@ module Pod ...@@ -28,11 +26,11 @@ module Pod
autoload :Pathname, 'pathname' autoload :Pathname, 'pathname'
autoload :FileList, 'cocoapods/file_list' autoload :FileList, 'cocoapods/file_list'
autoload :Open3, 'open3'
module Generator module Generator
autoload :BridgeSupport, 'cocoapods/generator/bridge_support' autoload :BridgeSupport, 'cocoapods/generator/bridge_support'
autoload :CopyResourcesScript, 'cocoapods/generator/copy_resources_script' autoload :CopyResourcesScript, 'cocoapods/generator/copy_resources_script'
autoload :Documentation, 'cocoapods/generator/documentation'
end end
end end
......
module Pod
class DocsGenerator
def self.appledoc_installed?
!`which appledoc`.strip.empty?
end
include Config::Mixin
attr_reader :pod, :specification, :target_path, :options
def initialize(pod)
@pod = pod
@specification = pod.specification
@target_path = pod.sandbox.root + "Documentation" + pod.name
@options = pod.specification.documentation || {}
end
def name
@specification.to_s
end
def company
if @specification.authors
@specification.authors.keys.join(', ')
else
'no-company'
end
end
def copyright
company
end
def description
@specification.description || "Generated by CocoaPods."
end
def docs_id
'org.cocoapods'
end
def files
@pod.absolute_source_files
end
def index_file
@pod.chdir do
Dir.glob("README*", File::FNM_CASEFOLD).first
end
end
def spec_appledoc_options
@options[:appledoc] || []
end
def generate_appledoc_options
options = ['--project-name', name,
'--docset-desc', description,
'--project-company', company,
'--docset-copyright', copyright,
'--company-id', docs_id,
'--ignore', '.m',
'--keep-undocumented-objects',
'--keep-undocumented-members']
index = index_file
options += ['--index-desc', index] if index
options += spec_appledoc_options
end
def generate(install = false)
unless self.class.appledoc_installed?
puts "[!] Skipping documentation generation because appledoc can't be found." if config.verbose?
return
end
options = generate_appledoc_options
options += ['--output', @target_path.to_s]
options += ['--keep-intermediate-files']
options += install ? ['-create-docset'] : ['--no-create-docset']
@target_path.mkpath
@pod.chdir do
appledoc(options)
end
end
def appledoc(options)
arguments = []
arguments += options
arguments += ['--print-settings'] if config.verbose?
arguments += files.map(&:to_s)
Open3.popen3('appledoc', *arguments) do |i, o, e|
if config.verbose?
puts o.read.chomp
puts e.read.chomp
else
# TODO: This is needed otherwise appledoc may not install the doc set
# This is a work around related to poor understanding of the IO class.
#
# I think we can use the non-block version here, which should read
# everything till the end and then return.
o.read
e.read
end
end
end
end
end
require 'open3'
module Pod
module Generator
class Documentation
def self.appledoc_installed?
!`which appledoc`.strip.empty?
end
include Config::Mixin
attr_reader :pod, :specification, :target_path, :options
def initialize(pod)
@pod = pod
@specification = pod.specification
@target_path = pod.sandbox.root + "Documentation" + pod.name
@options = pod.specification.documentation || {}
end
def name
@specification.to_s
end
def company
if @specification.authors
@specification.authors.keys.join(', ')
else
'no-company'
end
end
def copyright
company
end
def description
@specification.description || "Generated by CocoaPods."
end
def docs_id
'org.cocoapods'
end
def files
@pod.absolute_source_files
end
def index_file
@pod.chdir do
Dir.glob("README*", File::FNM_CASEFOLD).first
end
end
def spec_appledoc_options
@options[:appledoc] || []
end
def generate_appledoc_options
options = ['--project-name', name,
'--docset-desc', description,
'--project-company', company,
'--docset-copyright', copyright,
'--company-id', docs_id,
'--ignore', '.m',
'--keep-undocumented-objects',
'--keep-undocumented-members']
index = index_file
options += ['--index-desc', index] if index
options += spec_appledoc_options
end
def generate(install = false)
unless self.class.appledoc_installed?
puts "[!] Skipping documentation generation because appledoc can't be found." if config.verbose?
return
end
options = generate_appledoc_options
options += ['--output', @target_path.to_s]
options += ['--keep-intermediate-files']
options += install ? ['-create-docset'] : ['--no-create-docset']
@target_path.mkpath
@pod.chdir do
appledoc(options)
end
end
def appledoc(options)
arguments = []
arguments += options
arguments += ['--print-settings'] if config.verbose?
arguments += files.map(&:to_s)
Open3.popen3('appledoc', *arguments) do |i, o, e|
if config.verbose?
puts o.read.chomp
puts e.read.chomp
else
# TODO: This is needed otherwise appledoc may not install the doc set
# This is a work around related to poor understanding of the IO class.
#
# I think we can use the non-block version here, which should read
# everything till the end and then return.
o.read
e.read
end
end
end
end
end
end
...@@ -59,8 +59,7 @@ module Pod ...@@ -59,8 +59,7 @@ module Pod
if config.doc? if config.doc?
puts "Installing Documentation for #{spec}" if config.verbose? puts "Installing Documentation for #{spec}" if config.verbose?
docs_generator = DocsGenerator.new(pod) Generator::Documentation.new(pod).generate(config.doc_install?)
docs_generator.generate(config.doc_install?)
end end
end end
end end
......
...@@ -134,7 +134,7 @@ else ...@@ -134,7 +134,7 @@ else
change_log.should.not.include '1.3' change_log.should.not.include '1.3'
end end
if Pod::DocsGenerator.appledoc_installed? if Pod::Generator::Documentation.appledoc_installed?
it "generates documentation of all pods by default" do it "generates documentation of all pods by default" do
create_config! create_config!
......
require File.expand_path('../../spec_helper', __FILE__) require File.expand_path('../../../spec_helper', __FILE__)
describe Pod::Generator::Documentation do
describe Pod::DocsGenerator do
before do before do
@sandbox = temporary_sandbox @sandbox = temporary_sandbox
@pod = Pod::LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), @sandbox) @pod = Pod::LocalPod.new(fixture_spec('banana-lib/BananaLib.podspec'), @sandbox)
copy_fixture_to_pod('banana-lib', @pod) copy_fixture_to_pod('banana-lib', @pod)
@doc_installer = Pod::DocsGenerator.new(@pod) @doc_installer = Pod::Generator::Documentation.new(@pod)
end end
it 'returns reads correctly the Pod documentation' do it 'returns reads correctly the Pod documentation' do
...@@ -44,7 +43,7 @@ describe Pod::DocsGenerator do ...@@ -44,7 +43,7 @@ describe Pod::DocsGenerator do
] ]
end end
if Pod::DocsGenerator.appledoc_installed? if Pod::Generator::Documentation.appledoc_installed?
before do before do
@doc_installer.generate @doc_installer.generate
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment