Class: Pod::Command::Lib::Docstats

Inherits:
Pod::Command::Lib show all
Defined in:
lib/pod/command/lib/docstats.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Docstats

Returns a new instance of Docstats.



13
14
15
16
# File 'lib/pod/command/lib/docstats.rb', line 13

def initialize(argv)
  @output = './cocoapods-docstats/'
  super
end

Instance Method Details

#docstat(docset_path) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/pod/command/lib/docstats.rb', line 18

def docstat(docset_path)
  require 'docstat'

  stats  = DocStat.process(docset_path)
  tokens = stats['containers'].map {|c| c['tokens']}.flatten
  ratio  = stats['ratio']
  puts "#{tokens.size} tokens, #{((ratio*1000).to_i/1000.0) * 100}% documented"
end

#generate_docset(path, spec) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pod/command/lib/docstats.rb', line 27

def generate_docset(path, spec)
  headers = headers_for_spec_at_location(path, spec)
  headers.map! { |header| Shellwords.escape header }

  docset_command = [
      "appledoc",
      "--project-name #{spec.name}",                           # name in top left
      "--project-company '#{spec.or_contributors_to_spec}'",   # name in top right
      "--company-id com.cocoadocs.#{spec.name.downcase}",      # the id for the

      "--project-version #{spec.version}",                      # project version
      "--no-install-docset",                                    # don't make a duplicate

      "--keep-intermediate-files",                              # space for now is OK
      "--create-html",                                          # eh, nice to have
      "--publish-docset",                                       # this should create atom

      "--docset-feed-url http://www.cocoadocs.org/docsets/#{spec.name}/xcode-docset.atom",
      "--docset-atom-filename xcode-docset.atom",

      "--docset-package-url http://www.cocoadocs.org/docsets/#{spec.name}/docset.xar",
      "--docset-package-filename docset",

      "--docset-fallback-url http://www.cocoadocs.org/docsets/#{spec.name}",
      "--docset-feed-name #{spec.name}",

      # http://gentlebytes.com/appledoc-docs-examples-advanced/
      "--keep-undocumented-objects",                         # not everyone will be documenting
      "--keep-undocumented-members",                         # so we should at least show something
      "--search-undocumented-doc",                           # uh? ( no idea what this does... )

      "--output #{@output}",                                 # where should we throw stuff
      *headers,
      " >/dev/null"
    ]

    command docset_command.join(' ')
end

#headers_for_spec_at_location(path, spec) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/pod/command/lib/docstats.rb', line 66

def headers_for_spec_at_location(path, spec)
  pathlist = Pod::Sandbox::PathList.new( Pathname.new(path) )
  headers = []

  # https://github.com/CocoaPods/cocoadocs.org/issues/35
  [spec, *spec.recursive_subspecs].each do |internal_spec|
    internal_spec.available_platforms.each do |platform|
      consumer = Pod::Specification::Consumer.new(internal_spec, platform)
      accessor = Pod::Sandbox::FileAccessor.new(pathlist, consumer)

      if accessor.public_headers
        headers += accessor.public_headers.map{ |filepath| filepath.to_s }
      else
        puts "Skipping headers for #{internal_spec} on platform #{platform} (no headers found).".blue
      end
    end
  end

  headers.uniq
end

#podspecs_to_checkObject

Raises:

  • (Informative)


87
88
89
90
91
# File 'lib/pod/command/lib/docstats.rb', line 87

def podspecs_to_check
  podspecs = Pathname.glob(Pathname.pwd + '*.podspec{.yaml,}')
  raise Informative, "Unable to find a podspec in the working directory" if podspecs.count.zero?
  podspecs
end

#runObject



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/pod/command/lib/docstats.rb', line 93

def run
  podspecs_to_check.each do |path|
    spec = Specification.from_file(path)

    generate_docset(Dir.pwd, spec)

    docset_path = File.join(@output, "com.cocoadocs.#{spec.name.downcase}." +
        spec.name + '.docset')
    docstat(docset_path)

    FileUtils.rm_rf(@output)
  end
end