rubydictionary 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.markdown +4 -12
- data/bin/rubydictionary +1 -11
- data/{Ruby.css → lib/rdoc/generator/template/Dictionary.css} +0 -0
- data/{MyInfo.plist → lib/rdoc/generator/template/Dictionary.plist.erb} +3 -3
- data/lib/rubydictionary/generator.rb +86 -9
- data/lib/rubydictionary/version.rb +1 -1
- metadata +6 -7
- data/Makefile +0 -52
data/.gitignore
CHANGED
data/README.markdown
CHANGED
@@ -10,21 +10,13 @@ You will need latest [*Xcode* developer tools](http://developer.apple.com/).
|
|
10
10
|
|
11
11
|
## Building dictionary
|
12
12
|
|
13
|
-
|
13
|
+
Run `rubydictionary` in your source code directory. For example for source of Sinatra:
|
14
14
|
|
15
|
-
|
15
|
+
rubydictionary --format=rubydictionary --dict-name=Sinatra --dict-id=com.sinatrarb.Dictionary
|
16
16
|
|
17
|
-
If all goes well, you should have .dictionary file under ./doc directory. Drop it into `~/Library/Dictionaries/` folder.
|
18
|
-
|
19
|
-
## TODO
|
20
|
-
|
21
|
-
* Set RDoc options from command line:
|
22
|
-
** Dictionary name
|
23
|
-
** Dictionary title (optional, name is default)
|
24
|
-
* Dictinary builder script:
|
25
|
-
** Store RDoc results into xml file (into doc/ directory)
|
26
|
-
** Prepare .plist file
|
17
|
+
If all goes well, you should have Sinatra.dictionary file under ./doc/objects directory. Drop it into `~/Library/Dictionaries/` folder.
|
27
18
|
|
28
19
|
# Links
|
29
20
|
|
30
21
|
* [Dictionary Services programming guide at Apple Developer site](http://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/DictionaryServicesProgGuide/index.html)
|
22
|
+
* [https://github.com/breakpointer/ajax-rdoc](https://github.com/breakpointer/ajax-rdoc)
|
data/bin/rubydictionary
CHANGED
@@ -2,16 +2,6 @@
|
|
2
2
|
|
3
3
|
require File.expand_path('../../lib/rubydictionary', __FILE__)
|
4
4
|
|
5
|
-
ARGV.push('--format=
|
5
|
+
ARGV.push('--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
|
8
|
-
|
9
|
-
# TODO: this below must be moved into special generator class
|
10
|
-
dict_name = 'Ruby'
|
11
|
-
dict_src_path = File.expand_path('../../doc/Ruby.xml', __FILE__)
|
12
|
-
css_path = File.expand_path('../../Ruby.css', __FILE__)
|
13
|
-
plist_path = File.expand_path('../../MyInfo.plist', __FILE__)
|
14
|
-
|
15
|
-
dict_build_tool = "/Developer/Extras/Dictionary Development Kit/bin/build_dict.sh"
|
16
|
-
|
17
|
-
%x{"#{dict_build_tool}" #{dict_name} #{dict_src_path} #{css_path} #{plist_path}}
|
File without changes
|
@@ -5,15 +5,15 @@
|
|
5
5
|
<key>CFBundleDevelopmentRegion</key>
|
6
6
|
<string>English</string>
|
7
7
|
<key>CFBundleIdentifier</key>
|
8
|
-
<string
|
8
|
+
<string><%= bundle_identifier %></string>
|
9
9
|
<key>CFBundleName</key>
|
10
|
-
<string
|
10
|
+
<string><%= bundle_name %></string>
|
11
11
|
<key>CFBundleShortVersionString</key>
|
12
12
|
<string>1.0</string>
|
13
13
|
<key>DCSDictionaryCopyright</key>
|
14
14
|
<string>Copyright</string>
|
15
15
|
<key>DCSDictionaryManufacturerName</key>
|
16
|
-
<string
|
16
|
+
<string><%= bundle_name %></string>
|
17
17
|
<key>DCSDictionaryFrontMatterReferenceID</key>
|
18
18
|
<string>front_back_matter</string>
|
19
19
|
<key>DCSDictionaryDefaultPrefs</key>
|
@@ -1,37 +1,76 @@
|
|
1
|
+
require 'erb'
|
1
2
|
require 'rdoc'
|
2
3
|
require 'rdoc/rdoc'
|
3
4
|
require 'rdoc/generator'
|
4
5
|
|
5
6
|
require 'nokogiri'
|
6
7
|
|
7
|
-
class
|
8
|
+
class RDoc::Options
|
9
|
+
attr_accessor :dictionary_name
|
10
|
+
|
11
|
+
attr_accessor :dictionary_identifier
|
12
|
+
end
|
13
|
+
|
14
|
+
class RDoc::Generator::Dictionary
|
8
15
|
|
9
16
|
RDoc::RDoc.add_generator self
|
10
17
|
|
11
18
|
XMLNS = 'http://www.w3.org/1999/xhtml'
|
12
19
|
|
13
20
|
XMLNS_D = 'http://www.apple.com/DTDs/DictionaryService-1.0.rng'
|
14
|
-
|
21
|
+
|
22
|
+
# TODO: Raise an error when dictionary name is missing
|
15
23
|
def self.setup_options(options)
|
24
|
+
options.dictionary_identifier = 'com.priithaamer.Dictionary'
|
25
|
+
|
26
|
+
opt = options.option_parser
|
27
|
+
opt.separator "Dictionary generator options:"
|
28
|
+
opt.separator nil
|
29
|
+
opt.on('--dict-name=NAME', 'Title that appears in Dictionary.app') do |value|
|
30
|
+
options.dictionary_name = value
|
31
|
+
end
|
32
|
+
opt.on('--dict-id=IDENTIFIER',
|
33
|
+
'Dictionary bundle identifier, such as',
|
34
|
+
'org.rubyonrails.Rails'
|
35
|
+
) do |value|
|
36
|
+
options.dictionary_identifier = value
|
37
|
+
end
|
38
|
+
opt.separator nil
|
16
39
|
end
|
17
40
|
|
18
41
|
def initialize(options)
|
42
|
+
@options = options
|
43
|
+
@template_dir = Pathname.new(File.expand_path('../../rdoc/generator/template', __FILE__))
|
19
44
|
end
|
20
45
|
|
21
46
|
def generate(top_levels)
|
22
|
-
|
23
47
|
builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
24
48
|
xml.send('dictionary', 'xmlns' => XMLNS, 'xmlns:d' => XMLNS_D) do
|
25
49
|
xml.parent.namespace = xml.parent.namespace_definitions.first
|
26
50
|
|
27
51
|
RDoc::TopLevel.all_classes.each do |clazz|
|
28
52
|
append_class_entry(clazz, xml)
|
53
|
+
clazz.method_list.each do |mthd|
|
54
|
+
append_method_entry(mthd, xml)
|
55
|
+
end
|
29
56
|
end
|
30
57
|
end
|
31
58
|
end
|
32
59
|
|
33
|
-
|
34
|
-
|
60
|
+
xml_file = 'Dictionary.xml'
|
61
|
+
|
62
|
+
File.open(File.join(Pathname.pwd, xml_file), 'w') { |f| f << builder.to_xml }
|
63
|
+
|
64
|
+
dict_src_path = File.join(Pathname.pwd, xml_file)
|
65
|
+
|
66
|
+
css_path = File.join(@template_dir, 'Dictionary.css')
|
67
|
+
File.open(File.join(Pathname.pwd, 'Dictionary.plist'), 'w') { |f| f.write render_plist(@options.dictionary_name, bundle_identifier) }
|
68
|
+
|
69
|
+
plist_path = File.join(Pathname.pwd, 'Dictionary.plist')
|
70
|
+
|
71
|
+
dict_build_tool = "/Developer/Extras/Dictionary Development Kit/bin/build_dict.sh"
|
72
|
+
|
73
|
+
%x{"#{dict_build_tool}" #{@options.dictionary_name} #{dict_src_path} #{css_path} #{plist_path}}
|
35
74
|
end
|
36
75
|
|
37
76
|
def class_dir
|
@@ -52,7 +91,7 @@ class Rubydictionary::Generator
|
|
52
91
|
xml.h1(cls.full_name, :xmlns => XMLNS)
|
53
92
|
|
54
93
|
xml.div(:xmlns => XMLNS) do
|
55
|
-
xml
|
94
|
+
xml << cls.description
|
56
95
|
end
|
57
96
|
|
58
97
|
# Link to class methods
|
@@ -81,19 +120,57 @@ class Rubydictionary::Generator
|
|
81
120
|
end
|
82
121
|
end
|
83
122
|
|
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
|
+
def append_method_entry(mthd, xml)
|
135
|
+
xml.entry('id' => method_id(mthd), 'd:title' => method_title(mthd)) do
|
136
|
+
xml.index('d:value' => mthd.full_name)
|
137
|
+
xml.index('d:value' => mthd.name)
|
138
|
+
|
139
|
+
xml.h1(mthd.full_name, :xmlns => XMLNS)
|
140
|
+
|
141
|
+
xml.div(:xmlns => XMLNS) do
|
142
|
+
xml << mthd.description
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
84
147
|
def class_id(cls)
|
85
|
-
cls.
|
148
|
+
'class_' << cls.object_id.to_s(36)
|
86
149
|
end
|
87
150
|
|
88
151
|
def class_title(cls)
|
89
152
|
cls.full_name
|
90
153
|
end
|
91
154
|
|
155
|
+
def method_title(mthd)
|
156
|
+
# TODO: escape <>
|
157
|
+
mthd.name
|
158
|
+
end
|
159
|
+
|
92
160
|
def method_url(mthd)
|
93
|
-
"x-dictionary:r
|
161
|
+
"x-dictionary:r:#{method_id(mthd)}:#{bundle_identifier}"
|
94
162
|
end
|
95
163
|
|
96
164
|
def method_id(mthd)
|
97
|
-
mthd.
|
165
|
+
'method_' << mthd.object_id.to_s(36)
|
166
|
+
end
|
167
|
+
|
168
|
+
def bundle_identifier
|
169
|
+
@options.dictionary_identifier
|
170
|
+
end
|
171
|
+
|
172
|
+
# Render .plist file from erb template
|
173
|
+
def render_plist(bundle_name, bundle_identifier)
|
174
|
+
ERB.new(File.read(File.join(@template_dir, 'Dictionary.plist.erb'))).result(binding)
|
98
175
|
end
|
99
176
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydictionary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
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-
|
18
|
+
date: 2011-10-03 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -31,13 +31,12 @@ extra_rdoc_files: []
|
|
31
31
|
files:
|
32
32
|
- .gitignore
|
33
33
|
- Gemfile
|
34
|
-
- Makefile
|
35
|
-
- MyInfo.plist
|
36
34
|
- README.markdown
|
37
35
|
- Rakefile
|
38
|
-
- Ruby.css
|
39
36
|
- bin/rubydictionary
|
40
37
|
- dictionary_generator.rb
|
38
|
+
- lib/rdoc/generator/template/Dictionary.css
|
39
|
+
- lib/rdoc/generator/template/Dictionary.plist.erb
|
41
40
|
- lib/rubydictionary.rb
|
42
41
|
- lib/rubydictionary/generator.rb
|
43
42
|
- lib/rubydictionary/version.rb
|
data/Makefile
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Makefile
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
|
-
###########################
|
8
|
-
|
9
|
-
# You need to edit these values.
|
10
|
-
|
11
|
-
DICT_NAME = "Ruby"
|
12
|
-
DICT_SRC_PATH = Ruby.xml
|
13
|
-
CSS_PATH = Ruby.css
|
14
|
-
PLIST_PATH = MyInfo.plist
|
15
|
-
|
16
|
-
DICT_BUILD_OPTS =
|
17
|
-
# Suppress adding supplementary key.
|
18
|
-
# DICT_BUILD_OPTS = -s 0 # Suppress adding supplementary key.
|
19
|
-
|
20
|
-
###########################
|
21
|
-
|
22
|
-
# The DICT_BUILD_TOOL_DIR value is used also in "build_dict.sh" script.
|
23
|
-
# You need to set it when you invoke the script directly.
|
24
|
-
|
25
|
-
DICT_BUILD_TOOL_DIR = "/Developer/Extras/Dictionary Development Kit"
|
26
|
-
DICT_BUILD_TOOL_BIN = "$(DICT_BUILD_TOOL_DIR)/bin"
|
27
|
-
|
28
|
-
###########################
|
29
|
-
|
30
|
-
DICT_DEV_KIT_OBJ_DIR = ./objects
|
31
|
-
export DICT_DEV_KIT_OBJ_DIR
|
32
|
-
|
33
|
-
DESTINATION_FOLDER = ~/Library/Dictionaries
|
34
|
-
RM = /bin/rm
|
35
|
-
|
36
|
-
###########################
|
37
|
-
|
38
|
-
all:
|
39
|
-
"$(DICT_BUILD_TOOL_BIN)/build_dict.sh" $(DICT_BUILD_OPTS) $(DICT_NAME) $(DICT_SRC_PATH) $(CSS_PATH) $(PLIST_PATH)
|
40
|
-
echo "Done."
|
41
|
-
|
42
|
-
|
43
|
-
install:
|
44
|
-
echo "Installing into $(DESTINATION_FOLDER)".
|
45
|
-
mkdir -p $(DESTINATION_FOLDER)
|
46
|
-
ditto --noextattr --norsrc $(DICT_DEV_KIT_OBJ_DIR)/$(DICT_NAME).dictionary $(DESTINATION_FOLDER)/$(DICT_NAME).dictionary
|
47
|
-
touch $(DESTINATION_FOLDER)
|
48
|
-
echo "Done."
|
49
|
-
echo "To test the new dictionary, try Dictionary.app."
|
50
|
-
|
51
|
-
clean:
|
52
|
-
$(RM) -rf $(DICT_DEV_KIT_OBJ_DIR)
|