rtypeset 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +18 -4
- data/VERSION +1 -1
- data/lib/typeset.rb +20 -12
- data/lib/typeset/hanging_punctuation.rb +10 -24
- data/lib/typeset/hyphenate.rb +1 -1
- data/rtypeset.gemspec +84 -0
- data/test/helper.rb +2 -0
- data/test/test_typeset.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c6a2fbd26527d3299578780c904e7912d54b5d8
|
4
|
+
data.tar.gz: 88cabe98ef680e1fd514cb5e31355036f243ea0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4502d70a2721ca59b1a30ce00fdb1f149188cbde94db7161fd3ff3ea3823bcaa990dd3052d5242c6b9373ad6dc9461422f1b78c15653b2c94031cbb4decacd0e
|
7
|
+
data.tar.gz: f94bf56385b52360b2307235b6f5beb789014dc05c01ae12d70a6b463263b08a64c4ab76e708a47e1b4f8c9e0d0bc0ba8dc2dd4ae684daf82ff22f99df4a7ff8
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# An HTML pre-processor for web typography
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/rtypeset)
|
3
4
|
[](https://travis-ci.org/doches/rtypeset)
|
4
|
-
[](https://inch-ci.org/github/doches/rtypeset)
|
6
|
+
[](https://codeclimate.com/github/doches/rtypeset)
|
7
|
+
[](https://codeclimate.com/github/doches/rtypeset/coverage)
|
5
8
|
|
6
9
|
a pure Ruby typographic pre-processor for HTML inspired by [Typeset.js](https://github.com/davidmerfield/Typeset) that gives you:
|
7
10
|
|
@@ -32,11 +35,22 @@ HTML:
|
|
32
35
|
# Output beautifully-formatted HTML
|
33
36
|
puts Typeset.typeset(raw_html)
|
34
37
|
|
35
|
-
|
36
|
-
|
38
|
+
### Customisation
|
39
|
+
|
40
|
+
Want more control over your typesetting?
|
41
|
+
|
42
|
+
#### Disabling Features
|
43
|
+
|
44
|
+
You can selectively disable Typeset features by passing in an options hash to `#typeset`:
|
37
45
|
|
38
46
|
# Disable hyphenation and small caps conversion.
|
39
47
|
options = {:disable => [:hyphenate, :small-caps]}
|
40
48
|
Typeset.typeset(raw_html, options)
|
41
49
|
|
42
|
-
The full list of
|
50
|
+
The full list of modules is: `:quotes`, `:hanging_punctuation`, `:spaces`, `:small_caps`, `:hyphenate`, `:ligatures` and `:punctuation`.
|
51
|
+
|
52
|
+
#### Hyphenation Language
|
53
|
+
|
54
|
+
If you're using hyphenation (it's on by default!) you may want to specify the language (the default is `en_us`):
|
55
|
+
|
56
|
+
Typeset.typeset(raw_html, {:language => "en_us"})
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/typeset.rb
CHANGED
@@ -29,20 +29,28 @@ module Typeset
|
|
29
29
|
return content.join("")
|
30
30
|
end
|
31
31
|
|
32
|
+
# The default typesetting methods and their configuration. Add new methods here
|
33
|
+
# in whatever order makes sense.
|
34
|
+
DefaultMethods = [
|
35
|
+
[:quotes, true],
|
36
|
+
[:hanging_punctuation, true],
|
37
|
+
[:spaces, true],
|
38
|
+
[:small_caps, true],
|
39
|
+
[:ligatures, false],
|
40
|
+
[:punctuation, false],
|
41
|
+
[:hyphenate, true]
|
42
|
+
]
|
43
|
+
|
44
|
+
DefaultOptions = {
|
45
|
+
:disable => [],
|
46
|
+
:language => "en_us"
|
47
|
+
}
|
48
|
+
|
32
49
|
# The main entry point for Typeset. Pass in raw HTML or text, along with an
|
33
50
|
# optional options block.
|
34
|
-
def self.typeset(html, options=
|
35
|
-
methods =
|
36
|
-
|
37
|
-
[:hanging_punctuation, true],
|
38
|
-
[:spaces, true],
|
39
|
-
[:small_caps, true],
|
40
|
-
[:hyphenate, true],
|
41
|
-
[:ligatures, false],
|
42
|
-
[:punctuation, false]
|
43
|
-
]
|
44
|
-
|
45
|
-
options[:disable] ||= []
|
51
|
+
def self.typeset(html, options=Typeset::DefaultOptions)
|
52
|
+
methods = Typeset::DefaultMethods.dup
|
53
|
+
options[:disable] ||= DefaultOptions[:disable]
|
46
54
|
methods.reject! { |method| options[:disable].include?(method[0]) }
|
47
55
|
|
48
56
|
methods.each do |func, use_text_nodes|
|
@@ -30,30 +30,16 @@ module Typeset
|
|
30
30
|
aligns = "CcOoYTAVvWwY".split('')
|
31
31
|
words = text.split(/\s+/)
|
32
32
|
words.each_with_index do |word, i|
|
33
|
-
aligns
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if
|
38
|
-
words[i
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
if word[0] == punctuation
|
44
|
-
words[i] = "#{HangingPunctuation.pull('single', punctuation)}#{word.slice(1,word.length)}"
|
45
|
-
|
46
|
-
if not words[i-1].nil?
|
47
|
-
words[i-1] = "#{words[i-1]}#{HangingPunctuation.push('single')}"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
HangingPunctuation::DoubleWidth.each do |punctuation|
|
52
|
-
if word[0] == punctuation
|
53
|
-
words[i] = "#{HangingPunctuation.pull('double', punctuation)}#{word.slice(1,word.length)}"
|
54
|
-
|
55
|
-
if not words[i-1].nil?
|
56
|
-
words[i-1] = "#{words[i-1]}#{HangingPunctuation.push('double')}"
|
33
|
+
[[aligns, false],
|
34
|
+
[HangingPunctuation::SingleWidth, 'single'],
|
35
|
+
[HangingPunctuation::DoubleWidth, 'double']].each do |pair|
|
36
|
+
pair[0].each do |signal|
|
37
|
+
if word[0] == signal
|
38
|
+
words[i] = "#{HangingPunctuation.pull(pair[1], signal)}#{word.slice(1,word.length)}"
|
39
|
+
|
40
|
+
if not words[i-1].nil?
|
41
|
+
words[i-1] = "#{words[i-1]}#{HangingPunctuation.push(pair[1] ? pair[1] : signal)}"
|
42
|
+
end
|
57
43
|
end
|
58
44
|
end
|
59
45
|
end
|
data/lib/typeset/hyphenate.rb
CHANGED
@@ -7,7 +7,7 @@ module Typeset
|
|
7
7
|
# Typeset.typeset("do hyphenation on this", {:language => "en_gb"})
|
8
8
|
def self.hyphenate(text, options)
|
9
9
|
options[:language] ||= 'en_us'
|
10
|
-
hyphen = Text::Hyphen.new(:language => options[:language])
|
10
|
+
hyphen = Text::Hyphen.new(:language => options[:language], :left => 0, :right => 0)
|
11
11
|
|
12
12
|
text = hyphen.visualise(text, "\u00AD")
|
13
13
|
|
data/rtypeset.gemspec
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: rtypeset 0.1.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "rtypeset"
|
9
|
+
s.version = "0.1.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Trevor Fountain"]
|
14
|
+
s.date = "2015-08-20"
|
15
|
+
s.description = "A pure Ruby implementation of Typeset.js, an HTML pre-processor for web typography"
|
16
|
+
s.email = "trevor@texasexpat.net"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".travis.yml",
|
24
|
+
"Gemfile",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"demo/demo.rb",
|
30
|
+
"demo/raw.html",
|
31
|
+
"demo/style.css",
|
32
|
+
"demo/typeset.css",
|
33
|
+
"index.html",
|
34
|
+
"lib/typeset.rb",
|
35
|
+
"lib/typeset/hanging_punctuation.rb",
|
36
|
+
"lib/typeset/hyphenate.rb",
|
37
|
+
"lib/typeset/ligatures.rb",
|
38
|
+
"lib/typeset/punctuation.rb",
|
39
|
+
"lib/typeset/quotes.rb",
|
40
|
+
"lib/typeset/small_caps.rb",
|
41
|
+
"lib/typeset/spaces.rb",
|
42
|
+
"rtypeset.gemspec",
|
43
|
+
"test/helper.rb",
|
44
|
+
"test/test_typeset.rb"
|
45
|
+
]
|
46
|
+
s.homepage = "http://github.com/doches/rtypeset"
|
47
|
+
s.licenses = ["MIT"]
|
48
|
+
s.rubygems_version = "2.4.7"
|
49
|
+
s.summary = "An HTML pre-processor for web typography"
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 4
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<text-hyphen>, ["~> 1.4"])
|
56
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 1.6"])
|
57
|
+
s.add_development_dependency(%q<minitest>, [">= 5.8.0"])
|
58
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
60
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
61
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
62
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<text-hyphen>, ["~> 1.4"])
|
65
|
+
s.add_dependency(%q<nokogiri>, [">= 1.6"])
|
66
|
+
s.add_dependency(%q<minitest>, [">= 5.8.0"])
|
67
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
71
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<text-hyphen>, ["~> 1.4"])
|
75
|
+
s.add_dependency(%q<nokogiri>, [">= 1.6"])
|
76
|
+
s.add_dependency(%q<minitest>, [">= 5.8.0"])
|
77
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
79
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
80
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
81
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
data/test/helper.rb
CHANGED
data/test/test_typeset.rb
CHANGED
@@ -9,7 +9,7 @@ class TestTypeset < Minitest::Test
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_quotes
|
12
|
-
assert_equal "“foo”", Typeset.typeset("\"foo\"", {:disable => [:hanging_punctuation]})
|
12
|
+
assert_equal "“foo”", Typeset.typeset("\"foo\"", {:disable => [:hanging_punctuation, :hyphenate]})
|
13
13
|
assert_equal "19′ 43.5″", Typeset.typeset("19\' 43.5\"")
|
14
14
|
end
|
15
15
|
|
@@ -28,7 +28,7 @@ class TestTypeset < Minitest::Test
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_small_caps
|
31
|
-
assert_equal "an <span class=\"small-caps\">FBI</span> agent", Typeset.typeset("an FBI agent")
|
31
|
+
assert_equal "an <span class=\"small-caps\">FBI</span> agent", Typeset.typeset("an FBI agent", OptNoHyphenate)
|
32
32
|
assert_equal "The <span class=\"small-caps\">CIA</span>", Typeset.typeset("The CIA", {:disable => [:hanging_punctuation, :hyphenate]})
|
33
33
|
assert_equal "<span class=\"small-caps\">NCSA</span>", Typeset.typeset("NCSA", OptNoHyphenate)
|
34
34
|
assert_equal "<span class=\"small-caps\">NCSA</span> Mosaic", Typeset.typeset("NCSA Mosaic", OptNoHyphenate)
|
@@ -54,6 +54,6 @@ class TestTypeset < Minitest::Test
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_hyphenate
|
57
|
-
assert_equal "do hy\u00ADphen\u00ADation", Typeset.typeset("do hyphenation")
|
57
|
+
assert_equal "do hy\u00ADphen\u00ADation", Typeset.typeset("do hyphenation", Typeset::DefaultOptions)
|
58
58
|
end
|
59
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtypeset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor Fountain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: text-hyphen
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/typeset/quotes.rb
|
152
152
|
- lib/typeset/small_caps.rb
|
153
153
|
- lib/typeset/spaces.rb
|
154
|
+
- rtypeset.gemspec
|
154
155
|
- test/helper.rb
|
155
156
|
- test/test_typeset.rb
|
156
157
|
homepage: http://github.com/doches/rtypeset
|