Commit 98c972e0 authored by Fabio Pelosin's avatar Fabio Pelosin

[#149] Improved documentation generation

- refactoring
- default options for appledoc
- added command line arguments to pod install
- added option to force documentation generation with appledoc
parent e14fb9c8
...@@ -69,8 +69,6 @@ module Pod ...@@ -69,8 +69,6 @@ module Pod
show_help = argv.option('--help') show_help = argv.option('--help')
Config.instance.silent = argv.option('--silent') Config.instance.silent = argv.option('--silent')
Config.instance.verbose = argv.option('--verbose') Config.instance.verbose = argv.option('--verbose')
Config.instance.generate_documentation = argv.option('--generate_documentation')
Config.instance.install_documentation = argv.option('--install_documentation')
command_class = case argv.shift_argument command_class = case argv.shift_argument
when 'install' then Install when 'install' then Install
......
...@@ -20,11 +20,17 @@ module Pod ...@@ -20,11 +20,17 @@ module Pod
def self.options def self.options
" --no-clean Leave SCM dirs like `.git' and `.svn' in tact after downloading\n" + " --no-clean Leave SCM dirs like `.git' and `.svn' in tact after downloading\n" +
" --no-update Skip running `pod repo update` before install\n" + " --no-update Skip running `pod repo update` before install\n" +
" --doc-force Generate documentation for all pods with appledoc\n" +
" --no-doc Skip documentation generation\n" +
" --no-doc-install Skip documentation installation to Xcode\n" +
super super
end end
def initialize(argv) def initialize(argv)
config.clean = !argv.option('--no-clean') config.clean = !argv.option('--no-clean')
config.doc = !argv.option('--no-doc')
config.doc_install = !argv.option('--no-doc-install')
config.doc_force = argv.option('--doc-force')
@update_repo = !argv.option('--no-update') @update_repo = !argv.option('--no-update')
@projpath = argv.shift_argument @projpath = argv.shift_argument
super unless argv.empty? super unless argv.empty?
......
...@@ -10,20 +10,22 @@ module Pod ...@@ -10,20 +10,22 @@ module Pod
@instance = instance @instance = instance
end end
attr_accessor :repos_dir, :project_root, :project_pods_root, :rootspec, :clean, :verbose, :silent, :install_documentation, :generate_documentation attr_accessor :repos_dir, :project_root, :project_pods_root, :rootspec, :clean, :verbose, :silent, :doc, :doc_install, :doc_force
alias_method :clean?, :clean alias_method :clean?, :clean
alias_method :verbose?, :verbose alias_method :verbose?, :verbose
alias_method :silent?, :silent alias_method :silent?, :silent
alias_method :install_documentation?, :install_documentation alias_method :doc?, :doc
alias_method :generate_documentation?, :generate_documentation alias_method :doc_install?, :doc_install
alias_method :doc_force?, :doc_force
def initialize def initialize
@repos_dir = Pathname.new(File.expand_path("~/.cocoapods")) @repos_dir = Pathname.new(File.expand_path("~/.cocoapods"))
@clean = true @clean = true
@verbose = false @verbose = false
@silent = false @silent = false
@install_documentation = false @doc = true
@generate_documentation = false @doc_install = true
@doc_force = false
end end
def project_root def project_root
......
...@@ -51,13 +51,15 @@ module Pod ...@@ -51,13 +51,15 @@ module Pod
downloader = Downloader.for_pod(pod) downloader = Downloader.for_pod(pod)
downloader.download downloader.download
if config.generate_documentation && pod.can_generated_documentation
puts "Generating documentation for #{spec}" unless config.silent? if config.doc?
pods.each { |pod| pod.generate_documentation } doc_source = pod.generate_documentation(config.doc_install?, config.doc_force? ,config.verbose?)
elsif config.install_documentation && pod.can_install_documentation if doc_source
puts "Installing documentation for #{spec}" unless config.silent? action = config.doc_install ? 'installed' : 'generated'
pods.each { |pod| pod.install_documentation } puts " #{action} #{doc_source} documentation" unless config.silent?
end
end end
if config.clean if config.clean
downloader.clean downloader.clean
pod.clean pod.clean
......
...@@ -75,40 +75,58 @@ module Pod ...@@ -75,40 +75,58 @@ module Pod
end end
end end
def can_generated_documentation # Generates and installs the documentation of the pod.
specification.documentation && specification.documentation[:appledoc] #
end # It returns a human redable string containing the source used
# for the documentation. If no source was available it returns
def can_install_documentation # nil.
specification.documentation && specification.documentation[:appledoc] #
end def generate_documentation(install, force = true, verbose = false)
documentation = specification.documentation ? specification.documentation : {}
def generate_documentation
if specification.documentation if force || documentation.has_key?(:appledoc)
appledoc_options = specification.documentation[:appledoc] `which appledoc`
if appledoc_options return nil unless $?.success?
appledoc_options += ['--output', "#{@sandbox.root}/doc", '--no-create-docset'] dir = "#{@sandbox.root}/Documentation/#{name}/"
appledoc_options += source_files FileUtils.mkdir_p(dir)
Open3.popen3('appledoc', *appledoc_options ) { |stdin, stdout, stderr| # default options
puts stdout.read.chomp options = ['--project-name', specification.to_s,
puts stderr.read.chomp '--project-company', specification.authors.keys.to_s,
} '--docset-copyright', "Generated by cocoapods (see #{specification.homepage} for copyright information).",
end '--docset-desc', specification.description,
end '--company-id', 'org.cocoapods',
end '--ignore', '.m']
# spec options
def install_documentation options += documentation[:appledoc] if documentation[:appledoc]
if specification.documentation # options that can't be overridden
appledoc_options = specification.documentation[:appledoc] options << '--no-create-docset' unless install
if appledoc_options options << '--keep-intermediate-files'
appledoc_options += ['--output', "#{@sandbox.root}/doc"] options += ['--output', dir]
appledoc_options += source_files options += expanded_paths(specification.source_files, :glob => '*.{h,m,mm,c,cpp}', :relative_to_sandbox => false)
Open3.popen3('appledoc', *appledoc_options ) { |stdin, stdout, stderr| puts "appledoc #{options.join(" ")}" if verbose
puts stdout.read.chomp success = false
puts stderr.read.chomp Open3.popen3('appledoc', *options ) do |stdin, stdout, stderr|
} puts stdout.read.chomp if verbose
end puts stderr.read.chomp if verbose
end success = stderr.read.chomp == ""
end
# TODO: should return nil if appledoc fails
return success ? 'appledoc' : nil
elsif documentation[:atom] && install
# TODO: donwload and uncompress the docset
# path =
#Open3.popen3('osascript') { |stdin, stdout, stderr|
#stdin.puts('tell application "Xcode"')
#stdin.puts("load documentation set with path \"#{path}\"")
#stdin.puts('end tell')
#stdin.close
#puts stdout.read.chomp if verbose
#puts stderr.read.chomp if verbose
#}
#return 'atom'
end
return nil
end end
def requires_arc? def requires_arc?
......
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