truncate_html 0.2.0 → 0.2.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.
data/Rakefile CHANGED
@@ -26,8 +26,8 @@ begin
26
26
  gem.homepage = "http://github.com/hgimenez/truncate_html"
27
27
  gem.authors = ["hgimenez"]
28
28
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
29
- Jeweler::GemcutterTasks.new
30
29
  end
30
+ Jeweler::GemcutterTasks.new
31
31
 
32
32
  rescue LoadError
33
33
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -27,7 +27,6 @@ module TruncateHtml
27
27
  end
28
28
  result << str
29
29
  else
30
- #result[-1] += options[:omission]
31
30
  result[-1] = result[-1].rstrip + options[:omission]
32
31
  @open_tags.reverse_each do |open_tag|
33
32
  result << matching_close_tag(open_tag)
@@ -39,7 +38,7 @@ module TruncateHtml
39
38
  end
40
39
 
41
40
  def html_tokens
42
- @original_html.scan(/<\/?[^>]+>|[\w\|`~!@#\$%^&*\(\)\-_\+=\[\]{}:;'",\.\/?]+|\s+/).map do
41
+ @original_html.scan(/(?:<script.*>.*<\/script>)+|<\/?[^>]+>|[\w\|`~!@#\$%^&*\(\)\-_\+=\[\]{}:;'",\.\/?]+|\s+/).map do
43
42
  |t| t.gsub(
44
43
  #remove newline characters
45
44
  /\n/,''
@@ -47,7 +46,7 @@ module TruncateHtml
47
46
  #clean out extra consecutive whitespace
48
47
  /\s+/, ' '
49
48
  )
50
- end
49
+ end
51
50
  end
52
51
 
53
52
  def html_tag?(string)
@@ -55,7 +54,7 @@ module TruncateHtml
55
54
  end
56
55
 
57
56
  def open_tag?(html_tag)
58
- html_tag =~ /<(?!(?:#{UNPAIRED_TAGS.join('|')}|\/))[^>]+>/i ? true : false
57
+ html_tag =~ /<(?!(?:#{UNPAIRED_TAGS.join('|')}|script|\/))[^>]+>/i ? true : false
59
58
  end
60
59
 
61
60
  def remove_latest_open_tag(close_tag)
@@ -21,6 +21,16 @@ describe TruncateHtmlHelper do
21
21
  end
22
22
  end
23
23
 
24
+ context 'the input html contains a script tag' do
25
+ before(:each) do
26
+ @input_html = "<p>I have a script <script type=text/javascript>document.write('lum dee dum');</script> and more text</p>"
27
+ @expected_out = "<p>I have a script <script type=text/javascript>document.write('lum dee dum');</script> and...</p>"
28
+ end
29
+ it 'treats the script tag as lengthless string' do
30
+ truncate_html(@input_html, :length => 23).should == @expected_out
31
+ end
32
+ end
33
+
24
34
  context 'truncating in the middle of a link' do
25
35
  before(:each) do
26
36
  @html = '<div><ul><li>Look at <a href="foo">this</a> link </li></ul></div>'
@@ -48,6 +48,10 @@ describe TruncateHtml::HtmlTruncator do
48
48
  it 'returns false if the string is not an html tag' do
49
49
  truncator.open_tag?('foo bar').should be_false
50
50
  end
51
+
52
+ it 'returns false if it is a <script> tag' do
53
+ truncator.open_tag?('<script>').should be_false
54
+ end
51
55
  end
52
56
 
53
57
  describe '#matching_close_tag' do
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{truncate_html}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["hgimenez"]
12
- s.date = %q{2009-11-23}
12
+ s.date = %q{2009-12-18}
13
13
  s.description = %q{Truncates html so you don't have to}
14
14
  s.email = %q{harold.gimenez@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truncate_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hgimenez
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-23 00:00:00 -05:00
12
+ date: 2009-12-18 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15