typogruby 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- typogruby (1.0.10)
4
+ typogruby (1.0.11)
5
5
  rubypants
6
6
 
7
7
  GEM
data/HISTORY.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.11
4
+
5
+ * Excluded more typography-sensitive tags from filtering (thanks Justin Hileman)
6
+
3
7
  ## 1.0.10
4
8
 
5
9
  * Decoupled jeweler, which is no longer a dependency.
data/README.md CHANGED
@@ -57,9 +57,13 @@ See HISTORY.md for the complete changelog.
57
57
 
58
58
  By Arjan van der Gaag ([avdgaag @ github][6]) based on the hard work of lots of others. See LICENSE for license details (same as Ruby).
59
59
 
60
+ This gem includes contributions by:
61
+
62
+ * Justin Hileman
63
+
60
64
  [1]: http://jeffcroft.com/blog/2007/may/29/typogrify-easily-produce-web-typography-doesnt-suc/
61
65
  [2]: http://github.com/hunter/typography-helper
62
66
  [3]: http://code.google.com/p/typogrify
63
67
  [4]: http://avdgaag.github.com/typogruby
64
68
  [5]: http://github.com/avdgaag/Typography-tmbundle
65
- [6]: http://github.com/avdgaag
69
+ [6]: http://github.com/avdgaag
data/lib/typogruby.rb CHANGED
@@ -57,7 +57,7 @@ module Typogruby
57
57
  # @return [String] input text with ampersands wrapped
58
58
  def amp(text)
59
59
  # $1 is an excluded HTML tag, $2 is the part before the caps and $3 is the amp match
