osx_dict 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/examples/simple.rb +15 -0
- data/lib/osx_dict.rb +81 -0
- data/lib/osx_dict/Dictionary.css +0 -0
- data/lib/osx_dict/Dictionary.xml.erb +11 -0
- data/lib/osx_dict/Info.plist.erb +35 -0
- data/lib/osx_dict/version.rb +3 -0
- data/osx_dict.gemspec +24 -0
- metadata +56 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
osx_dict
|
2
|
+
====
|
3
|
+
|
4
|
+
Make your own dictionary for MacOSX!
|
5
|
+
|
6
|
+
Install
|
7
|
+
----
|
8
|
+
|
9
|
+
gem install osx_dict
|
10
|
+
|
11
|
+
Example
|
12
|
+
----
|
13
|
+
|
14
|
+
require 'osx_dict'
|
15
|
+
|
16
|
+
dict = OSXDict::Dictionary.new(:id => 'com.example.Foo', :name => "Foo Dictionary", :filename => 'Foo Dict')
|
17
|
+
|
18
|
+
dict.add_entry(:id => 'foo', :title => 'Foo', :indexes => ['foo', 'Foo'], :body => <<BODY)
|
19
|
+
<h1>foo</h1>
|
20
|
+
<p>foo foo foo</p>
|
21
|
+
BODY
|
22
|
+
|
23
|
+
dict.add_entry(:id => 'bar', :title => 'Bar', :indexes => ['bar', 'Bar'], :body => <<BODY)
|
24
|
+
<h1>bar</h1>
|
25
|
+
<p>bar bar</p>
|
26
|
+
BODY
|
27
|
+
|
28
|
+
dict.make('./')
|
29
|
+
|
30
|
+
Copyright
|
31
|
+
----
|
32
|
+
|
33
|
+
Copyright (c) 2012 jugyo, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/examples/simple.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'osx_dict'
|
2
|
+
|
3
|
+
dict = OSXDict::Dictionary.new(:id => 'com.example.Foo', :name => "Foo Dictionary", :filename => 'Foo Dict')
|
4
|
+
|
5
|
+
dict.add_entry(:id => 'foo', :title => 'Foo', :indexes => ['foo', 'Foo'], :body => <<BODY)
|
6
|
+
<h1>foo</h1>
|
7
|
+
<p>foo foo foo</p>
|
8
|
+
BODY
|
9
|
+
|
10
|
+
dict.add_entry(:id => 'bar', :title => 'Bar', :indexes => ['bar', 'Bar'], :body => <<BODY)
|
11
|
+
<h1>bar</h1>
|
12
|
+
<p>bar bar</p>
|
13
|
+
BODY
|
14
|
+
|
15
|
+
dict.make
|
data/lib/osx_dict.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "osx_dict/version"
|
3
|
+
require "fileutils"
|
4
|
+
require "tmpdir"
|
5
|
+
require "erb"
|
6
|
+
|
7
|
+
module OSXDict
|
8
|
+
class Dictionary
|
9
|
+
attr_accessor :id, :filename, :name
|
10
|
+
|
11
|
+
def initialize(attrs)
|
12
|
+
attrs.each do |key, value|
|
13
|
+
__send__(:"#{key}=", value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_entry(options)
|
18
|
+
entries << OSXDict::Entry.new(options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def entries
|
22
|
+
@entries ||= []
|
23
|
+
end
|
24
|
+
|
25
|
+
def make(dest = './')
|
26
|
+
Dir.mktmpdir do |dir|
|
27
|
+
xml_filename = "#{dir}/#{name}Dictionary.xml"
|
28
|
+
plist_filename = "#{dir}/#{name}Info.plist"
|
29
|
+
css_filename = "#{template_dir}/Dictionary.css"
|
30
|
+
|
31
|
+
File.open(xml_filename, 'w') do |file|
|
32
|
+
file << to_xml
|
33
|
+
end
|
34
|
+
|
35
|
+
File.open(plist_filename, 'w') do |file|
|
36
|
+
file << to_plist
|
37
|
+
end
|
38
|
+
|
39
|
+
Dir.chdir(dir) do
|
40
|
+
run("/Developer/Extras/Dictionary Development Kit/bin/build_dict.sh",
|
41
|
+
"-c=0", filename, xml_filename, css_filename, plist_filename)
|
42
|
+
end
|
43
|
+
|
44
|
+
FileUtils.cp_r("#{dir}/objects/#{filename}.dictionary", dest)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_xml
|
49
|
+
erb = ERB.new(File.read("#{template_dir}/Dictionary.xml.erb"))
|
50
|
+
erb.result(binding)
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_plist
|
54
|
+
erb = ERB.new(File.read("#{template_dir}/Info.plist.erb"))
|
55
|
+
erb.result(binding)
|
56
|
+
end
|
57
|
+
|
58
|
+
def run(*cmd)
|
59
|
+
abort "command failed" unless system(*cmd)
|
60
|
+
end
|
61
|
+
|
62
|
+
def template_dir
|
63
|
+
File.expand_path('../osx_dict', __FILE__)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Entry
|
68
|
+
attr_accessor :id, :title, :body
|
69
|
+
attr_writer :indexes
|
70
|
+
|
71
|
+
def initialize(attrs)
|
72
|
+
attrs.each do |key, value|
|
73
|
+
__send__(:"#{key}=", value)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def indexes
|
78
|
+
@indexes ||= []
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
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
|
+
<% entries.each do |entry| %>
|
4
|
+
<d:entry id="<%= entry.id %>" d:title="<%= entry.title %>">
|
5
|
+
<% entry.indexes.each do |index| %>
|
6
|
+
<d:index d:value="<%= index %>"/>
|
7
|
+
<% end %>
|
8
|
+
<%= entry.body %>
|
9
|
+
</d:entry>
|
10
|
+
<% end %>
|
11
|
+
</d:dictionary>
|
@@ -0,0 +1,35 @@
|
|
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><%= id %></string>
|
9
|
+
<key>CFBundleName</key>
|
10
|
+
<string><%= name %></string>
|
11
|
+
<key>CFBundleShortVersionString</key>
|
12
|
+
<string>1.0</string>
|
13
|
+
<key>DCSDictionaryCopyright</key>
|
14
|
+
<string>Copyright © 2007 Apple Inc.</string>
|
15
|
+
<key>DCSDictionaryManufacturerName</key>
|
16
|
+
<string>Apple Inc.</string>
|
17
|
+
<key>DCSDictionaryFrontMatterReferenceID</key>
|
18
|
+
<string>front_back_matter</string>
|
19
|
+
<key>DCSDictionaryPrefsHTML</key>
|
20
|
+
<string><%= name %>Dictionary_prefs.html</string>
|
21
|
+
<key>DCSDictionaryXSL</key>
|
22
|
+
<string><%= name %>Dictionary.xsl</string>
|
23
|
+
<key>DCSDictionaryDefaultPrefs</key>
|
24
|
+
<dict>
|
25
|
+
<key>pronunciation</key>
|
26
|
+
<string>0</string>
|
27
|
+
<key>display-column</key>
|
28
|
+
<string>1</string>
|
29
|
+
<key>display-picture</key>
|
30
|
+
<string>1</string>
|
31
|
+
<key>version</key>
|
32
|
+
<string>1</string>
|
33
|
+
</dict>
|
34
|
+
</dict>
|
35
|
+
</plist>
|
data/osx_dict.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "osx_dict/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "osx_dict"
|
7
|
+
s.version = OSXDict::VERSION
|
8
|
+
s.authors = ["jugyo"]
|
9
|
+
s.email = ["jugyo.org@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/jugyo/osx_dict"
|
11
|
+
s.summary = %q{Make your own dictionary for MacOSX!}
|
12
|
+
s.description = %q{Dictionary maker for MacOSX Dictionary.app}
|
13
|
+
|
14
|
+
s.rubyforge_project = "osx_dict"
|
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
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: osx_dict
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jugyo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-31 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Dictionary maker for MacOSX Dictionary.app
|
15
|
+
email:
|
16
|
+
- jugyo.org@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- examples/simple.rb
|
26
|
+
- lib/osx_dict.rb
|
27
|
+
- lib/osx_dict/Dictionary.css
|
28
|
+
- lib/osx_dict/Dictionary.xml.erb
|
29
|
+
- lib/osx_dict/Info.plist.erb
|
30
|
+
- lib/osx_dict/version.rb
|
31
|
+
- osx_dict.gemspec
|
32
|
+
homepage: https://github.com/jugyo/osx_dict
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project: osx_dict
|
52
|
+
rubygems_version: 1.8.10
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Make your own dictionary for MacOSX!
|
56
|
+
test_files: []
|