cocoadex 1.0.1 → 1.1
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/bin/cocoadex +5 -28
- data/lib/cocoadex/keyword.rb +51 -14
- data/lib/cocoadex/models/class.rb +19 -31
- data/lib/cocoadex/models/element.rb +31 -0
- data/lib/cocoadex/models/entity.rb +5 -5
- data/lib/cocoadex/models/method.rb +22 -26
- data/lib/cocoadex/models/property.rb +12 -16
- data/lib/cocoadex/templates.rb +114 -0
- data/lib/cocoadex/version.rb +1 -1
- data/lib/cocoadex.rb +45 -0
- data/lib/ext/nil.rb +4 -0
- data/readme.md +71 -18
- metadata +37 -36
- data/cocoadex.gemspec +0 -25
- data/data/_store +0 -0
data/bin/cocoadex
CHANGED
@@ -15,52 +15,29 @@ main do |arg|
|
|
15
15
|
logger.error_level = Logger::DEBUG
|
16
16
|
end
|
17
17
|
|
18
|
-
if options[:
|
18
|
+
if options[:load_docset] and path = File.expand_path(options[:load_docset].first)
|
19
19
|
Parser.parse(path)
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
22
|
if options[:search] and text = options[:search].first
|
24
23
|
if Keyword.loaded?
|
25
24
|
logger.debug "Loading index..."
|
26
25
|
Keyword.read
|
27
|
-
search(text)
|
26
|
+
Cocoadex.search(text, options[:first])
|
28
27
|
else
|
29
28
|
puts "No DocSets loaded"
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
|
-
def search term
|
35
|
-
if term and not term.strip.empty?
|
36
|
-
objects = Keyword.find(term.strip)
|
37
|
-
if objects.size == 0
|
38
|
-
puts "No matches found"
|
39
|
-
elsif objects.size == 1
|
40
|
-
objects.first.print
|
41
|
-
else
|
42
|
-
objects.each_with_index do |obj, index|
|
43
|
-
puts "#{index} #{obj}"
|
44
|
-
end
|
45
|
-
puts "Select:"
|
46
|
-
which = gets
|
47
|
-
begin
|
48
|
-
index = [[which.to_i,0].max,objects.size - 1].min
|
49
|
-
objects[index].print
|
50
|
-
rescue Exception => e
|
51
|
-
puts ":("
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
33
|
version Cocoadex::VERSION
|
58
34
|
description 'A Class Reference Utility for Cocoa APIs'
|
59
35
|
|
60
36
|
on("--verbose","Be verbose")
|
37
|
+
on("--first","Load first result when multiple matches exist")
|
61
38
|
|
62
|
-
on("-d DOCSET","--docset","DocSet",/^(.*)$/)
|
63
|
-
on("-s QUERY","--search","Search",/^(.*)$/)
|
39
|
+
on("-d DOCSET","--load-docset","Load a DocSet into the datastore",/^(.*)$/)
|
40
|
+
on("-s QUERY","--search","Search the index",/^(.*)$/)
|
64
41
|
|
65
42
|
# todo: support --platform, --platform-version, --language, --first, --force
|
66
43
|
|
data/lib/cocoadex/keyword.rb
CHANGED
@@ -1,43 +1,82 @@
|
|
1
1
|
|
2
|
+
require 'fileutils'
|
3
|
+
|
2
4
|
module Cocoadex
|
3
5
|
class Keyword
|
4
6
|
attr_reader :term, :type, :docset, :url
|
5
7
|
attr_accessor :fk, :id
|
6
8
|
|
7
|
-
|
9
|
+
# Cache storage location
|
10
|
+
DATA_PATH = File.expand_path("~/.cocoadex/data/store.blob")
|
11
|
+
|
12
|
+
SEPARATOR = "--__--"
|
13
|
+
CLASS_METHOD_DELIM = '+'
|
14
|
+
INST_METHOD_DELIM = '-'
|
15
|
+
CLASS_PROP_DELIM = '.'
|
16
|
+
SCOPE_CHARS = [CLASS_PROP_DELIM,CLASS_METHOD_DELIM,INST_METHOD_DELIM]
|
8
17
|
|
9
18
|
def self.datastore
|
10
19
|
@store ||= []
|
11
20
|
end
|
12
21
|
|
22
|
+
# Search the cache for matching text
|
13
23
|
def self.find text
|
14
|
-
|
15
|
-
|
16
|
-
|
24
|
+
if (text.split(//u) & SCOPE_CHARS).size == 1
|
25
|
+
scope = SCOPE_CHARS.detect {|c| text.include? c }
|
26
|
+
class_name, term = text.split(scope)
|
27
|
+
find_with_scope scope, class_name, term
|
28
|
+
else
|
29
|
+
keys = datastore.select {|k| k.term.start_with? text }
|
30
|
+
if key = keys.detect {|k| k.term == text}
|
31
|
+
keys = [key]
|
32
|
+
end
|
33
|
+
untokenize(keys)
|
17
34
|
end
|
18
|
-
untokenize(keys)
|
19
35
|
end
|
20
36
|
|
37
|
+
def self.find_with_scope scope, class_name, term
|
38
|
+
if class_key = datastore.detect {|k| k.term == class_name }
|
39
|
+
klass = untokenize([class_key]).first
|
40
|
+
case scope
|
41
|
+
when CLASS_PROP_DELIM
|
42
|
+
(klass.methods + klass.properties).select {|m| m.name.start_with? term}
|
43
|
+
when CLASS_METHOD_DELIM
|
44
|
+
klass.class_methods.select {|m| m.name.start_with? term}
|
45
|
+
when INST_METHOD_DELIM
|
46
|
+
klass.instance_methods.select {|m| m.name.start_with? term}
|
47
|
+
end
|
48
|
+
else
|
49
|
+
[]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Are any docsets loaded into the cache?
|
21
54
|
def self.loaded?
|
22
55
|
File.exists? DATA_PATH
|
23
56
|
end
|
24
57
|
|
58
|
+
# Read a serialized cache file into an Array
|
25
59
|
def self.read
|
26
|
-
$/=
|
60
|
+
$/=SEPARATOR
|
27
61
|
File.open(DATA_PATH, "r").each do |object|
|
28
|
-
datastore <<
|
62
|
+
datastore << Marshal::load(object)
|
29
63
|
end
|
30
64
|
end
|
31
65
|
|
66
|
+
# Write a cache Array as a serialized file
|
32
67
|
def self.write
|
68
|
+
unless File.exists? File.dirname(DATA_PATH)
|
69
|
+
FileUtils.mkdir_p File.dirname(DATA_PATH)
|
70
|
+
end
|
33
71
|
File.open(DATA_PATH, "w") do |file|
|
34
72
|
datastore.each do |keyword|
|
35
|
-
file.
|
36
|
-
file.
|
73
|
+
file.print(Marshal.dump(keyword))
|
74
|
+
file.print SEPARATOR
|
37
75
|
end
|
38
76
|
end
|
39
77
|
end
|
40
78
|
|
79
|
+
# Create Cocoadex model objects for Keyword references
|
41
80
|
def self.untokenize keys
|
42
81
|
keys.map do |key|
|
43
82
|
case key.type
|
@@ -48,18 +87,16 @@ module Cocoadex
|
|
48
87
|
klass = Cocoadex::Class.new(class_key.url)
|
49
88
|
case key.type
|
50
89
|
when :method
|
51
|
-
|
90
|
+
klass.methods.detect {|m| m.name == key.term}
|
52
91
|
when :property
|
53
|
-
|
92
|
+
klass.properties.detect {|m| m.name == key.term}
|
54
93
|
end
|
55
|
-
|
56
|
-
entity.class_name = klass.name
|
57
|
-
entity
|
58
94
|
end
|
59
95
|
end
|
60
96
|
end
|
61
97
|
end
|
62
98
|
|
99
|
+
# Find all searchable keywords in a class and add to cache
|
63
100
|
def self.tokenize_class docset, path, id
|
64
101
|
klass = Cocoadex::Class.new(path)
|
65
102
|
class_key = Keyword.new(klass.name, :class, docset, path)
|
@@ -2,8 +2,11 @@
|
|
2
2
|
require 'set'
|
3
3
|
|
4
4
|
module Cocoadex
|
5
|
+
# A model of a Cocoa API class or protocol
|
5
6
|
class Class < Entity
|
6
|
-
|
7
|
+
TEMPLATE=Cocoadex::Templates::CLASS_DESCRIPTION
|
8
|
+
|
9
|
+
attr_reader :description, :overview
|
7
10
|
|
8
11
|
def properties
|
9
12
|
@properties ||=[]
|
@@ -17,45 +20,31 @@ module Cocoadex
|
|
17
20
|
@methods ||= ::Set.new
|
18
21
|
end
|
19
22
|
|
20
|
-
def
|
21
|
-
|
23
|
+
def class_methods
|
24
|
+
methods.select{|m| m.scope == :class }
|
22
25
|
end
|
23
26
|
|
24
|
-
def
|
25
|
-
|
27
|
+
def instance_methods
|
28
|
+
methods.select{|m| m.scope == :instance }
|
26
29
|
end
|
27
30
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#{description}
|
33
|
-
|
34
|
-
Inherits From: #{parents.join(' > ')}
|
35
|
-
|
36
|
-
Overview:
|
37
|
-
|
38
|
-
#{overview}
|
31
|
+
def parents
|
32
|
+
@parents ||= []
|
33
|
+
end
|
39
34
|
|
40
|
-
|
35
|
+
def type
|
36
|
+
"Class"
|
37
|
+
end
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
prop.print
|
45
|
-
end
|
46
|
-
puts <<-INFO
|
47
|
-
Methods:
|
48
|
-
INFO
|
49
|
-
methods.each do |m|
|
50
|
-
m.print
|
51
|
-
end
|
39
|
+
def origin
|
40
|
+
parents.join(' > ')
|
52
41
|
end
|
53
42
|
|
54
43
|
def parse doc
|
55
44
|
@name = doc.css('body a').first['title']
|
56
45
|
@description = doc.css('meta#description').first['content']
|
57
46
|
# @overview = doc.css(".zClassDescription p.abstract").first.text
|
58
|
-
@overview = doc.css(".zClassDescription").first.text.sub("Overview","")
|
47
|
+
@overview = doc.css(".zClassDescription").first.children.map {|n| n.text.sub("Overview","") }
|
59
48
|
@parents = doc.css("div.zSharedSpecBoxHeadList").first.css('a').map {|node| node.text}
|
60
49
|
|
61
50
|
parse_properties(doc)
|
@@ -66,16 +55,15 @@ module Cocoadex
|
|
66
55
|
def parse_methods doc
|
67
56
|
[:class, :instance].each do |selector|
|
68
57
|
nodes = doc.css("div.#{selector}Method")
|
69
|
-
# logger.debug(nodes.inspect)
|
70
58
|
unless nodes.empty?
|
71
|
-
methods.merge(nodes.map {|n| Method.new(selector, n)})
|
59
|
+
methods.merge(nodes.map {|n| Method.new(self, selector, n)})
|
72
60
|
end
|
73
61
|
end
|
74
62
|
end
|
75
63
|
|
76
64
|
def parse_properties doc
|
77
65
|
@properties = doc.css("div.propertyObjC").map do |prop|
|
78
|
-
Property.new(prop)
|
66
|
+
Property.new(self, prop)
|
79
67
|
end
|
80
68
|
end
|
81
69
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
module Cocoadex
|
3
|
+
# A searchable element stored in the cache
|
4
|
+
class Element
|
5
|
+
include Comparable
|
6
|
+
include Bri::Templates::Helpers
|
7
|
+
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
name
|
12
|
+
end
|
13
|
+
|
14
|
+
def print
|
15
|
+
template = self.class.const_get(:TEMPLATE)
|
16
|
+
ERB.new(template, nil, '<>').result(binding)
|
17
|
+
end
|
18
|
+
|
19
|
+
def <=> other
|
20
|
+
name <=> other.name if other.respond_to? :name
|
21
|
+
end
|
22
|
+
|
23
|
+
def origin
|
24
|
+
raise "#{self.class}#origin is not defined"
|
25
|
+
end
|
26
|
+
|
27
|
+
def type
|
28
|
+
raise "#{self.class}#type is not defined"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
module Cocoadex
|
3
|
-
|
3
|
+
# A top level element, roughly equivalent to one
|
4
|
+
# page of documentation
|
5
|
+
class Entity < Element
|
4
6
|
|
5
7
|
def initialize path
|
6
8
|
text = clean(IO.read(path))
|
@@ -8,10 +10,8 @@ module Cocoadex
|
|
8
10
|
parse(document)
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
13
|
+
# Remove leading and trailing whitespace from lines, while
|
14
|
+
# stripping HTML tags
|
15
15
|
def clean text
|
16
16
|
text.gsub(/(\n|\t|\r)/, ' ').gsub(/>\s*</, '><').squeeze(' ')
|
17
17
|
end
|
@@ -1,22 +1,29 @@
|
|
1
1
|
|
2
2
|
module Cocoadex
|
3
3
|
class Class < Entity
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
:return_value
|
4
|
+
# A model of a method in a Cocoa class
|
5
|
+
class Method < Element
|
6
|
+
TEMPLATE=Cocoadex::Templates::METHOD_DESCRIPTION
|
8
7
|
|
9
|
-
|
8
|
+
attr_reader :abstract, :declaration, :discussion,
|
9
|
+
:declared_in, :availability, :parameters,
|
10
|
+
:return_value, :scope, :parent
|
10
11
|
|
11
12
|
class Parameter
|
13
|
+
include Comparable
|
14
|
+
|
12
15
|
attr_reader :name, :description
|
13
16
|
|
14
17
|
def initialize name, description
|
15
18
|
@name, @description = name, description
|
16
19
|
end
|
17
20
|
|
18
|
-
def
|
19
|
-
|
21
|
+
def to_s
|
22
|
+
"#{name} - #{description}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def <=> other
|
26
|
+
name <=> other.name if other.respond_to? :name
|
20
27
|
end
|
21
28
|
end
|
22
29
|
|
@@ -24,9 +31,10 @@ module Cocoadex
|
|
24
31
|
@parameters ||= []
|
25
32
|
end
|
26
33
|
|
27
|
-
def initialize type, node
|
28
|
-
@
|
29
|
-
@
|
34
|
+
def initialize parent_class, type, node
|
35
|
+
@parent = parent_class
|
36
|
+
@scope = type
|
37
|
+
@name = node.css("h3.#{type}Method").first.text
|
30
38
|
logger.debug("parsing #{@type} method #{@name}")
|
31
39
|
@abstract = node.css(".abstract").first.text
|
32
40
|
@declaration = node.css(".declaration").first.text
|
@@ -62,24 +70,12 @@ module Cocoadex
|
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
65
|
-
def
|
66
|
-
"
|
67
|
-
end
|
68
|
-
|
69
|
-
def print
|
70
|
-
puts <<-PRINT
|
71
|
-
Declared in: #{declared_in}
|
72
|
-
|
73
|
-
#{declaration}
|
74
|
-
#{print_parameters}
|
75
|
-
Returns: #{return_value}
|
76
|
-
#{abstract}
|
77
|
-
#{availability}
|
78
|
-
PRINT
|
73
|
+
def type
|
74
|
+
"#{scope.to_s.capitalize} Method"
|
79
75
|
end
|
80
76
|
|
81
|
-
def
|
82
|
-
|
77
|
+
def origin
|
78
|
+
parent.to_s
|
83
79
|
end
|
84
80
|
end
|
85
81
|
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
|
2
2
|
module Cocoadex
|
3
|
-
class
|
4
|
-
|
3
|
+
# A Cocoa API class property
|
4
|
+
class Property < Element
|
5
|
+
TEMPLATE=Cocoadex::Templates::PROPERTY_DESCRIPTION
|
5
6
|
|
6
|
-
|
7
|
+
attr_reader :abstract, :declaration, :discussion,
|
8
|
+
:availability, :parent
|
7
9
|
|
8
|
-
def initialize node
|
9
|
-
@
|
10
|
+
def initialize parent_class, node
|
11
|
+
@parent = parent_class
|
12
|
+
@name = node.css("h3.method_property").first.text
|
10
13
|
logger.debug("Adding property: #{@name}")
|
11
14
|
|
12
15
|
if abs = node.css(".abstract") and abs.length > 0
|
@@ -26,19 +29,12 @@ module Cocoadex
|
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
29
|
-
def
|
30
|
-
|
32
|
+
def origin
|
33
|
+
parent.to_s
|
31
34
|
end
|
32
35
|
|
33
|
-
def
|
34
|
-
|
35
|
-
Declared in: #{class_name || ''}
|
36
|
-
|
37
|
-
#{name}
|
38
|
-
#{abstract}
|
39
|
-
#{availability}
|
40
|
-
|
41
|
-
PRINT
|
36
|
+
def type
|
37
|
+
"Property"
|
42
38
|
end
|
43
39
|
end
|
44
40
|
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Cocoadex
|
2
|
+
module Templates
|
3
|
+
MULTIPLE_CHOICES =<<-EOT
|
4
|
+
<%= Bri::Templates::Helpers.hrule("Multiple choices:") %>
|
5
|
+
|
6
|
+
<%= Bri::Renderer.wrap_list( objects.sort ) %>
|
7
|
+
|
8
|
+
EOT
|
9
|
+
|
10
|
+
CLASS_DESCRIPTION =<<-EOT
|
11
|
+
|
12
|
+
<%= hrule( type + ": " + name ) %>
|
13
|
+
<%= print_origin( origin ) %>
|
14
|
+
|
15
|
+
<% if description.empty? %>
|
16
|
+
(no description...)
|
17
|
+
<% else %>
|
18
|
+
<%= '\n' + description %>
|
19
|
+
<% end %>
|
20
|
+
<% unless overview.empty? %>
|
21
|
+
<%= hrule %>
|
22
|
+
|
23
|
+
<%= section_header( "Overview:" ) %>
|
24
|
+
<%= Bri::Renderer.wrap_row(overview.join('\n\n'), Cocoadex.width) %>
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
<%= hrule %>
|
28
|
+
|
29
|
+
<% unless class_methods.empty? %>
|
30
|
+
<%= section_header( "Class methods:" ) %>
|
31
|
+
<%= Bri::Renderer.wrap_list( class_methods.sort ) %>
|
32
|
+
|
33
|
+
|
34
|
+
<% end %>
|
35
|
+
<% unless instance_methods.empty? %>
|
36
|
+
<%= section_header( "Instance methods:" ) %>
|
37
|
+
<%= Bri::Renderer.wrap_list( instance_methods.sort ) %>
|
38
|
+
|
39
|
+
|
40
|
+
<% end %>
|
41
|
+
<% unless properties.empty? %>
|
42
|
+
<%= section_header( "Properties:" ) %>
|
43
|
+
<%= Bri::Renderer.wrap_list( properties.sort ) %>
|
44
|
+
|
45
|
+
|
46
|
+
<% end %>
|
47
|
+
EOT
|
48
|
+
|
49
|
+
METHOD_DESCRIPTION =<<-EOT
|
50
|
+
|
51
|
+
<%= hrule( name ) %>
|
52
|
+
<%= print_origin( origin ) %>
|
53
|
+
|
54
|
+
|
55
|
+
<%= Cocoadex.trailing_indent(Bri::Renderer.wrap_row(declaration, Cocoadex.width), 2, 6) %>
|
56
|
+
|
57
|
+
<% if return_value %>
|
58
|
+
|
59
|
+
<%= 'Returns: ' + return_value %>
|
60
|
+
<% end %>
|
61
|
+
|
62
|
+
<%= hrule %>
|
63
|
+
<% if abstract.empty? %>
|
64
|
+
(no description...)
|
65
|
+
<% else %>
|
66
|
+
<%= Bri::Renderer.wrap_row(abstract, Cocoadex.width) %>
|
67
|
+
<% end %>
|
68
|
+
|
69
|
+
<% unless parameters.empty? %>
|
70
|
+
<%= section_header( "Parameters:" ) %>
|
71
|
+
<% parameters.each do |param| %>
|
72
|
+
|
73
|
+
<%= h3(Cocoadex.indent(param.name, 2)).strip %>
|
74
|
+
<% Bri::Renderer.wrap_row(param.description, Cocoadex.width).split('\n').each do |line| %>
|
75
|
+
<%= Cocoadex.indent(line, 4) %>
|
76
|
+
<% end %>
|
77
|
+
<% end %>
|
78
|
+
|
79
|
+
|
80
|
+
<% end %>
|
81
|
+
<%= availability %>
|
82
|
+
|
83
|
+
EOT
|
84
|
+
|
85
|
+
PROPERTY_DESCRIPTION =<<-EOT
|
86
|
+
|
87
|
+
<%= hrule( name ) %>
|
88
|
+
<%= print_origin( origin ) %>
|
89
|
+
|
90
|
+
|
91
|
+
<%= Bri::Renderer.wrap_row(declaration, Cocoadex.width) %>
|
92
|
+
<%= hrule %>
|
93
|
+
<% if abstract.empty? %>
|
94
|
+
(no description...)
|
95
|
+
<% else %>
|
96
|
+
<%= Bri::Renderer.wrap_row(abstract, Cocoadex.width) %>
|
97
|
+
<% end %>
|
98
|
+
|
99
|
+
<%= availability %>
|
100
|
+
|
101
|
+
EOT
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
module Bri
|
106
|
+
module Templates
|
107
|
+
module Helpers
|
108
|
+
def h3 text
|
109
|
+
Term::ANSIColor::blue + text + Term::ANSIColor::reset + "\n"
|
110
|
+
end
|
111
|
+
module_function :h3
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/cocoadex/version.rb
CHANGED
data/lib/cocoadex.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
|
2
|
+
require 'erb'
|
3
|
+
require 'bri'
|
2
4
|
require 'cocoadex/version'
|
5
|
+
require 'cocoadex/templates'
|
3
6
|
require 'cocoadex/models/docset'
|
7
|
+
require 'cocoadex/models/element'
|
4
8
|
require 'cocoadex/models/entity'
|
5
9
|
require 'cocoadex/models/method'
|
6
10
|
require 'cocoadex/models/property'
|
@@ -9,7 +13,48 @@ require 'cocoadex/parser'
|
|
9
13
|
require 'cocoadex/keyword'
|
10
14
|
require 'ext/nil'
|
11
15
|
require 'nokogiri'
|
16
|
+
require 'term/ansicolor'
|
12
17
|
|
13
18
|
module Cocoadex
|
14
19
|
|
20
|
+
DEFAULT_WIDTH = 72
|
21
|
+
|
22
|
+
# output documentation text for a given search term
|
23
|
+
def self.search term, load_first=false
|
24
|
+
term = term.strip
|
25
|
+
unless term.empty?
|
26
|
+
objects = Keyword.find(term)
|
27
|
+
if objects.size == 0
|
28
|
+
puts "No matches found"
|
29
|
+
elsif objects.size == 1 or load_first
|
30
|
+
puts objects.first.print
|
31
|
+
else
|
32
|
+
template = Cocoadex::Templates::MULTIPLE_CHOICES
|
33
|
+
puts ERB.new(template, nil, '<>').result(binding)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# The maximum line width
|
39
|
+
def self.width
|
40
|
+
@width || DEFAULT_WIDTH
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.width= width
|
44
|
+
@width = width
|
45
|
+
end
|
46
|
+
|
47
|
+
# add leading whitespace to lines
|
48
|
+
def self.indent text, level=2
|
49
|
+
text.split("\n").collect {|row| "#{' '*level}#{row}"}.join("\n" )
|
50
|
+
end
|
51
|
+
|
52
|
+
# add leading whitespace to lines, increasing indent after
|
53
|
+
# the first line
|
54
|
+
def self.trailing_indent text, base_level=2, inside_level=4
|
55
|
+
text.split("\n").each_with_index.collect do |row, index|
|
56
|
+
level = index == 0 ? base_level : inside_level
|
57
|
+
"#{' '*level}#{row}"
|
58
|
+
end.join("\n")
|
59
|
+
end
|
15
60
|
end
|
data/lib/ext/nil.rb
CHANGED
data/readme.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# THE COCOADEX
|
2
2
|
|
3
|
-
|
3
|
+
Documentation lookup for Cocoa APIs, in the spirit of RI
|
4
4
|
|
5
|
+
Cocoadex parses Cocoa documentation files and creates a keyword index. Queries can then be run against the index for fast documentation lookup.
|
5
6
|
|
6
7
|
## Installation
|
7
8
|
|
@@ -10,25 +11,77 @@ Spartan documentation lookup for Cocoa APIs
|
|
10
11
|
## Usage
|
11
12
|
|
12
13
|
- **View Options:** `cocoadex --help`
|
13
|
-
- **Loading a DocSet:** `cocoadex --docset [path]` (Try `~/Library/Developer/DocSets/[docset name]`)
|
14
|
-
- **Look up:** `cocoadex --search [query]`
|
15
|
-
- Valid search terms are Class, method, and property names
|
16
|
-
- Example:
|
17
14
|
|
18
|
-
|
19
|
-
Declared in: UITableView.h
|
15
|
+
- **Loading a DocSet:** `cocoadex --load-docset [path]` (Try `~/Library/Developer/DocSets/[docset name]`)
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
indexPath - An index path locating the new selected row in tableView.
|
24
|
-
Returns:
|
25
|
-
Tells the delegate that the specified row is now selected.
|
26
|
-
Available in iOS 2.0 and later.
|
17
|
+
- **Look up Documentation:** `cocoadex --search [query]`
|
18
|
+
- Valid search terms are Class, method, and property names. Search scope can also be focused using delimiters, such as `ClassName-method` to find instance methods, `Class+method` to find class methods, or `Class.method` to find any matching method or property in `Class`.
|
27
19
|
|
28
20
|
|
29
|
-
|
21
|
+
*Property Lookup Example*
|
30
22
|
|
31
|
-
|
32
|
-
-
|
33
|
-
|
34
|
-
|
23
|
+
<pre>
|
24
|
+
$ cocoadex -s tableView
|
25
|
+
|
26
|
+
-------------------------------------------------------------- tableView
|
27
|
+
(UITableViewController)
|
28
|
+
|
29
|
+
@property(nonatomic, retain) UITableView *tableView
|
30
|
+
------------------------------------------------------------------------
|
31
|
+
Returns the table view managed by the controller object.
|
32
|
+
|
33
|
+
Available in iOS 2.0 and later.
|
34
|
+
</pre>
|
35
|
+
|
36
|
+
|
37
|
+
*Method Lookup Example*
|
38
|
+
|
39
|
+
<pre>
|
40
|
+
$ cocoadex -s tableView:viewForFoo
|
41
|
+
|
42
|
+
-------------------------------------- tableView:viewForFooterInSection:
|
43
|
+
(UITableViewDelegate)
|
44
|
+
|
45
|
+
- (UIView *)tableView:(UITableView *)tableView
|
46
|
+
viewForFooterInSection:(NSInteger)section
|
47
|
+
|
48
|
+
Returns: A view object to be displayed in the footer of section .
|
49
|
+
------------------------------------------------------------------------
|
50
|
+
Asks the delegate for a view object to display in the footer of the
|
51
|
+
specified section of the table view.
|
52
|
+
|
53
|
+
Parameters:
|
54
|
+
|
55
|
+
tableView
|
56
|
+
The table-view object asking for the view object.
|
57
|
+
section
|
58
|
+
An index number identifying a section of tableView .
|
59
|
+
|
60
|
+
Available in iOS 2.0 and later.
|
61
|
+
</pre>
|
62
|
+
|
63
|
+
*Class Lookup Example (Clipped for brevity)*
|
64
|
+
|
65
|
+
<pre>
|
66
|
+
$ cocoadex -s UILabel
|
67
|
+
|
68
|
+
--------------------------------------------------------- Class: UILabel
|
69
|
+
(UIView > UIResponder > NSObject)
|
70
|
+
|
71
|
+
Describes a control for displaying static text.
|
72
|
+
------------------------------------------------------------------------
|
73
|
+
|
74
|
+
Overview:
|
75
|
+
|
76
|
+
(...)
|
77
|
+
|
78
|
+
Instance Methods:
|
79
|
+
drawTextInRect:, textRectForBounds:limitedToNumberOfLines:
|
80
|
+
|
81
|
+
Properties:
|
82
|
+
adjustsFontSizeToFitWidth, baselineAdjustment, enabled, font,
|
83
|
+
highlighted, highlightedTextColor, lineBreakMode, minimumFontSize,
|
84
|
+
numberOfLines, shadowColor, shadowOffset, text, textAlignment,
|
85
|
+
textColor, userInteractionEnabled
|
86
|
+
|
87
|
+
</pre>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoadex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,8 +13,8 @@ date: 2012-07-19 00:00:00.000000000 -04:00
|
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement: &
|
16
|
+
name: rdoc
|
17
|
+
requirement: &21891660 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,54 +22,54 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *21891660
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
28
|
-
requirement: &
|
27
|
+
name: rake
|
28
|
+
requirement: &21891100 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.9.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *21891100
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
requirement: &
|
38
|
+
name: methadone
|
39
|
+
requirement: &21890500 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
45
|
-
type: :
|
44
|
+
version: 1.2.1
|
45
|
+
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *21890500
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
50
|
-
requirement: &
|
49
|
+
name: term-ansicolor
|
50
|
+
requirement: &21890060 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ! '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0
|
56
|
-
type: :
|
55
|
+
version: '0'
|
56
|
+
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *21890060
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
61
|
-
requirement: &
|
60
|
+
name: bri
|
61
|
+
requirement: &21889520 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
|
-
- -
|
64
|
+
- - ! '>='
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
66
|
+
version: '0'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *21889520
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: nokogiri
|
72
|
-
requirement: &
|
72
|
+
requirement: &21889020 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,32 +77,33 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
81
|
-
description: A reference utility
|
80
|
+
version_requirements: *21889020
|
81
|
+
description: A command-line class reference utility Cocoa APIs
|
82
82
|
email:
|
83
83
|
- iskanamagus@gmail.com
|
84
84
|
executables:
|
85
85
|
- cocoadex
|
86
86
|
extensions: []
|
87
|
-
extra_rdoc_files:
|
87
|
+
extra_rdoc_files:
|
88
|
+
- readme.md
|
88
89
|
files:
|
89
90
|
- Gemfile
|
90
91
|
- LICENSE
|
91
92
|
- LICENSE.txt
|
93
|
+
- readme.md
|
92
94
|
- bin/cocoadex
|
93
|
-
- cocoadex.gemspec
|
94
|
-
- data/_store
|
95
95
|
- lib/cocoadex.rb
|
96
96
|
- lib/cocoadex/keyword.rb
|
97
|
+
- lib/cocoadex/parser.rb
|
98
|
+
- lib/cocoadex/templates.rb
|
99
|
+
- lib/cocoadex/version.rb
|
97
100
|
- lib/cocoadex/models/class.rb
|
98
101
|
- lib/cocoadex/models/docset.rb
|
102
|
+
- lib/cocoadex/models/element.rb
|
99
103
|
- lib/cocoadex/models/entity.rb
|
100
104
|
- lib/cocoadex/models/method.rb
|
101
105
|
- lib/cocoadex/models/property.rb
|
102
|
-
- lib/cocoadex/parser.rb
|
103
|
-
- lib/cocoadex/version.rb
|
104
106
|
- lib/ext/nil.rb
|
105
|
-
- readme.md
|
106
107
|
has_rdoc: true
|
107
108
|
homepage: http://kattrali.github.com/cocoadex
|
108
109
|
licenses: []
|
@@ -127,5 +128,5 @@ rubyforge_project:
|
|
127
128
|
rubygems_version: 1.6.2
|
128
129
|
signing_key:
|
129
130
|
specification_version: 3
|
130
|
-
summary: A command-line reference utility for Cocoa APIs.
|
131
|
+
summary: A command-line class reference utility for Cocoa APIs, based on RI.
|
131
132
|
test_files: []
|
data/cocoadex.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/cocoadex/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Delisa Mason"]
|
6
|
-
gem.email = ["iskanamagus@gmail.com"]
|
7
|
-
gem.description = %q{A reference utility for Cocoa APIs}
|
8
|
-
gem.summary = %q{A command-line reference utility for Cocoa APIs.}
|
9
|
-
gem.homepage = "http://kattrali.github.com/cocoadex"
|
10
|
-
|
11
|
-
gem.files = `git ls-files`.split($\)
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name = "cocoadex"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = Cocoadex::VERSION
|
17
|
-
gem.add_development_dependency('bacon')
|
18
|
-
gem.add_development_dependency('rdoc')
|
19
|
-
gem.add_development_dependency('aruba')
|
20
|
-
gem.add_development_dependency('rake','~> 0.9.2')
|
21
|
-
gem.add_dependency('methadone', '~>1.2.1')
|
22
|
-
# gem.add_dependency('term-ansicolor')
|
23
|
-
# gem.add_dependency('sqlite3')
|
24
|
-
gem.add_dependency('nokogiri')
|
25
|
-
end
|
data/data/_store
DELETED
File without changes
|