60
- ignore_scripts(text) do |t|
60
+ exclude_sensitive_tags(text) do |t|
61
61
  t.gsub(/<(code|pre).+?<\/\1>|(\s|&nbsp;)&(?:amp;|#38;)?(\s|&nbsp;)/) { |str|
62
62
  $1 ? str : $2 + '<span class="amp">&amp;</span>' + $3
63
63
  }.gsub(/(\w+)="(.*?)<span class="amp">&amp;<\/span>(.*?)"/, '\1="\2&amp;\3"')
@@ -108,7 +108,7 @@ module Typogruby
108
108
  # @param [String] text input text
109
109
  # @return [String] input text with non-breaking spaces inserted
110
110
  def widont(text)
111
- ignore_scripts(text) do |t|
111
+ exclude_sensitive_tags(text) do |t|
112
112
  t.gsub(%r{
113
113
  ((?:</?(?:a|em|span|strong|i|b)[^>]*>)|[^<>\s]) # must be proceeded by an approved inline opening or closing tag or a nontag/nonspace
114
114
  \s+ # the space to replace
@@ -144,7 +144,7 @@ module Typogruby
144
144
  # @param [String] text input text
145
145
  # @return [String] input text with caps wrapped
146
146
  def caps(text)
147
- ignore_scripts(text) do |t|
147
+ exclude_sensitive_tags(text) do |t|
148
148
  # $1 and $2 are excluded HTML tags, $3 is the part before the caps and $4 is the caps match
149
149
  t.gsub(%r{
150
150
  (?i:<(code|pre).+?</\1>)| # Ignore the contents of code and pre elements
@@ -190,7 +190,7 @@ module Typogruby
190
190
  # @return [String] input text with initial quotes wrapped
191
191
  def initial_quotes(text)
192
192
  # $1 is the initial part of the string, $2 is the quote or entitity, and $3 is the double quote
193
- ignore_scripts(text) do |t|
193
+ exclude_sensitive_tags(text) do |t|
194
194
  t.gsub(/((?:<(?:h[1-6]|p|li|dt|dd)[^>]*>|^)\s*(?:<(?:a|em|strong|span)[^>]*>)?)('|&#8216;|&lsquo;|("|&#8220;|&ldquo;))/) {$1 + "<span class=\"#{'d' if $3}quo\">#{$2}</span>"}
195
195
  end
196
196
  end
@@ -254,29 +254,36 @@ private
254
254
  end
255
255
  end
256
256
 
257
- # Hackish text filter that will make sure our text filters leave inline
258
- # javascript alone without resorting to a full-blown HTML parser.
257
+ # Hackish text filter that will make sure our text filters leave
258
+ # sensitive tags alone without resorting to a full-blown HTML parser.
259
+ #
260
+ # Sensitive tags are tags with literal contents, which we do not
261
+ # want to change. It currently ignores: <pre>, <code>, <kbd>, <math>
262
+ # and <script>.
259
263
  #
260
264
  # The idea is simple: every text filter is applied as a block to this
261
- # method. This will preprocess the text and replace any inline scripts
265
+ # method. This will preprocess the text and replace any sensitive tags
262
266
  # with a MD5 hash of its entire contents. Then the filter is called,
263
267
  # and then the hashes are replaced back with their original content.
264
268
  #
265
- # @yield [hashed_text] Hands you the input text with all script tags
269
+ # @yield [hashed_text] Hands you the input text with all sensitive tags
266
270
  # hashed. The block's result will be unhashed and then returned.
267
271
  # @param [String] text
268
- # @return [String] input with script tags restored
269
- def ignore_scripts(text)
270
- @ignored_scripts = {}
271
- modified_text = text.gsub(/<script[^>]*>.*?<\/script>/mi) do |script|
272
+ # @return [String] input with sensitive tags restored
273
+ def exclude_sensitive_tags(text)
274
+ @exluded_sensitive_tags = {}
275
+ modified_text = text.gsub(/<(#{EXCLUDED_TAGS .join('|')})[^>]*>.*?<\/\1>/mi) do |script|
272
276
  hash = Digest::MD5.hexdigest(script)
273
- @ignored_scripts[hash] = script
277
+ @exluded_sensitive_tags[hash] = script
274
278
  hash
275
279
  end
276
- yield(modified_text).gsub(/#{@ignored_scripts.keys.join('|')}/) do |h|
277
- @ignored_scripts.delete(h)
280
+ yield(modified_text).gsub(/#{@exluded_sensitive_tags.keys.join('|')}/) do |h|
281
+ @exluded_sensitive_tags.delete(h)
278
282
  end
279
283
  end
280
284
 
285
+ # Array of all the senstive tags that should be ignored by all the text filters.
286
+ EXCLUDED_TAGS = %w{pre code kbd math script}
287
+
281
288
  extend self
282
289
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Typogruby
2
- VERSION = '1.0.10'
2
+ VERSION = '1.0.11'
3
3
  end
@@ -97,4 +97,11 @@ class TestTypogruby < Test::Unit::TestCase
97
97
  assert_equal "Vari&euml;ren&hellip;", entities('Variëren…')
98
98
  assert_equal "<p>Ol&eacute;</p>", entities('<p>Olé</p>')
99
99
  end
100
+
101
+ def test_should_leave_sensitive_tags_alone
102
+ %w{script pre code kbd math}.each do |tag_name|
103
+ test_string = "<#{tag_name}>“CAPS & chårs” and widows</#{tag_name}>"
104
+ assert_equal test_string, improve(test_string)
105
+ end
106
+ end
100
107
  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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 10
10
- version: 1.0.10
9
+ - 11
10
+ version: 1.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Arjan van der Gaag
@@ -15,13 +15,14 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-15 00:00:00 +01:00
18
+ date: 2011-02-24 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rubypants
23
22
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ type: :runtime
24
+ name: rubypants
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
27
28
  - - ">="
@@ -30,12 +31,12 @@ dependencies:
30
31
  segments:
31
32
  - 0
32
33
  version: "0"
33
- type: :runtime
34
- version_requirements: *id001
34
+ requirement: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: yard
37
36
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
37
+ type: :development
38
+ name: yard
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
42
  - - ">="
@@ -44,12 +45,12 @@ dependencies:
44
45
  segments:
45
46
  - 0
46
47
  version: "0"
47
- type: :development
48
- version_requirements: *id002
48
+ requirement: *id002
49
49
  - !ruby/object:Gem::Dependency
50
- name: rake
51
50
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
51
+ type: :development
52
+ name: rake
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
54
  none: false
54
55
  requirements:
55
56
  - - ">="
@@ -58,12 +59,12 @@ dependencies:
58
59
  segments:
59
60
  - 0
60
61
  version: "0"
61
- type: :development
62
- version_requirements: *id003
62
+ requirement: *id003
63
63
  - !ruby/object:Gem::Dependency
64
- name: aruba
65
64
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
65
+ type: :development
66
+ name: aruba
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
68
  none: false
68
69
  requirements:
69
70
  - - ">="
@@ -72,12 +73,12 @@ dependencies:
72
73
  segments:
73
74
  - 0
74
75
  version: "0"
75
- type: :development
76
- version_requirements: *id004
76
+ requirement: *id004
77
77
  - !ruby/object:Gem::Dependency
78
- name: cucumber
79
78
  prerelease: false
80
- requirement: &id005 !ruby/object:Gem::Requirement
79
+ type: :development
80
+ name: cucumber
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
81
82
  none: false
82
83
  requirements:
83
84
  - - ">="
@@ -86,12 +87,12 @@ dependencies:
86
87
  segments:
87
88
  - 0
88
89
  version: "0"
89
- type: :development
90
- version_requirements: *id005
90
+ requirement: *id005
91
91
  - !ruby/object:Gem::Dependency
92
- name: rcov
93
92
  prerelease: false
94
- requirement: &id006 !ruby/object:Gem::Requirement
93
+ type: :development
94
+ name: rcov
95
+ version_requirements: &id006 !ruby/object:Gem::Requirement
95
96
  none: false
96
97
  requirements:
97
98
  - - ">="
@@ -100,12 +101,12 @@ dependencies:
100
101
  segments:
101
102
  - 0
102
103
  version: "0"
103
- type: :development
104
- version_requirements: *id006
104
+ requirement: *id006
105
105
  - !ruby/object:Gem::Dependency
106
- name: rspec
107
106
  prerelease: false
108
- requirement: &id007 !ruby/object:Gem::Requirement
107
+ type: :development
108
+ name: rspec
109
+ version_requirements: &id007 !ruby/object:Gem::Requirement
109
110
  none: false
110
111
  requirements:
111
112
  - - ">="
@@ -114,12 +115,12 @@ dependencies:
114
115
  segments:
115
116
  - 0
116
117
  version: "0"
117
- type: :development
118
- version_requirements: *id007
118
+ requirement: *id007
119
119
  - !ruby/object:Gem::Dependency
120
- name: bluecloth
121
120
  prerelease: false
122
- requirement: &id008 !ruby/object:Gem::Requirement
121
+ type: :development
122
+ name: bluecloth
123
+ version_requirements: &id008 !ruby/object:Gem::Requirement
123
124
  none: false
124
125
  requirements:
125
126
  - - ">="
@@ -128,8 +129,7 @@ dependencies:
128
129
  segments:
129
130
  - 0
130
131
  version: "0"
131
- type: :development
132
- version_requirements: *id008
132
+ requirement: *id008
133
133
  description: Improve web typography using various text filters. This gem prevents widows and applies markup to ampersans, consecutive capitals and initial quotes.
134
134
  email: arjan@arjanvandergaag.nl
135
135
  executables: