truncate_html 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/README.markdown +19 -8
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/init.rb +1 -1
- data/lib/truncate_html/configuration.rb +1 -1
- data/lib/truncate_html/html_truncator.rb +3 -3
- data/spec/truncate_html/html_truncator_spec.rb +2 -2
- data/truncate_html.gemspec +3 -3
- metadata +3 -3
data/History.txt
CHANGED
data/README.markdown
CHANGED
@@ -15,14 +15,25 @@ Example
|
|
15
15
|
|
16
16
|
A few notes:
|
17
17
|
|
18
|
-
*
|
19
|
-
|
20
|
-
* :omission => '...'
|
21
|
-
* By default, it will truncate on word boundry.
|
22
|
-
To truncate the HTML string strictly at the specified length, pass in the `:word_boundry => false` option.
|
18
|
+
* By default, it will truncate on word boundary.
|
19
|
+
To truncate the HTML string strictly at the specified length, pass in the `:word_boundary => false` option.
|
23
20
|
* If the input HTML is nil, it will return an empty string.
|
24
21
|
* The omission text's length does count toward the resulting string's length.
|
25
22
|
* `<script>` tags will pass right through - they will not count toward the resulting string's length, or be truncated.
|
23
|
+
* The default options are:
|
24
|
+
* :length => 100
|
25
|
+
* :omission => '...'
|
26
|
+
* :word_boundary => true
|
27
|
+
|
28
|
+
You may also set global configuration options.
|
29
|
+
For example, place the following on a sensible place,
|
30
|
+
like `config/initializers/truncate_html.rb`
|
31
|
+
|
32
|
+
TruncateHtml.configure do |config|
|
33
|
+
config.length = 50
|
34
|
+
config.omission = '...(continued)'
|
35
|
+
config.word_boundary = false
|
36
|
+
end
|
26
37
|
|
27
38
|
Installation
|
28
39
|
------------
|
@@ -41,10 +52,10 @@ or
|
|
41
52
|
#### As a plugin:
|
42
53
|
<code>script/plugin install git://github.com/hgimenez/truncate_html.git</code>
|
43
54
|
|
44
|
-
Issues
|
45
|
-
|
55
|
+
Issues or Suggestions
|
56
|
+
---------------------
|
46
57
|
|
47
|
-
Found an issue? Please report it on [Github's issue tracker](http://github.com/hgimenez/truncate_html/issues).
|
58
|
+
Found an issue or have a suggestion? Please report it on [Github's issue tracker](http://github.com/hgimenez/truncate_html/issues).
|
48
59
|
|
49
60
|
Testing
|
50
61
|
-------
|
data/Rakefile
CHANGED
@@ -43,7 +43,7 @@ begin
|
|
43
43
|
gem.description = %Q{Truncates html so you don't have to}
|
44
44
|
gem.email = "harold.gimenez@gmail.com"
|
45
45
|
gem.homepage = "http://github.com/hgimenez/truncate_html"
|
46
|
-
gem.authors = ["
|
46
|
+
gem.authors = ["Harold A. Gimenez"]
|
47
47
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
48
48
|
end
|
49
49
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/init.rb
CHANGED
@@ -8,7 +8,7 @@ module TruncateHtml
|
|
8
8
|
def truncate(options = {})
|
9
9
|
length = options[:length] || TruncateHtml.configuration.length
|
10
10
|
@omission = options[:omission] || TruncateHtml.configuration.omission
|
11
|
-
@
|
11
|
+
@word_boundary = (options.has_key?(:word_boundary) ? options[:word_boundary] : TruncateHtml.configuration.word_boundary)
|
12
12
|
@chars_remaining = length - @omission.length
|
13
13
|
@open_tags, @truncated_html = [], ['']
|
14
14
|
|
@@ -35,12 +35,12 @@ module TruncateHtml
|
|
35
35
|
remove_latest_open_tag(token)
|
36
36
|
end
|
37
37
|
else
|
38
|
-
@chars_remaining -= (@
|
38
|
+
@chars_remaining -= (@word_boundary ? token.length : token[0, @chars_remaining].length)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def append_to_result(token)
|
43
|
-
if @
|
43
|
+
if @word_boundary
|
44
44
|
@truncated_html << token
|
45
45
|
else
|
46
46
|
@truncated_html << token[0, @chars_remaining]
|
@@ -9,9 +9,9 @@ describe TruncateHtml::HtmlTruncator do
|
|
9
9
|
|
10
10
|
describe '#truncate' do
|
11
11
|
|
12
|
-
context 'when the
|
12
|
+
context 'when the word_boundary option is set to false' do
|
13
13
|
it 'truncates to the exact length specified' do
|
14
|
-
truncate('<div>123456789</div>', :length => 5, :omission => '', :
|
14
|
+
truncate('<div>123456789</div>', :length => 5, :omission => '', :word_boundary => false).should == '<div>12345</div>'
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
data/truncate_html.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{truncate_html}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["
|
12
|
-
s.date = %q{2010-02-
|
11
|
+
s.authors = ["Harold A. Gimenez"]
|
12
|
+
s.date = %q{2010-02-03}
|
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,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: truncate_html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Harold A. Gimenez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-03 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|