typographic-unit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.1.0 2007-12-19
2
+
3
+ * Keita Yamaguchi:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Keita Yamaguchi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,26 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/typographic-unit.rb
9
+ lib/typographic-unit/version.rb
10
+ log/debug.log
11
+ script/destroy
12
+ script/generate
13
+ script/txt2html
14
+ setup.rb
15
+ spec/spec.opts
16
+ spec/spec_helper.rb
17
+ spec/typographic-unit_spec.rb
18
+ tasks/deployment.rake
19
+ tasks/environment.rake
20
+ tasks/rspec.rake
21
+ tasks/website.rake
22
+ website/index.html
23
+ website/index.txt
24
+ website/javascripts/rounded_corners_lite.inc.js
25
+ website/stylesheets/screen.css
26
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,27 @@
1
+ =README
2
+
3
+ TypographicUnit is a library for converting between typographic units according
4
+ to TeX.
5
+
6
+ == Units
7
+
8
+ * TeX Scaled Point(sp)
9
+ * TeX Point(pt)
10
+ * Pica(pt)
11
+ * Inch(in)
12
+ * TeX Big Point(bp)
13
+ * PostScript Point(ps_pt)
14
+ * Meter(m)
15
+ * Centimeter(cm)
16
+ * Milimeter(mm)
17
+ * Didot Point(dd)
18
+ * Cicero(cc)
19
+ * Japanese Q(q)
20
+ * JIS Point(jis_q)
21
+
22
+ == Links
23
+
24
+ * http://typographicunit.rubyforge.org/
25
+ * http://rubyforge.org/projects/typographicunit/
26
+
27
+ Copyright (C) 2007 Keita Yamaguchi(keita.yamaguchi@gmail.com)
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'typographic-unit/version'
2
+
3
+ AUTHOR = 'Keita Yamaguchi' # can also be an array of Authors
4
+ EMAIL = "keita.yamaguchi@gmail.com"
5
+ DESCRIPTION = "TypographicUnit is a library for converting between typographic units according to TeX."
6
+ GEM_NAME = 'typographic-unit' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'typographicunit' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = TypographicUnit::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'TypographicUnit documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.author = AUTHOR
52
+ p.description = DESCRIPTION
53
+ p.email = EMAIL
54
+ p.summary = DESCRIPTION
55
+ p.url = HOMEPATH
56
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
+ p.test_globs = ["test/**/test_*.rb"]
58
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
+
60
+ # == Optional
61
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
62
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
+
64
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
+
66
+ end
67
+
68
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ PATH = RUBYFORGE_PROJECT
70
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
71
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'typographic-unit'
@@ -0,0 +1,9 @@
1
+ module TypographicUnit
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,240 @@
1
+ require "rational"
2
+
3
+ module TypographicUnit
4
+ Table = Hash.new
5
+
6
+ def self.open #:nodoc:
7
+ Table.values.each do |unit|
8
+ ::Numeric.instance_eval do
9
+ define_method(unit.short) do
10
+ unit.new(self)
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ class Unit < ::Numeric
17
+ def self.register(short, unit)
18
+ TypographicUnit::Table[short] = unit
19
+ end
20
+
21
+ def self.unit(short, base, size)
22
+ @short = short
23
+ @base = base
24
+ @size = size
25
+ register(short, self)
26
+ end
27
+
28
+ def self.short; @short; end
29
+ def self.base; @base; end
30
+ def self.size; @size; end
31
+
32
+ attr_reader :value
33
+
34
+ def initialize(value)
35
+ unless value.kind_of?(Numeric) and not(value.kind_of?(Unit))
36
+ raise ArgumentError.new, value
37
+ end
38
+ @value = value
39
+ end
40
+
41
+ # Convert the value into scaled point.
42
+ def scaled_point
43
+ val = self.class.base.new(@value * self.class.size)
44
+ val.kind_of?(ScaledPoint) ? val : val.scaled_point
45
+ end
46
+
47
+ def <=>(other)
48
+ raise ArgumentError, other unless other.kind_of?(Unit)
49
+ self.scaled_point.value.to_i <=> other.scaled_point.value.to_i
50
+ end
51
+
52
+ # Convert the length into other unit
53
+ # other:: unit
54
+ def >>(other)
55
+ oclass = other.kind_of?(Symbol) ? Table[other] : other
56
+ u = oclass.new(1)
57
+ oclass.new((self.scaled_point.value / u.scaled_point.value).to_f)
58
+ end
59
+
60
+ def %(other)
61
+ case other
62
+ when Unit
63
+ self.class.new(@value % (other >> self.class).value)
64
+ when Integer, Float
65
+ self.class.new(@value % other)
66
+ else
67
+ raise ArgumentError, other
68
+ end
69
+ end
70
+
71
+ def div(other)
72
+ case other
73
+ when Unit
74
+ @value.div((other >> self.class).value)
75
+ when Integer, Float
76
+ @value.div(other)
77
+ else
78
+ raise ArgumentError, other
79
+ end
80
+ end
81
+
82
+ def quo(other)
83
+ case other
84
+ when Unit
85
+ @value.quo((other >> self.class).value)
86
+ when Integer, Float
87
+ @value.quo(other)
88
+ else
89
+ raise ArgumentError, other
90
+ end
91
+ end
92
+
93
+ def +@
94
+ self.class.new(+@value)
95
+ end
96
+
97
+ def -@
98
+ self.class.new(-@value)
99
+ end
100
+
101
+ def abs
102
+ self.class.new(@value.abs)
103
+ end
104
+
105
+ def +(other)
106
+ raise ArgumentError, other unless other.kind_of?(Unit)
107
+ self.class.new((@value + (other >> self.class).value).to_f)
108
+ end
109
+
110
+ def -(other)
111
+ raise ArgumentError, other unless other.kind_of?(Unit)
112
+ self.class.new((@value - (other >> self.class).value).to_f)
113
+ end
114
+
115
+ def *(other)
116
+ raise ArgumentError, other unless other.kind_of?(Integer) or other.kind_of?(Float)
117
+ self.class.new(@value * other)
118
+ end
119
+
120
+ def ceil
121
+ self.class.new(@value.ceil)
122
+ end
123
+
124
+ def floor
125
+ self.class.new(@value.floor)
126
+ end
127
+
128
+ def round
129
+ self.class.new(@value.round)
130
+ end
131
+
132
+ def truncate
133
+ self.class.new(@value.truncate)
134
+ end
135
+
136
+ def integer?
137
+ @value.integer?
138
+ end
139
+
140
+ def nonzero?
141
+ @value.nonzero?
142
+ end
143
+
144
+ def to_i
145
+ self.class.new(@value.to_i)
146
+ end
147
+
148
+ def to_f
149
+ self.class.new(@value.to_f)
150
+ end
151
+
152
+ def to_int
153
+ @value.to_i
154
+ end
155
+
156
+ def to_float
157
+ @value.to_f
158
+ end
159
+
160
+ def zero?
161
+ @value.zero?
162
+ end
163
+
164
+ def step(limit, _step=1)
165
+ step = _step.kind_of?(Unit) ? _step : self.class.new(_step)
166
+ @value.step(limit.value, (step >> self.class).value) do |n|
167
+ yield(self.class.new(n)) if block_given?
168
+ end
169
+ end
170
+
171
+ def to_s
172
+ @value.to_s + self.class.short.to_s
173
+ end
174
+
175
+ def inspect
176
+ "#<#{@value.to_s}#{self.class.short.to_s}>"
177
+ end
178
+
179
+ alias :eql? :==
180
+ alias :convert :>>
181
+ end
182
+
183
+ class ScaledPoint < Unit
184
+ unit :sp, self, 1
185
+ end
186
+
187
+ class TeXPoint < Unit
188
+ unit :pt, ScaledPoint, 65536
189
+ end
190
+
191
+ class Pica < Unit
192
+ unit :pc, TeXPoint, 12
193
+ end
194
+
195
+ class Inch < Unit
196
+ unit :in, TeXPoint, Rational(7227, 100)
197
+ end
198
+
199
+ class BigPoint < Unit
200
+ unit :bp, Inch, Rational(1, 72)
201
+ end
202
+
203
+ class PostScriptPoint < Unit
204
+ unit :ps_pt, BigPoint, 1
205
+ end
206
+
207
+ class Millimeter < Unit
208
+ unit :mm, Inch, Rational(10, 254)
209
+ end
210
+
211
+ class Centimeter < Unit
212
+ unit :cm, Millimeter, 10
213
+ end
214
+
215
+ class Meter < Unit
216
+ unit :m, Centimeter, 100
217
+ end
218
+
219
+ class DidotPoint < Unit
220
+ unit :dd, TeXPoint, Rational(1238, 1157)
221
+ end
222
+
223
+ class Cicero < Unit
224
+ unit :cc, DidotPoint, 12
225
+ end
226
+
227
+ # Japanese Q(級)
228
+ class Q < Unit
229
+ unit :q, Millimeter, Rational(25, 100)
230
+ end
231
+
232
+ # JIS point
233
+ class JISPoint < Unit
234
+ unit :jis_pt, Millimeter, Rational(3514, 10000)
235
+ end
236
+ end
237
+
238
+ require "typographic-unit/version"
239
+
240
+ TypographicUnit.open
data/log/debug.log ADDED
File without changes
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ begin
5
+ require 'newgem'
6
+ rescue LoadError
7
+ puts "\n\nGenerating the website requires the newgem RubyGem"
8
+ puts "Install: gem install newgem\n\n"
9
+ exit(1)
10
+ end
11
+ require 'redcloth'
12
+ require 'syntax/convertors/html'
13
+ require 'erb'
14
+ require File.dirname(__FILE__) + '/../lib/typographic-unit/version.rb'
15
+
16
+ version = TypographicUnit::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/typographicunit'
18
+
19
+ class Fixnum
20
+ def ordinal
21
+ # teens
22
+ return 'th' if (10..19).include?(self % 100)
23
+ # others
24
+ case self % 10
25
+ when 1: return 'st'
26
+ when 2: return 'nd'
27
+ when 3: return 'rd'
28
+ else return 'th'
29
+ end
30
+ end
31
+ end
32
+
33
+ class Time
34
+ def pretty
35
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
+ end
37
+ end
38
+
39
+ def convert_syntax(syntax, source)
40
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
+ end
42
+
43
+ if ARGV.length >= 1
44
+ src, template = ARGV
45
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
+
47
+ else
48
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
49
+ exit!
50
+ end
51
+
52
+ template = ERB.new(File.open(template).read)
53
+
54
+ title = nil
55
+ body = nil
56
+ File.open(src) do |fsrc|
57
+ title_text = fsrc.readline
58
+ body_text = fsrc.read
59
+ syntax_items = []
60
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
+ ident = syntax_items.length
62
+ element, syntax, source = $1, $2, $3
63
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
+ "syntax-temp-#{ident}"
65
+ }
66
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
+ body = RedCloth.new(body_text).to_html
68
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
+ end
70
+ stat = File.stat(src)
71
+ created = stat.ctime
72
+ modified = stat.mtime
73
+
74
+ $stdout << template.result(binding)