hgimenez-truncate_html 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.
- data/README.markdown +12 -4
- data/VERSION +1 -1
- data/lib/truncate_html/html_truncator.rb +3 -3
- data/spec/helpers/truncate_html_helper_spec.rb +1 -1
- data/spec/truncate_html/html_truncator_spec.rb +3 -27
- data/truncate_html.gemspec +3 -3
- metadata +3 -4
data/README.markdown
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
TruncateHtml
|
2
2
|
============
|
3
3
|
|
4
|
-
truncate_html is a Rails helper plugin that [cuts off](http://www.youtube.com/watch?v=6XG4DIOA7nU) a string of HTML and takes care of closing any lingering open tags. There are many possible solutions to this. This plugin does not have any dependencies, and does all it's work via regular expressions.
|
4
|
+
truncate_html is a Rails helper plugin that [cuts off](http://www.youtube.com/watch?v=6XG4DIOA7nU) a string of HTML and takes care of closing any lingering open tags. There are many possible solutions to this. This plugin does not have any dependencies, and does all it's work via [regular expressions](http://xkcd.com/208/).
|
5
5
|
|
6
6
|
The API is very similar to Rails' own truncate method.
|
7
7
|
|
@@ -26,10 +26,18 @@ A few notes:
|
|
26
26
|
Installation
|
27
27
|
------------
|
28
28
|
|
29
|
-
As a gem
|
30
|
-
<code>
|
29
|
+
#### As a gem
|
30
|
+
Add this to your <code>config/environment.rb</code>:
|
31
31
|
|
32
|
-
|
32
|
+
config.gem 'truncate_html',
|
33
|
+
:source => 'http://gemcutter.org'
|
34
|
+
|
35
|
+
Then either
|
36
|
+
<code>sudo rake gems:install</code>
|
37
|
+
or
|
38
|
+
<code>sudo gem install truncate_html</code>
|
39
|
+
|
40
|
+
#### As a plugin:
|
33
41
|
<code>script/plugin install git://github.com/hgimenez/truncate_html.git</code>
|
34
42
|
|
35
43
|
Issues
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -27,7 +27,7 @@ module TruncateHtml
|
|
27
27
|
result << str
|
28
28
|
else
|
29
29
|
result[-1] += options[:omission] unless options[:omission].nil?
|
30
|
-
@open_tags.
|
30
|
+
@open_tags.reverse_each do |open_tag|
|
31
31
|
result << matching_close_tag(open_tag)
|
32
32
|
end
|
33
33
|
break
|
@@ -52,11 +52,11 @@ module TruncateHtml
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def html_tag?(string)
|
55
|
-
|
55
|
+
string =~ /<\/?[^>]+>/ ? true : false
|
56
56
|
end
|
57
57
|
|
58
58
|
def open_tag?(html_tag)
|
59
|
-
|
59
|
+
html_tag =~ /<(?!(?:#{UNPAIRED_TAGS.join('|')}|\/))[^>]+>/i ? true : false
|
60
60
|
end
|
61
61
|
|
62
62
|
def remove_latest_open_tag(close_tag)
|
@@ -12,7 +12,7 @@ describe TruncateHtmlHelper do
|
|
12
12
|
|
13
13
|
context 'truncating in the middle of a link' do
|
14
14
|
before(:each) do
|
15
|
-
@html = '<div><ul><li>Look at <a href="foo">this</a> link
|
15
|
+
@html = '<div><ul><li>Look at <a href="foo">this</a> link </li></ul></div>'
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should truncate, and close the <a>, and close any remaining open tags' do
|
@@ -41,15 +41,15 @@ describe TruncateHtml::HtmlTruncator do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'should be true if the tag is an open tag, and has whitespace and html properties with either single or double quotes' do
|
44
|
-
@truncator.send(:open_tag?, ' <a href="
|
45
|
-
@truncator.send(:open_tag?, " <a href='
|
44
|
+
@truncator.send(:open_tag?, ' <a href="http://awesomeful.net">').should be_true
|
45
|
+
@truncator.send(:open_tag?, " <a href='http://awesomeful.net' >").should be_true
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should be false if the tag is a close tag' do
|
49
49
|
@truncator.send(:open_tag?, '</a>').should be_false
|
50
50
|
end
|
51
51
|
|
52
|
-
it 'should be false if the string
|
52
|
+
it 'should be false if the string is not an html tag' do
|
53
53
|
@truncator.send(:open_tag?, 'foo bar').should be_false
|
54
54
|
end
|
55
55
|
end
|
@@ -68,28 +68,4 @@ describe TruncateHtml::HtmlTruncator do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
#describe '#remove_open_tag' do
|
72
|
-
|
73
|
-
#before(:each) do
|
74
|
-
#@truncator = TruncateHtml::HtmlTruncator.new 'foo'
|
75
|
-
#@open_tags = ['<a>', '<p>', '<div>', '<h1>', '<div>']
|
76
|
-
#@truncator.instance_variable_set(:open_tags, @open_tags)
|
77
|
-
#end
|
78
|
-
|
79
|
-
#it 'should remove the latest matching tag' do
|
80
|
-
#@truncator.send(:remove_latest_open_tag, '</h1>').should == ['<a>', '<p>', '<div>', '<div>']
|
81
|
-
#@truncator.send(:remove_latest_open_tag, '</div>').should == ['<a>', '<p>', '<div>', '<h1>']
|
82
|
-
#end
|
83
|
-
|
84
|
-
#it 'should not modify @open_tags if the close tag parameter didn not match' do
|
85
|
-
#@truncator.send(:remove_latest_open_tag, '<strong>').should == @open_tags
|
86
|
-
#end
|
87
|
-
|
88
|
-
#it 'should raise an error if the close tag parameter is not an html tag' do
|
89
|
-
#lambda { @truncator.send(:remove_latest_open_tag, '<strong>') }.should raise_error
|
90
|
-
#end
|
91
|
-
|
92
|
-
#end
|
93
|
-
|
94
|
-
|
95
71
|
end
|
data/truncate_html.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{truncate_html}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["hgimenez"]
|
9
|
-
s.date = %q{2009-08-
|
9
|
+
s.date = %q{2009-08-25}
|
10
10
|
s.description = %q{Truncates html so you don't have to}
|
11
11
|
s.email = %q{harold.gimenez@gmail.com}
|
12
12
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hgimenez-truncate_html
|
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
|
- hgimenez
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -38,7 +38,6 @@ files:
|
|
38
38
|
- uninstall.rb
|
39
39
|
has_rdoc: false
|
40
40
|
homepage: http://github.com/hgimenez/truncate_html
|
41
|
-
licenses:
|
42
41
|
post_install_message:
|
43
42
|
rdoc_options:
|
44
43
|
- --charset=UTF-8
|
@@ -59,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
58
|
requirements: []
|
60
59
|
|
61
60
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.2.0
|
63
62
|
signing_key:
|
64
63
|
specification_version: 3
|
65
64
|
summary: Uses an API similar to Rails' truncate helper to truncate HTML and close any lingering open tags.
|