rubydictionary 0.0.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/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ objects
2
+ .DS_Store
3
+ doc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rubydictionary.gemspec
4
+ gemspec
data/Makefile ADDED
@@ -0,0 +1,52 @@
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)
data/MyInfo.plist ADDED
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>English</string>
7
+ <key>CFBundleIdentifier</key>
8
+ <string>org.ruby-lang.Dictionary</string>
9
+ <key>CFBundleName</key>
10
+ <string>Ruby</string>
11
+ <key>CFBundleShortVersionString</key>
12
+ <string>1.0</string>
13
+ <key>DCSDictionaryCopyright</key>
14
+ <string>Copyright</string>
15
+ <key>DCSDictionaryManufacturerName</key>
16
+ <string>Ruby</string>
17
+ <key>DCSDictionaryFrontMatterReferenceID</key>
18
+ <string>front_back_matter</string>
19
+ <key>DCSDictionaryDefaultPrefs</key>
20
+ <dict>
21
+ <key>pronunciation</key>
22
+ <string>0</string>
23
+ <key>display-column</key>
24
+ <string>1</string>
25
+ <key>display-picture</key>
26
+ <string>1</string>
27
+ <key>version</key>
28
+ <string>1</string>
29
+ </dict>
30
+ </dict>
31
+ </plist>
data/README.markdown ADDED
@@ -0,0 +1,30 @@
1
+ This gem adds `rubydictionary` formatter to RDoc.
2
+
3
+ ## Prerequisites
4
+
5
+ You will need latest [*Xcode* developer tools](http://developer.apple.com/).
6
+
7
+ ## Install
8
+
9
+ gem install rubydictionary
10
+
11
+ ## Building dictionary
12
+
13
+ Create documentation from the source code like you normally would. Only do not forget to pass `--format=rubydictionary` option:
14
+
15
+ rdoc --format=rubydictionary ./sourcedir
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
27
+
28
+ # Links
29
+
30
+ * [Dictionary Services programming guide at Apple Developer site](http://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/DictionaryServicesProgGuide/index.html)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Ruby.css ADDED
@@ -0,0 +1,42 @@
1
+ @charset "UTF-8";
2
+ @namespace d url(http://www.apple.com/DTDs/DictionaryService-1.0.rng);
3
+
4
+ d|entry {
5
+ }
6
+
7
+ h1, h2, h3 {
8
+ font-family: 'Helvetica Neue', Helvetica, sans-serif;
9
+ text-shadow: 0px 0px 0px #000;
10
+ }
11
+
12
+ h1 { font-size: 150%; }
13
+ h1 .classname { font-size: 80%; }
14
+ h1 .methodtype { font-size: 80%; }
15
+ h1 .visibility { font-size: 70%; font-weight: normal; }
16
+
17
+ ul.classmethods li { list-style-type: circle; }
18
+ ul.instancemethods li { list-style-type: disc; }
19
+ ul.attributes li { list-style-type: none; }
20
+
21
+ .access { background-color: #000; color: #fff; border-radius: 5px; padding: 0 0 0 2px; text-align: center; font-size: 70%; margin-right: 5px; }
22
+ .raccess { background-color: #666; }
23
+
24
+ hr { border: none; border-bottom: 1px solid #ddd; }
25
+
26
+ tt,
27
+ pre,
28
+ p.signatures {
29
+ font-family: Monaco;
30
+ font-size: 12px;
31
+ }
32
+
33
+ pre {
34
+ padding: 10px;
35
+ background-color: #eee;
36
+ border: 1px solid #ddd;
37
+ }
38
+
39
+ a {
40
+ color: #555;
41
+ text-decoration: none;
42
+ }
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby -KU
2
+
3
+ require File.expand_path('../../lib/rubydictionary', __FILE__)
4
+
5
+ ARGV.push('--format=rubydictionary') if ARGV.grep(/\A(-f|--fmt|--format|-r|-R|--ri|--ri-site)\b/).empty?
6
+ r = RDoc::RDoc.new
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}}
@@ -0,0 +1,121 @@
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("&", "&amp;").gsub("<", "&lt;").gsub(">", "&gt;").gsub("'", "&apos;").gsub("\"", "&quot;")
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"
@@ -0,0 +1,99 @@
1
+ require 'rdoc'
2
+ require 'rdoc/rdoc'
3
+ require 'rdoc/generator'
4
+
5
+ require 'nokogiri'
6
+
7
+ class Rubydictionary::Generator
8
+
9
+ RDoc::RDoc.add_generator self
10
+
11
+ XMLNS = 'http://www.w3.org/1999/xhtml'
12
+
13
+ XMLNS_D = 'http://www.apple.com/DTDs/DictionaryService-1.0.rng'
14
+
15
+ def self.setup_options(options)
16
+ end
17
+
18
+ def initialize(options)
19
+ end
20
+
21
+ def generate(top_levels)
22
+
23
+ builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
24
+ xml.send('dictionary', 'xmlns' => XMLNS, 'xmlns:d' => XMLNS_D) do
25
+ xml.parent.namespace = xml.parent.namespace_definitions.first
26
+
27
+ RDoc::TopLevel.all_classes.each do |clazz|
28
+ append_class_entry(clazz, xml)
29
+ end
30
+ end
31
+ end
32
+
33
+ puts "Writing into Ruby.xml..."
34
+ File.open('Ruby.xml', 'w') { |f| f << builder.to_xml }
35
+ end
36
+
37
+ def class_dir
38
+ 'classes'
39
+ end
40
+
41
+ private
42
+
43
+ # <d:entry id="activerecord_base" d:title="ActiveRecord::Base">
44
+ # <d:index d:value="ActiveRecord::Base"/>
45
+ # <d:index d:value="Base"/>
46
+ # <h1>ActiveRecord::Base</h1>
47
+ def append_class_entry(cls, xml)
48
+ xml.entry('id' => class_id(cls), 'd:title' => class_title(cls)) do
49
+ xml.index('d:value' => cls.full_name)
50
+ # xml.index('d:value' => class_index_name(clazz))
51
+
52
+ xml.h1(cls.full_name, :xmlns => XMLNS)
53
+
54
+ xml.div(:xmlns => XMLNS) do
55
+ xml.cdata cls.description
56
+ end
57
+
58
+ # Link to class methods
59
+ unless cls.class_method_list.empty?
60
+ xml.h3('Class methods', :xmlns => XMLNS)
61
+ xml.ul(:xmlns => XMLNS) do
62
+ cls.class_method_list.each do |mthd|
63
+ xml.li(:xmlns => XMLNS) do
64
+ xml.a(mthd.name, :href => method_url(mthd), :xmlns => XMLNS)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ # Link to instance methods
71
+ unless cls.instance_method_list.empty?
72
+ xml.h3('Instance methods', :xmlns => XMLNS)
73
+ xml.ul(:xmlns => XMLNS) do
74
+ cls.instance_method_list.each do |mthd|
75
+ xml.li(:xmlns => XMLNS) do
76
+ xml.a(mthd.name, :href => method_url(mthd), :xmlns => XMLNS)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def class_id(cls)
85
+ cls.full_name.downcase.gsub('::', '_')
86
+ end
87
+
88
+ def class_title(cls)
89
+ cls.full_name
90
+ end
91
+
92
+ def method_url(mthd)
93
+ "x-dictionary:r:method_#{method_id(mthd)}:org.ruby-lang.Dictionary"
94
+ end
95
+
96
+ def method_id(mthd)
97
+ mthd.name
98
+ end
99
+ end
@@ -0,0 +1,3 @@
1
+ module Rubydictionary
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'rubygems'
3
+ gem 'rdoc', '~> 3'
4
+
5
+ module Rubydictionary end
6
+
7
+ require 'rubydictionary/generator'
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'rubydictionary/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'rubydictionary'
7
+ s.version = Rubydictionary::VERSION
8
+ s.authors = ['Priit Haamer']
9
+ s.email = ['priit@fraktal.ee']
10
+ s.homepage = 'https://github.com/priithaamer/rubydictionary'
11
+ s.summary = %q{Adds "rubydictionary" formatter to RDoc}
12
+ s.description = %q{Builds dictionary files for Mac OS Dictionary.app of Ruby documentation using RDoc}
13
+
14
+ s.rubyforge_project = 'rubydictionary'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+ end
@@ -0,0 +1,44 @@
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>
@@ -0,0 +1,9 @@
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>
@@ -0,0 +1,11 @@
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>
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubydictionary
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Priit Haamer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-14 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Builds dictionary files for Mac OS Dictionary.app of Ruby documentation using RDoc
23
+ email:
24
+ - priit@fraktal.ee
25
+ executables:
26
+ - rubydictionary
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Makefile
35
+ - MyInfo.plist
36
+ - README.markdown
37
+ - Rakefile
38
+ - Ruby.css
39
+ - bin/rubydictionary
40
+ - dictionary_generator.rb
41
+ - lib/rubydictionary.rb
42
+ - lib/rubydictionary/generator.rb
43
+ - lib/rubydictionary/version.rb
44
+ - rubydictionary.gemspec
45
+ - templates/class.erb
46
+ - templates/dictionary.erb
47
+ - templates/method.erb
48
+ has_rdoc: true
49
+ homepage: https://github.com/priithaamer/rubydictionary
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project: rubydictionary
78
+ rubygems_version: 1.4.2
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Adds "rubydictionary" formatter to RDoc
82
+ test_files: []
83
+