rubydictionary 0.0.2 → 0.1.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.markdown +7 -3
- data/bin/rubydictionary +1 -1
- data/lib/rdoc/generator/template/Dictionary.css +21 -7
- data/lib/rubydictionary/generator.rb +19 -23
- data/lib/rubydictionary/version.rb +1 -1
- metadata +3 -7
- data/dictionary_generator.rb +0 -121
- data/templates/class.erb +0 -44
- data/templates/dictionary.erb +0 -9
- data/templates/method.erb +0 -11
data/README.markdown
CHANGED
@@ -12,11 +12,15 @@ You will need latest [*Xcode* developer tools](http://developer.apple.com/).
|
|
12
12
|
|
13
13
|
Run `rubydictionary` in your source code directory. For example for source of Sinatra:
|
14
14
|
|
15
|
-
rubydictionary --
|
15
|
+
rubydictionary --dict-name=Sinatra --dict-id=com.sinatrarb.Dictionary
|
16
16
|
|
17
|
-
If all goes well, you should have Sinatra.dictionary file under
|
17
|
+
If all goes well, you should now have `Sinatra.dictionary` file under `./doc/objects` directory. Drop it into `~/Library/Dictionaries/` folder.
|
18
18
|
|
19
|
-
|
19
|
+
## Authors
|
20
|
+
|
21
|
+
See the [Github contributors page](https://github.com/priithaamer/rubydictionary/contributors).
|
22
|
+
|
23
|
+
## Links
|
20
24
|
|
21
25
|
* [Dictionary Services programming guide at Apple Developer site](http://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/DictionaryServicesProgGuide/index.html)
|
22
26
|
* [https://github.com/breakpointer/ajax-rdoc](https://github.com/breakpointer/ajax-rdoc)
|
data/bin/rubydictionary
CHANGED
@@ -2,6 +2,6 @@
|
|
2
2
|
|
3
3
|
require File.expand_path('../../lib/rubydictionary', __FILE__)
|
4
4
|
|
5
|
-
ARGV.
|
5
|
+
ARGV.unshift('--format=dictionary') if ARGV.grep(/\A(-f|--fmt|--format|-r|-R|--ri|--ri-site)\b/).empty?
|
6
6
|
r = RDoc::RDoc.new
|
7
7
|
r.document ARGV
|
@@ -6,10 +6,9 @@ d|entry {
|
|
6
6
|
|
7
7
|
h1, h2, h3 {
|
8
8
|
font-family: 'Helvetica Neue', Helvetica, sans-serif;
|
9
|
-
text-shadow: 0px 0px 0px #000;
|
10
9
|
}
|
11
10
|
|
12
|
-
h1 { font-size:
|
11
|
+
h1 { font-size: 130%; }
|
13
12
|
h1 .classname { font-size: 80%; }
|
14
13
|
h1 .methodtype { font-size: 80%; }
|
15
14
|
h1 .visibility { font-size: 70%; font-weight: normal; }
|
@@ -23,20 +22,35 @@ ul.attributes li { list-style-type: none; }
|
|
23
22
|
|
24
23
|
hr { border: none; border-bottom: 1px solid #ddd; }
|
25
24
|
|
25
|
+
p.method_name {
|
26
|
+
color: #666;
|
27
|
+
font-family: 'Helvetica Neue', Helvetica, sans-serif;
|
28
|
+
font-size: 90%;
|
29
|
+
font-weight: bold;
|
30
|
+
}
|
31
|
+
|
32
|
+
dl.rdoc-list dt {
|
33
|
+
font-weight: bold;
|
34
|
+
}
|
35
|
+
|
26
36
|
tt,
|
27
37
|
pre,
|
28
38
|
p.signatures {
|
29
|
-
font-family: Monaco;
|
39
|
+
font-family: Inconsolata, Monaco;
|
30
40
|
font-size: 12px;
|
31
41
|
}
|
32
42
|
|
33
43
|
pre {
|
34
|
-
|
35
|
-
|
36
|
-
|
44
|
+
background: rgb(254,251,243);
|
45
|
+
border: 1px solid rgba(0,0,0,0.2);
|
46
|
+
color: rgb(5, 75, 125);
|
47
|
+
line-height: 16px;
|
48
|
+
padding: 9px;
|
49
|
+
-webkit-border-radius: 3px;
|
50
|
+
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
37
51
|
}
|
38
52
|
|
39
53
|
a {
|
40
|
-
|
54
|
+
color: rgb(41, 113, 167);
|
41
55
|
text-decoration: none;
|
42
56
|
}
|
@@ -41,6 +41,10 @@ class RDoc::Generator::Dictionary
|
|
41
41
|
def initialize(options)
|
42
42
|
@options = options
|
43
43
|
@template_dir = Pathname.new(File.expand_path('../../rdoc/generator/template', __FILE__))
|
44
|
+
|
45
|
+
# Keep the track of methods and classes already rendered and avoid duplication
|
46
|
+
@class_ids = []
|
47
|
+
@method_ids = []
|
44
48
|
end
|
45
49
|
|
46
50
|
def generate(top_levels)
|
@@ -48,10 +52,17 @@ class RDoc::Generator::Dictionary
|
|
48
52
|
xml.send('dictionary', 'xmlns' => XMLNS, 'xmlns:d' => XMLNS_D) do
|
49
53
|
xml.parent.namespace = xml.parent.namespace_definitions.first
|
50
54
|
|
51
|
-
RDoc::TopLevel.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
RDoc::TopLevel.all_classes_and_modules.each do |clazz|
|
56
|
+
unless @class_ids.include?(class_id(clazz))
|
57
|
+
append_class_entry(clazz, xml)
|
58
|
+
@class_ids << class_id(clazz)
|
59
|
+
|
60
|
+
clazz.method_list.each do |mthd|
|
61
|
+
unless @method_ids.include?(method_id(mthd))
|
62
|
+
append_method_entry(mthd, xml)
|
63
|
+
@method_ids << method_id(mthd)
|
64
|
+
end
|
65
|
+
end
|
55
66
|
end
|
56
67
|
end
|
57
68
|
end
|
@@ -70,7 +81,7 @@ class RDoc::Generator::Dictionary
|
|
70
81
|
|
71
82
|
dict_build_tool = "/Developer/Extras/Dictionary Development Kit/bin/build_dict.sh"
|
72
83
|
|
73
|
-
%x{"#{dict_build_tool}" #{@options.dictionary_name} #{dict_src_path} #{css_path} #{plist_path}}
|
84
|
+
%x{"#{dict_build_tool}" "#{@options.dictionary_name}" #{dict_src_path} #{css_path} #{plist_path}}
|
74
85
|
end
|
75
86
|
|
76
87
|
def class_dir
|
@@ -79,14 +90,9 @@ class RDoc::Generator::Dictionary
|
|
79
90
|
|
80
91
|
private
|
81
92
|
|
82
|
-
# <d:entry id="activerecord_base" d:title="ActiveRecord::Base">
|
83
|
-
# <d:index d:value="ActiveRecord::Base"/>
|
84
|
-
# <d:index d:value="Base"/>
|
85
|
-
# <h1>ActiveRecord::Base</h1>
|
86
93
|
def append_class_entry(cls, xml)
|
87
94
|
xml.entry('id' => class_id(cls), 'd:title' => class_title(cls)) do
|
88
95
|
xml.index('d:value' => cls.full_name)
|
89
|
-
# xml.index('d:value' => class_index_name(clazz))
|
90
96
|
|
91
97
|
xml.h1(cls.full_name, :xmlns => XMLNS)
|
92
98
|
|
@@ -120,23 +126,14 @@ class RDoc::Generator::Dictionary
|
|
120
126
|
end
|
121
127
|
end
|
122
128
|
|
123
|
-
# <d:entry id="method_method_id" d:title="method-Name">
|
124
|
-
# <d:index d:value="method full name"/>
|
125
|
-
# <d:index d:value="method name"/>
|
126
|
-
# <h1><a href="x-dictionary:r:class_id:org.ruby-lang.Dictionary">class full name</a> <span class="methodtype"> <%= @method.singleton ? '::' : '#' %> </span> <%= @method.name.escape %> <span class="visibility">(<%= @method.visibility %>)</span></h1>
|
127
|
-
# <% unless @method.arglists.nil? %><p class="signatures"><%= @method.arglists.escape %></p><% end %>
|
128
|
-
# <% unless !@method.respond_to?(:aliases) || @method.aliases.empty? %><p>Aliases: <%= @method.aliases.map {|a| a.new_name }.join(", ").escape %></p><% end %>
|
129
|
-
# <% unless !@method.respond_to?(:is_alias_for) || @method.is_alias_for.nil? %><p>Alias for: <%= @method.is_alias_for.escape %></p><% end %>
|
130
|
-
# <% unless @description.empty? %>
|
131
|
-
# <%= @description %>
|
132
|
-
# <% end %>
|
133
|
-
# </d:entry>
|
134
129
|
def append_method_entry(mthd, xml)
|
135
130
|
xml.entry('id' => method_id(mthd), 'd:title' => method_title(mthd)) do
|
136
131
|
xml.index('d:value' => mthd.full_name)
|
137
132
|
xml.index('d:value' => mthd.name)
|
138
133
|
|
139
|
-
xml.h1(mthd.
|
134
|
+
xml.h1(mthd.arglists, :xmlns => XMLNS)
|
135
|
+
|
136
|
+
xml.p(mthd.full_name, :class => 'method_name', :xmlns => XMLNS)
|
140
137
|
|
141
138
|
xml.div(:xmlns => XMLNS) do
|
142
139
|
xml << mthd.description
|
@@ -153,7 +150,6 @@ class RDoc::Generator::Dictionary
|
|
153
150
|
end
|
154
151
|
|
155
152
|
def method_title(mthd)
|
156
|
-
# TODO: escape <>
|
157
153
|
mthd.name
|
158
154
|
end
|
159
155
|
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Priit Haamer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-07 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -34,16 +34,12 @@ files:
|
|
34
34
|
- README.markdown
|
35
35
|
- Rakefile
|
36
36
|
- bin/rubydictionary
|
37
|
-
- dictionary_generator.rb
|
38
37
|
- lib/rdoc/generator/template/Dictionary.css
|
39
38
|
- lib/rdoc/generator/template/Dictionary.plist.erb
|
40
39
|
- lib/rubydictionary.rb
|
41
40
|
- lib/rubydictionary/generator.rb
|
42
41
|
- lib/rubydictionary/version.rb
|
43
42
|
- rubydictionary.gemspec
|
44
|
-
- templates/class.erb
|
45
|
-
- templates/dictionary.erb
|
46
|
-
- templates/method.erb
|
47
43
|
has_rdoc: true
|
48
44
|
homepage: https://github.com/priithaamer/rubydictionary
|
49
45
|
licenses: []
|
data/dictionary_generator.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'erb'
|
4
|
-
require 'rubygems'
|
5
|
-
require 'iconv'
|
6
|
-
|
7
|
-
gem 'rdoc', '>= 0'
|
8
|
-
require 'rdoc/ri'
|
9
|
-
require 'rdoc/ri/store'
|
10
|
-
require 'rdoc/ri/paths'
|
11
|
-
require 'rdoc/markup'
|
12
|
-
require 'rdoc/markup/formatter'
|
13
|
-
require 'rdoc/text'
|
14
|
-
|
15
|
-
class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
16
|
-
def self.gen_relative_url(path, target)
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class String
|
22
|
-
def escape
|
23
|
-
gsub("&", "&").gsub("<", "<").gsub(">", ">").gsub("'", "'").gsub("\"", """)
|
24
|
-
end
|
25
|
-
def to_id
|
26
|
-
downcase.gsub('::', '_')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_template(file)
|
31
|
-
erb = ''
|
32
|
-
File.open("./templates/#{file}", 'r') { |f| erb = f.read }
|
33
|
-
ERB.new(erb)
|
34
|
-
end
|
35
|
-
|
36
|
-
class_template = get_template('class.erb')
|
37
|
-
|
38
|
-
def render_class(klass)
|
39
|
-
tpl = get_template('class.erb')
|
40
|
-
@class = klass
|
41
|
-
@class_methods = klass.method_list.reject{ |m| !m.singleton }.sort{ |a,b| a.name <=> b.name }
|
42
|
-
@instance_methods = klass.method_list.reject{ |m| m.singleton }.sort{ |a,b| a.name <=> b.name }
|
43
|
-
begin
|
44
|
-
@description = @iconv.iconv(klass.comment.accept(@formatter))
|
45
|
-
rescue
|
46
|
-
@description = ""
|
47
|
-
end
|
48
|
-
tpl.result(binding)
|
49
|
-
end
|
50
|
-
|
51
|
-
def render_class_method(klass, method)
|
52
|
-
tpl = get_template('method.erb')
|
53
|
-
@klass = klass
|
54
|
-
@method = method
|
55
|
-
begin
|
56
|
-
@description = @iconv.iconv(method.comment.accept(@formatter))
|
57
|
-
rescue
|
58
|
-
@description = ""
|
59
|
-
end
|
60
|
-
tpl.result(binding)
|
61
|
-
end
|
62
|
-
|
63
|
-
puts "Loading Ruby documentation"
|
64
|
-
|
65
|
-
classes = {}
|
66
|
-
class_methods = {}
|
67
|
-
instance_methods = {}
|
68
|
-
stores = []
|
69
|
-
class_count = 0
|
70
|
-
count = 0
|
71
|
-
|
72
|
-
@formatter = RDoc::Markup::ToHtml.new
|
73
|
-
@iconv = Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
74
|
-
|
75
|
-
RDoc::RI::Paths.each(true, true, true, true) do |path, type|
|
76
|
-
$stderr.puts path
|
77
|
-
store = RDoc::RI::Store.new(path, type)
|
78
|
-
store.load_cache
|
79
|
-
stores << store
|
80
|
-
class_count += store.modules.count
|
81
|
-
end
|
82
|
-
|
83
|
-
stores.each do |store|
|
84
|
-
store.modules.each do |name|
|
85
|
-
count += 1
|
86
|
-
$stderr << "Parse [#{count}/#{class_count}]...\r"
|
87
|
-
klass = store.load_class(name)
|
88
|
-
oldklass = classes[name]
|
89
|
-
unless oldklass.nil? || oldklass.method_list.count < klass.method_list.count
|
90
|
-
$stderr.puts "Skipping #{name}..."
|
91
|
-
next
|
92
|
-
end
|
93
|
-
classes[name] = klass
|
94
|
-
klass.method_list.each_index do |index|
|
95
|
-
method = klass.method_list[index]
|
96
|
-
begin
|
97
|
-
method = store.load_method(name, "#{method.singleton ? '::' : '#'}#{method.name}")
|
98
|
-
klass.method_list[index] = method
|
99
|
-
rescue Errno::ENOENT => e
|
100
|
-
$stderr.puts e
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
puts "Building XML files from sources"
|
107
|
-
|
108
|
-
@classes = []
|
109
|
-
@methods = []
|
110
|
-
count = 0
|
111
|
-
|
112
|
-
classes.each do |name, klass|
|
113
|
-
count += 1
|
114
|
-
$stderr << "Render [#{count}/#{class_count}]...\r"
|
115
|
-
@classes << render_class(klass)
|
116
|
-
klass.method_list.each { |method| @methods << render_class_method(klass, method) }
|
117
|
-
end
|
118
|
-
|
119
|
-
File.open('./Ruby.xml', 'w') { |file| file.puts get_template('dictionary.erb').result(binding) }
|
120
|
-
|
121
|
-
puts "Dictionary XML file generation complete"
|
data/templates/class.erb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
<d:entry id="class_<%= @class.object_id.to_s(36) %>" d:title="<%= @class.full_name.escape %>">
|
2
|
-
<d:index d:value="<%= @class.full_name.escape %>"/>
|
3
|
-
<d:index d:value="<%= @class.name.escape %>"/>
|
4
|
-
<h1><%= @class.full_name.escape %></h1>
|
5
|
-
<% unless @description.empty? %>
|
6
|
-
<%= @description %>
|
7
|
-
<% end %>
|
8
|
-
|
9
|
-
<% unless @class_methods.empty? %>
|
10
|
-
<h3>Class methods</h3>
|
11
|
-
<ul class="classmethods">
|
12
|
-
<% for method in @class_methods %>
|
13
|
-
<li><a href="x-dictionary:r:method_<%= method.object_id.to_s(36) %>:org.ruby-lang.Dictionary"><%= method.name.escape %></a></li>
|
14
|
-
<% end %>
|
15
|
-
</ul>
|
16
|
-
<% end %>
|
17
|
-
|
18
|
-
<% unless @instance_methods.empty? %>
|
19
|
-
<h3>Instance methods</h3>
|
20
|
-
<ul class="instancemethods">
|
21
|
-
<% for method in @instance_methods %>
|
22
|
-
<li><a href="x-dictionary:r:method_<%= method.object_id.to_s(36) %>:org.ruby-lang.Dictionary"><%= method.name.escape %></a></li>
|
23
|
-
<% end %>
|
24
|
-
</ul>
|
25
|
-
<% end %>
|
26
|
-
|
27
|
-
<% unless @class.constants.empty? %>
|
28
|
-
<h3>Constants</h3>
|
29
|
-
<ul class="constants">
|
30
|
-
<% for constant in @class.constants %>
|
31
|
-
<li><tt><%= constant.name.escape %><% unless constant.value.nil? %>= <%= constant.value.escape %><% end %></tt> <% if constant.comment.respond_to?(:accept) %><%= @iconv.iconv(constant.comment.accept(@formatter)) %><% end %></li>
|
32
|
-
<% end %>
|
33
|
-
</ul>
|
34
|
-
<% end %>
|
35
|
-
|
36
|
-
<% unless @class.attributes.empty? %>
|
37
|
-
<h3>Attributes</h3>
|
38
|
-
<ul class="attributes">
|
39
|
-
<% for attrib in @class.attributes %>
|
40
|
-
<li><span class="access <%= attrib.rw.downcase %>access"> <%= attrib.rw %> </span> <%= attrib.name.escape %> <% if attrib.comment.respond_to?(:accept) %><%= @iconv.iconv(attrib.comment.accept(@formatter)) %><% end %></li>
|
41
|
-
<% end %>
|
42
|
-
</ul>
|
43
|
-
<% end %>
|
44
|
-
</d:entry>
|
data/templates/dictionary.erb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<d:dictionary xmlns="http://www.w3.org/1999/xhtml" xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng">
|
3
|
-
<% for cls in @classes %>
|
4
|
-
<%= cls %>
|
5
|
-
<% end %>
|
6
|
-
<% for mthd in @methods %>
|
7
|
-
<%= mthd %>
|
8
|
-
<% end %>
|
9
|
-
</d:dictionary>
|
data/templates/method.erb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
<d:entry id="method_<%= @method.object_id.to_s(36) %>" d:title="<%= @method.name.escape %>">
|
2
|
-
<d:index d:value="<%= @method.full_name.escape %>"/>
|
3
|
-
<d:index d:value="<%= @method.name.escape %>"/>
|
4
|
-
<h1><a href="x-dictionary:r:class_<%= @class.object_id.to_s(36) %>:org.ruby-lang.Dictionary"><%= @class.full_name.escape %></a> <span class="methodtype"> <%= @method.singleton ? '::' : '#' %> </span> <%= @method.name.escape %> <span class="visibility">(<%= @method.visibility %>)</span></h1>
|
5
|
-
<% unless @method.arglists.nil? %><p class="signatures"><%= @method.arglists.escape %></p><% end %>
|
6
|
-
<% unless !@method.respond_to?(:aliases) || @method.aliases.empty? %><p>Aliases: <%= @method.aliases.map {|a| a.new_name }.join(", ").escape %></p><% end %>
|
7
|
-
<% unless !@method.respond_to?(:is_alias_for) || @method.is_alias_for.nil? %><p>Alias for: <%= @method.is_alias_for.escape %></p><% end %>
|
8
|
-
<% unless @description.empty? %>
|
9
|
-
<%= @description %>
|
10
|
-
<% end %>
|
11
|
-
</d:entry>
|