typogruby 1.0.2 → 1.0.3
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/README.md +30 -1
- data/VERSION +1 -1
- data/bin/typogruby +83 -0
- data/lib/typogruby.rb +1 -1
- data/test/test_typogruby.rb +1 -0
- metadata +8 -7
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Helps you improve your web typograpbhy with some standard text filters.
|
|
4
4
|
|
5
5
|
This project is based on Django's Typogrify, so the best introduction to read would be [Jeff Croft's][1].
|
6
6
|
|
7
|
-
I created this gem to easily share these text filters in some tiny Ruby projects, including a TextMate bundle. For production code I recommend checking out the originals first.
|
7
|
+
I created this gem to easily share these text filters in some tiny Ruby projects, including [a TextMate bundle][5]. For production code I recommend checking out the originals first.
|
8
8
|
|
9
9
|
## General Usage
|
10
10
|
|
@@ -23,6 +23,16 @@ Or, you can include the library in a helper or something:
|
|
23
23
|
include Typogruby
|
24
24
|
improve('Hello, world!')
|
25
25
|
|
26
|
+
See the [full API documentation][4] for more information. You could also use [this Textmate Bundle][5].
|
27
|
+
|
28
|
+
## From the command line
|
29
|
+
|
30
|
+
You can also use typogruby directly from the command line:
|
31
|
+
|
32
|
+
typogruby MY_FILE
|
33
|
+
|
34
|
+
This will output the contents of your file with all filters applied. Use `typogruby -h` for more information and options.
|
35
|
+
|
26
36
|
## References
|
27
37
|
|
28
38
|
* Based on [typography-helper][2]
|
@@ -32,6 +42,25 @@ Or, you can include the library in a helper or something:
|
|
32
42
|
[1]: http://jeffcroft.com/blog/2007/may/29/typogrify-easily-produce-web-typography-doesnt-suc/
|
33
43
|
[2]: http://github.com/hunter/typography-helper
|
34
44
|
[3]: http://code.google.com/p/typogrify
|
45
|
+
[4]: http://avdgaag.github.com/typogruby
|
46
|
+
[5]: http://github.com/avdgaag/Typography-tmbundle
|
47
|
+
|
48
|
+
## Changelog
|
49
|
+
|
50
|
+
### 1.0.3
|
51
|
+
|
52
|
+
* Bugfix: caps also ignores unequal but same excepted tags
|
53
|
+
* Feature: added command-line program
|
54
|
+
* Improved documentation
|
55
|
+
|
56
|
+
### 1.0.2
|
57
|
+
|
58
|
+
* Bugfix: initial_quotes also wraps named HTML entities
|
59
|
+
* Bugfix: caps no longer wraps consecutive numbers
|
60
|
+
|
61
|
+
### 1.0
|
62
|
+
|
63
|
+
* First release
|
35
64
|
|
36
65
|
## Note on Patches/Pull Requests
|
37
66
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
data/bin/typogruby
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby -rubygems
|
2
|
+
require 'typogruby'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
operations = [:smartypants, :initial_quotes, :amp, :widont, :caps]
|
6
|
+
explicit_on = []
|
7
|
+
explicit_off = []
|
8
|
+
|
9
|
+
OptionParser.new do |options|
|
10
|
+
options.banner = <<-EOS
|
11
|
+
Improves web typography with text filters.
|
12
|
+
|
13
|
+
By default all filters are applied. You can disable partical filters using
|
14
|
+
the --no switch, or run only specified filters.
|
15
|
+
|
16
|
+
Examples:
|
17
|
+
|
18
|
+
typogruby FILE Runs all filters
|
19
|
+
typogruby --no-widows FILE Runs all filters except for widows
|
20
|
+
typogruby -w FILE Runs only the filter for widows
|
21
|
+
typogruby --widows FILE Runs only the filter for widows
|
22
|
+
|
23
|
+
Usage: typogruby [options] filename [filename, ...]
|
24
|
+
EOS
|
25
|
+
|
26
|
+
options.separator ""
|
27
|
+
options.separator "Available options:"
|
28
|
+
|
29
|
+
options.on '-s', '--[no-]smartypants', 'Apply smartypants' do |v|
|
30
|
+
(v ? explicit_on : explicit_off) << :smartypants
|
31
|
+
end
|
32
|
+
|
33
|
+
options.on '-q', '--[no-]quotes', 'Wrap initial quotes' do |v|
|
34
|
+
(v ? explicit_on : explicit_off) << :initial_quotes
|
35
|
+
end
|
36
|
+
|
37
|
+
options.on '-a', '--[no-]amps', 'Wrap ampersands' do |v|
|
38
|
+
(v ? explicit_on : explicit_off) << :amp
|
39
|
+
end
|
40
|
+
|
41
|
+
options.on '-w', '--[no-]widows', 'Prevent widows' do |v|
|
42
|
+
(v ? explicit_on : explicit_off) << :widont
|
43
|
+
end
|
44
|
+
|
45
|
+
options.on '-c', '--[no-]caps', 'Wrap consecutive capitals' do |v|
|
46
|
+
(v ? explicit_on : explicit_off) << :caps
|
47
|
+
end
|
48
|
+
|
49
|
+
options.on_tail '-h', '--help', 'Show this message' do
|
50
|
+
$stderr.print options
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
|
54
|
+
options.on_tail '-v', '--version', 'Display version information' do
|
55
|
+
$stderr.print Typogruby.version
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
options.parse!
|
59
|
+
end
|
60
|
+
|
61
|
+
operations_todo = if explicit_off.any? && explicit_on.empty?
|
62
|
+
operations - explicit_off
|
63
|
+
elsif explicit_off.empty? && explicit_on.any?
|
64
|
+
explicit_on
|
65
|
+
else
|
66
|
+
operations
|
67
|
+
end
|
68
|
+
|
69
|
+
unless ARGV.any?
|
70
|
+
$stderr.puts 'No file specified'
|
71
|
+
exit 1
|
72
|
+
end
|
73
|
+
|
74
|
+
output = ARGV.inject('') do |output, filename|
|
75
|
+
begin
|
76
|
+
output + operations_todo.inject(File.read(filename)) { |t, o| Typogruby.send(o, t) }
|
77
|
+
rescue
|
78
|
+
$stderr.print "Error processing '#{filename}'"
|
79
|
+
output
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
$stdout.print output
|
data/lib/typogruby.rb
CHANGED
@@ -133,7 +133,7 @@ module Typogruby
|
|
133
133
|
# @return [String] input text with caps wrapped
|
134
134
|
def caps(text)
|
135
135
|
# $1 is an excluded HTML tag, $2 is the part before the caps and $3 is the caps match
|
136
|
-
text.gsub(/<(code|pre)
|
136
|
+
text.gsub(/<(?i)(code|pre)(?-i).+?<(?i)\/\1(?-i)>|(\s| |^|'|"|>)([A-Z\d][A-Z\d\.']{1,})(?!\w)/) do |str|
|
137
137
|
excluded, before, caps = $1, $2, $3
|
138
138
|
if excluded
|
139
139
|
str
|
data/test/test_typogruby.rb
CHANGED
@@ -25,6 +25,7 @@ class TestTypogruby < Test::Unit::TestCase
|
|
25
25
|
def test_should_ignore_special_case_caps
|
26
26
|
assert_equal 'It should ignore just numbers like 1234', caps('It should ignore just numbers like 1234')
|
27
27
|
assert_equal '<pre>CAPS</pre> more <span class="caps">CAPS</span>', caps("<pre>CAPS</pre> more CAPS")
|
28
|
+
assert_equal '<Pre>CAPS</PRE> with odd tag names <span class="caps">CAPS</span>', caps("<Pre>CAPS</PRE> with odd tag names CAPS")
|
28
29
|
assert_equal 'A message from <span class="caps">2KU2</span> with digits', caps("A message from 2KU2 with digits")
|
29
30
|
assert_equal 'Dotted caps followed by spaces should never include them in the wrap <span class="caps">D.O.T.</span> like so.', caps("Dotted caps followed by spaces should never include them in the wrap D.O.T. like so.")
|
30
31
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typogruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Arjan van der Gaag
|
@@ -15,8 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
19
|
-
default_executable:
|
18
|
+
date: 2010-07-27 00:00:00 +02:00
|
19
|
+
default_executable: typogruby
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: yard
|
@@ -48,8 +48,8 @@ dependencies:
|
|
48
48
|
version_requirements: *id002
|
49
49
|
description: Improve web typography using various text filters. This gem prevents widows and applies markup to ampersans, consecutive capitals and initial quotes.
|
50
50
|
email: arjan@arjanvandergaag.nl
|
51
|
-
executables:
|
52
|
-
|
51
|
+
executables:
|
52
|
+
- typogruby
|
53
53
|
extensions: []
|
54
54
|
|
55
55
|
extra_rdoc_files:
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- README.md
|
63
63
|
- Rakefile
|
64
64
|
- VERSION
|
65
|
+
- bin/typogruby
|
65
66
|
- lib/typogruby.rb
|
66
67
|
- test/helper.rb
|
67
68
|
- test/test_typogruby.rb
|