truncate_html 0.9.2 → 0.9.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b62f471b431ebc1482936c69165f634440e9f97
4
+ data.tar.gz: 55123d5396db552d9a0ab64b834de98afbe17688
5
+ SHA512:
6
+ metadata.gz: 9d0fcc597a3e4e8f39a08bf5e0cfda14cf692dc6753727a2812ffa9338e4567ecdbd51a7751f2a8649aca6a8fa8335c8c3609313673e9156225d7df9d5472590
7
+ data.tar.gz: 78b8a0c36a8bf3c12390d7606ee2a4561006787dd527c166fcdd9c8104c1cd7f23680e6cb337e6b0b9d47bfa680932666c87a39400c07374371381d2d1729e79
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
4
6
  - jruby-19mode # JRuby in 1.9 mode
@@ -1,92 +1,105 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- truncate_html (0.9.2)
4
+ truncate_html (0.9.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- abstract (1.0.0)
10
- actionmailer (3.0.3)
11
- actionpack (= 3.0.3)
12
- mail (~> 2.2.9)
13
- actionpack (3.0.3)
14
- activemodel (= 3.0.3)
15
- activesupport (= 3.0.3)
16
- builder (~> 2.1.2)
17
- erubis (~> 2.6.6)
18
- i18n (~> 0.4)
19
- rack (~> 1.2.1)
20
- rack-mount (~> 0.6.13)
21
- rack-test (~> 0.5.6)
22
- tzinfo (~> 0.3.23)
23
- activemodel (3.0.3)
24
- activesupport (= 3.0.3)
25
- builder (~> 2.1.2)
26
- i18n (~> 0.4)
27
- activerecord (3.0.3)
28
- activemodel (= 3.0.3)
29
- activesupport (= 3.0.3)
30
- arel (~> 2.0.2)
31
- tzinfo (~> 0.3.23)
32
- activeresource (3.0.3)
33
- activemodel (= 3.0.3)
34
- activesupport (= 3.0.3)
35
- activesupport (3.0.3)
36
- arel (2.0.7)
37
- builder (2.1.2)
38
- diff-lcs (1.1.3)
39
- erubis (2.6.6)
40
- abstract (>= 1.0.0)
41
- i18n (0.5.0)
42
- mail (2.2.15)
43
- activesupport (>= 2.3.6)
9
+ actionmailer (3.2.13)
10
+ actionpack (= 3.2.13)
11
+ mail (~> 2.5.3)
12
+ actionpack (3.2.13)
13
+ activemodel (= 3.2.13)
14
+ activesupport (= 3.2.13)
15
+ builder (~> 3.0.0)
16
+ erubis (~> 2.7.0)
17
+ journey (~> 1.0.4)
18
+ rack (~> 1.4.5)
19
+ rack-cache (~> 1.2)
20
+ rack-test (~> 0.6.1)
21
+ sprockets (~> 2.2.1)
22
+ activemodel (3.2.13)
23
+ activesupport (= 3.2.13)
24
+ builder (~> 3.0.0)
25
+ activerecord (3.2.13)
26
+ activemodel (= 3.2.13)
27
+ activesupport (= 3.2.13)
28
+ arel (~> 3.0.2)
29
+ tzinfo (~> 0.3.29)
30
+ activeresource (3.2.13)
31
+ activemodel (= 3.2.13)
32
+ activesupport (= 3.2.13)
33
+ activesupport (3.2.13)
34
+ i18n (= 0.6.1)
35
+ multi_json (~> 1.0)
36
+ arel (3.0.2)
37
+ builder (3.0.4)
38
+ diff-lcs (1.2.2)
39
+ erubis (2.7.0)
40
+ hike (1.2.1)
41
+ i18n (0.6.1)
42
+ journey (1.0.4)
43
+ json (1.7.7)
44
+ mail (2.5.3)
44
45
  i18n (>= 0.4.0)
45
46
  mime-types (~> 1.16)
46
47
  treetop (~> 1.4.8)
47
- mime-types (1.16)
48
- polyglot (0.3.1)
49
- rack (1.2.1)
50
- rack-mount (0.6.13)
51
- rack (>= 1.0.0)
52
- rack-test (0.5.7)
48
+ mime-types (1.22)
49
+ multi_json (1.7.2)
50
+ polyglot (0.3.3)
51
+ rack (1.4.5)
52
+ rack-cache (1.2)
53
+ rack (>= 0.4)
54
+ rack-ssl (1.3.3)
55
+ rack
56
+ rack-test (0.6.2)
53
57
  rack (>= 1.0)
54
- rails (3.0.3)
55
- actionmailer (= 3.0.3)
56
- actionpack (= 3.0.3)
57
- activerecord (= 3.0.3)
58
- activeresource (= 3.0.3)
59
- activesupport (= 3.0.3)
58
+ rails (3.2.13)
59
+ actionmailer (= 3.2.13)
60
+ actionpack (= 3.2.13)
61
+ activerecord (= 3.2.13)
62
+ activeresource (= 3.2.13)
63
+ activesupport (= 3.2.13)
60
64
  bundler (~> 1.0)
61
- railties (= 3.0.3)
62
- railties (3.0.3)
63
- actionpack (= 3.0.3)
64
- activesupport (= 3.0.3)
65
+ railties (= 3.2.13)
66
+ railties (3.2.13)
67
+ actionpack (= 3.2.13)
68
+ activesupport (= 3.2.13)
69
+ rack-ssl (~> 1.3.2)
65
70
  rake (>= 0.8.7)
66
- thor (~> 0.14.4)
67
- rake (0.8.7)
68
- rspec (2.9.0)
69
- rspec-core (~> 2.9.0)
70
- rspec-expectations (~> 2.9.0)
71
- rspec-mocks (~> 2.9.0)
72
- rspec-core (2.9.0)
73
- rspec-expectations (2.9.1)
74
- diff-lcs (~> 1.1.3)
75
- rspec-mocks (2.9.0)
76
- rspec-rails (2.9.0)
71
+ rdoc (~> 3.4)
72
+ thor (>= 0.14.6, < 2.0)
73
+ rake (10.0.4)
74
+ rdoc (3.12.2)
75
+ json (~> 1.4)
76
+ rspec-core (2.13.1)
77
+ rspec-expectations (2.13.0)
78
+ diff-lcs (>= 1.1.3, < 2.0)
79
+ rspec-mocks (2.13.0)
80
+ rspec-rails (2.13.0)
77
81
  actionpack (>= 3.0)
78
82
  activesupport (>= 3.0)
79
83
  railties (>= 3.0)
80
- rspec (~> 2.9.0)
81
- thor (0.14.6)
82
- treetop (1.4.9)
84
+ rspec-core (~> 2.13.0)
85
+ rspec-expectations (~> 2.13.0)
86
+ rspec-mocks (~> 2.13.0)
87
+ sprockets (2.2.2)
88
+ hike (~> 1.2)
89
+ multi_json (~> 1.0)
90
+ rack (~> 1.0)
91
+ tilt (~> 1.1, != 1.3.0)
92
+ thor (0.18.1)
93
+ tilt (1.3.6)
94
+ treetop (1.4.12)
95
+ polyglot
83
96
  polyglot (>= 0.3.1)
84
- tzinfo (0.3.24)
97
+ tzinfo (0.3.37)
85
98
 
86
99
  PLATFORMS
87
100
  ruby
88
101
 
89
102
  DEPENDENCIES
90
- rails (~> 3.0.3)
91
- rspec-rails (~> 2.9)
103
+ rails (~> 3.2.13)
104
+ rspec-rails (~> 2.13)
92
105
  truncate_html!
data/README.md CHANGED
@@ -2,7 +2,7 @@ TruncateHtml
2
2
  ============
3
3
 
4
4
  [![Build Status](https://secure.travis-ci.org/hgmnz/truncate_html.png?branch=master)](http://travis-ci.org/hgmnz/truncate_html)
5
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/hgmnz/truncate_html)
5
+ [![Code Climate](https://codeclimate.com/github/hgmnz/truncate_html.png)](https://codeclimate.com/github/hgmnz/truncate_html)
6
6
 
7
7
  truncate_html cuts off a string of HTML and takes care of closing any lingering open tags. There are many ways to solve this. This library does not have any dependencies, and [parses HTML using regular expressions](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454).
8
8
 
@@ -13,22 +13,24 @@ Example
13
13
 
14
14
  ```ruby
15
15
  some_html = '<ul><li><a href="http://whatever">This is a link</a></li></ul>'
16
- truncate_html(some_html, :length => 15, :omission => '...(continued)')
16
+ truncate_html(some_html, length: 15, omission: '...(continued)')
17
17
  => <ul><li><a href="http://whatever">This...(continued)</a></li></ul>
18
18
  ```
19
19
 
20
20
  A few notes:
21
21
 
22
22
  * By default, it will truncate on word boundary.
23
- To truncate the HTML string strictly at the specified length, pass in the `:word_boundary => false` option.
23
+ To truncate the HTML string strictly at the specified length, pass in the `word_boundary: false` option.
24
24
  * If the input HTML is nil, it will return an empty string.
25
25
  * The omission text's length does count toward the resulting string's length.
26
26
  * `<script>` tags will pass right through - they will not count toward the resulting string's length, or be truncated.
27
27
 
28
28
  * The default options are:
29
- * `:length`: 100
30
- * `:omission`: '...'
31
- * `:word_boundary`: /\S/
29
+ ```
30
+ length: 100
31
+ omission: '...'
32
+ word_boundary: /\S/
33
+ ```
32
34
 
33
35
  You may also set global configuration options.
34
36
  For example, place the following on application boot,
@@ -50,13 +52,13 @@ TruncateHtml.configure do |config|
50
52
  end
51
53
  ```
52
54
 
53
- You can also truncate the html at a specific point not based on length but content.
55
+ You can also truncate the HTML at a specific point not based on length but content.
54
56
  To do that, place the `:break_token` in your source. This allows the truncation to be
55
57
  data driven, breaking after a leading paragraph or sentence. If the
56
- `:break_token` is in your content before the specified :length, :length will be
57
- ignored and the content truncated at :break_token
58
- If the `:break_token` is in your content after the specified :length,
59
- `:break_token` will be ignored and the content truncated at :length
58
+ `:break_token` is in your content before the specified `:length`, `:length` will be
59
+ ignored and the content truncated at `:break_token`.
60
+ If the `:break_token` is in your content after the specified `:length`,
61
+ `:break_token` will be ignored and the content truncated at `:length`.
60
62
 
61
63
  ```ruby
62
64
  TruncateHtml.configure do |config|
@@ -83,8 +85,10 @@ Found an issue or have a suggestion? Please report it on [Github's issue tracker
83
85
  Testing
84
86
  -------
85
87
 
86
- bundle
87
- rake
88
+ ```shell
89
+ bundle
90
+ rake
91
+ ```
88
92
 
89
93
  All green? Go hack.
90
94
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.9.2
@@ -5,9 +5,10 @@ require File.join(File.dirname(__FILE__), 'truncate_html', 'configuration')
5
5
  require File.join(File.dirname(__FILE__), 'app', 'helpers', 'truncate_html_helper')
6
6
 
7
7
  TruncateHtml.configure do |config|
8
- config.length = 100
9
- config.omission = '...'
8
+ config.length = 100
9
+ config.omission = '...'
10
10
  config.word_boundary = /\S/
11
11
  end
12
12
 
13
- ActionController::Base.helper(TruncateHtmlHelper)
13
+
14
+ ActionController::Base.helper(TruncateHtmlHelper) if defined?(ActionController)
@@ -3,16 +3,17 @@ module TruncateHtml
3
3
  class HtmlString < String
4
4
 
5
5
  UNPAIRED_TAGS = %w(br hr img).freeze
6
+ REGEX = /(?:<script.*>.*<\/script>)+|<\/?[^>]+>|[[[:alpha:]][0-9]\|`~!@#\$%^&*\(\)\-_\+=\[\]{}:;'²³§",\.\/?]+|\s+|[[:punct:]]/.freeze
6
7
 
7
8
  def initialize(original_html)
8
9
  super(original_html)
9
10
  end
10
11
 
11
12
  def html_tokens
12
- scan(regex).map do |token|
13
+ scan(REGEX).map do |token|
13
14
  HtmlString.new(
14
15
  token.gsub(
15
- /\n/,'' #remove newline characters
16
+ /\n/,' ' #replace newline characters with a whitespace
16
17
  ).gsub(
17
18
  /\s+/, ' ' #clean out extra consecutive whitespace
18
19
  )
@@ -36,10 +37,5 @@ module TruncateHtml
36
37
  gsub(/<(\w+)\s?.*>/, '</\1>').strip
37
38
  end
38
39
 
39
- private
40
- def regex
41
- /(?:<script.*>.*<\/script>)+|<\/?[^>]+>|[[[:alpha:]]\w\|`~!@#\$%^&*\(\)\-_\+=\[\]{}:;'",\.\/?]+|\s+|[[:punct:]]/
42
- end
43
-
44
40
  end
45
41
  end
@@ -8,7 +8,7 @@ module TruncateHtml
8
8
  @word_boundary = (options.has_key?(:word_boundary) ? options[:word_boundary] : TruncateHtml.configuration.word_boundary)
9
9
  @break_token = options[:break_token] || TruncateHtml.configuration.break_token || nil
10
10
  @chars_remaining = length - @omission.length
11
- @open_tags, @truncated_html = [], ['']
11
+ @open_tags, @closing_tags, @truncated_html = [], [], ['']
12
12
  end
13
13
 
14
14
  def truncate
@@ -22,15 +22,7 @@ module TruncateHtml
22
22
  end
23
23
  end
24
24
 
25
- out = @truncated_html.join
26
-
27
- if word_boundary
28
- term_regexp = Regexp.new("^.*#{word_boundary.source}")
29
- match = out.match(term_regexp)
30
- match ? match[0] : out
31
- else
32
- out
33
- end
25
+ build_output
34
26
  end
35
27
 
36
28
  private
@@ -43,6 +35,19 @@ module TruncateHtml
43
35
  end
44
36
  end
45
37
 
38
+ def build_output
39
+ out = @truncated_html.join
40
+ if word_boundary
41
+ term_regexp = Regexp.new("^.*#{word_boundary.source}")
42
+ match = out.match(term_regexp)
43
+ if match && match[0] != out
44
+ out = match[0] + @closing_tags.join
45
+ end
46
+ end
47
+
48
+ out
49
+ end
50
+
46
51
  def process_token(token)
47
52
  append_to_result(token)
48
53
  if token.html_tag?
@@ -71,6 +76,7 @@ module TruncateHtml
71
76
 
72
77
  def close_open_tags
73
78
  @open_tags.reverse_each do |open_tag|
79
+ @closing_tags << open_tag.matching_close_tag
74
80
  @truncated_html << open_tag.matching_close_tag
75
81
  end
76
82
  end
@@ -1,3 +1,3 @@
1
1
  module TruncateHtml
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  # Edit this Gemfile to bundle your application's dependencies.
2
2
  source 'http://gemcutter.org'
3
3
  group :development, :test do
4
- gem "rails", "= 3.0.3"
5
- gem 'rspec-rails', '= 2.3'
4
+ gem "rails", "~> 3.2.13"
5
+ gem 'rspec-rails', '~> 2.13'
6
6
  end
@@ -1,86 +1,99 @@
1
1
  GEM
2
2
  remote: http://gemcutter.org/
3
3
  specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.3)
6
- actionpack (= 3.0.3)
7
- mail (~> 2.2.9)
8
- actionpack (3.0.3)
9
- activemodel (= 3.0.3)
10
- activesupport (= 3.0.3)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.4)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.13)
16
- rack-test (~> 0.5.6)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.3)
19
- activesupport (= 3.0.3)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.4)
22
- activerecord (3.0.3)
23
- activemodel (= 3.0.3)
24
- activesupport (= 3.0.3)
25
- arel (~> 2.0.2)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.3)
28
- activemodel (= 3.0.3)
29
- activesupport (= 3.0.3)
30
- activesupport (3.0.3)
31
- arel (2.0.7)
32
- builder (2.1.2)
33
- diff-lcs (1.1.2)
34
- erubis (2.6.6)
35
- abstract (>= 1.0.0)
36
- i18n (0.5.0)
37
- mail (2.2.15)
38
- activesupport (>= 2.3.6)
4
+ actionmailer (3.2.13)
5
+ actionpack (= 3.2.13)
6
+ mail (~> 2.5.3)
7
+ actionpack (3.2.13)
8
+ activemodel (= 3.2.13)
9
+ activesupport (= 3.2.13)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.5)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.2.1)
17
+ activemodel (3.2.13)
18
+ activesupport (= 3.2.13)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.13)
21
+ activemodel (= 3.2.13)
22
+ activesupport (= 3.2.13)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.13)
26
+ activemodel (= 3.2.13)
27
+ activesupport (= 3.2.13)
28
+ activesupport (3.2.13)
29
+ i18n (= 0.6.1)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.4)
33
+ diff-lcs (1.2.2)
34
+ erubis (2.7.0)
35
+ hike (1.2.1)
36
+ i18n (0.6.1)
37
+ journey (1.0.4)
38
+ json (1.7.7)
39
+ mail (2.5.3)
39
40
  i18n (>= 0.4.0)
40
41
  mime-types (~> 1.16)
41
42
  treetop (~> 1.4.8)
42
- mime-types (1.16)
43
- polyglot (0.3.1)
44
- rack (1.2.1)
45
- rack-mount (0.6.13)
46
- rack (>= 1.0.0)
47
- rack-test (0.5.7)
43
+ mime-types (1.22)
44
+ multi_json (1.7.2)
45
+ polyglot (0.3.3)
46
+ rack (1.4.5)
47
+ rack-cache (1.2)
48
+ rack (>= 0.4)
49
+ rack-ssl (1.3.3)
50
+ rack
51
+ rack-test (0.6.2)
48
52
  rack (>= 1.0)
49
- rails (3.0.3)
50
- actionmailer (= 3.0.3)
51
- actionpack (= 3.0.3)
52
- activerecord (= 3.0.3)
53
- activeresource (= 3.0.3)
54
- activesupport (= 3.0.3)
53
+ rails (3.2.13)
54
+ actionmailer (= 3.2.13)
55
+ actionpack (= 3.2.13)
56
+ activerecord (= 3.2.13)
57
+ activeresource (= 3.2.13)
58
+ activesupport (= 3.2.13)
55
59
  bundler (~> 1.0)
56
- railties (= 3.0.3)
57
- railties (3.0.3)
58
- actionpack (= 3.0.3)
59
- activesupport (= 3.0.3)
60
+ railties (= 3.2.13)
61
+ railties (3.2.13)
62
+ actionpack (= 3.2.13)
63
+ activesupport (= 3.2.13)
64
+ rack-ssl (~> 1.3.2)
60
65
  rake (>= 0.8.7)
61
- thor (~> 0.14.4)
62
- rake (0.8.7)
63
- rspec (2.3.0)
64
- rspec-core (~> 2.3.0)
65
- rspec-expectations (~> 2.3.0)
66
- rspec-mocks (~> 2.3.0)
67
- rspec-core (2.3.1)
68
- rspec-expectations (2.3.0)
69
- diff-lcs (~> 1.1.2)
70
- rspec-mocks (2.3.0)
71
- rspec-rails (2.3.0)
72
- actionpack (~> 3.0)
73
- activesupport (~> 3.0)
74
- railties (~> 3.0)
75
- rspec (~> 2.3.0)
76
- thor (0.14.6)
77
- treetop (1.4.9)
66
+ rdoc (~> 3.4)
67
+ thor (>= 0.14.6, < 2.0)
68
+ rake (10.0.4)
69
+ rdoc (3.12.2)
70
+ json (~> 1.4)
71
+ rspec-core (2.13.1)
72
+ rspec-expectations (2.13.0)
73
+ diff-lcs (>= 1.1.3, < 2.0)
74
+ rspec-mocks (2.13.0)
75
+ rspec-rails (2.13.0)
76
+ actionpack (>= 3.0)
77
+ activesupport (>= 3.0)
78
+ railties (>= 3.0)
79
+ rspec-core (~> 2.13.0)
80
+ rspec-expectations (~> 2.13.0)
81
+ rspec-mocks (~> 2.13.0)
82
+ sprockets (2.2.2)
83
+ hike (~> 1.2)
84
+ multi_json (~> 1.0)
85
+ rack (~> 1.0)
86
+ tilt (~> 1.1, != 1.3.0)
87
+ thor (0.18.1)
88
+ tilt (1.3.6)
89
+ treetop (1.4.12)
90
+ polyglot
78
91
  polyglot (>= 0.3.1)
79
- tzinfo (0.3.24)
92
+ tzinfo (0.3.37)
80
93
 
81
94
  PLATFORMS
82
95
  ruby
83
96
 
84
97
  DEPENDENCIES
85
- rails (= 3.0.3)
86
- rspec-rails (= 2.3)
98
+ rails (~> 3.2.13)
99
+ rspec-rails (~> 2.13)
@@ -8,4 +8,6 @@ require File.expand_path('../../lib/truncate_html', __FILE__)
8
8
 
9
9
  RSpec.configure do |config|
10
10
  config.mock_with :rspec
11
+
12
+ config.order = 'random'
11
13
  end
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
3
 
3
4
  describe TruncateHtml::HtmlString do
@@ -8,8 +9,9 @@ describe TruncateHtml::HtmlString do
8
9
 
9
10
  describe '#html_tokens' do
10
11
  it 'returns each token in the string as an array element removing any consecutive whitespace from the string' do
11
- html = '<h1>Hi there</h1> <p>This is sweet!</p>'
12
- html_string(html).html_tokens.should == ['<h1>', 'Hi', ' ', 'there', '</h1>', ' ', '<p>', 'This', ' ', 'is', ' ', 'sweet!', '</p>']
12
+ html = '<h1>Hi there</h1> <p>This is sweet!</p> <p> squaremeter m² </p>'
13
+ html_string(html).html_tokens.should == ['<h1>', 'Hi', ' ', 'there', '</h1>', ' ', '<p>', 'This', ' ', 'is', ' ', 'sweet!', '</p>',
14
+ ' ', '<p>', ' ', 'squaremeter', ' ', 'm²', ' ', '</p>']
13
15
  end
14
16
  end
15
17
 
@@ -39,6 +39,10 @@ describe TruncateHtml::HtmlTruncator do
39
39
  it 'truncates to the end of the nearest sentence' do
40
40
  truncate('hello there. or maybe not?', :length => 16, :omission => '', :word_boundary => /\S[\.\?\!]/).should == 'hello there.'
41
41
  end
42
+
43
+ it 'is respectful of closing tags' do
44
+ truncate('<p>hmmm this <em>should</em> be okay. I think...</p>', :length => 28, :omission => '', :word_boundary => /\S[\.\?\!]/).should == "<p>hmmm this <em>should</em> be okay.</p>"
45
+ end
42
46
  end
43
47
 
44
48
  it "includes the omission text's length in the returned truncated html" do
@@ -102,8 +106,8 @@ describe TruncateHtml::HtmlTruncator do
102
106
  html = <<-END_HTML
103
107
  <div id="foo"
104
108
  class="bar">
105
- This is ugly html.
106
- </div>
109
+ This is ugly html.
110
+ </div>
107
111
  END_HTML
108
112
  truncate(html, :length => 12).should == ' <div id="foo" class="bar"> This is...</div>'
109
113
  end
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe TruncateHtml do
4
+ it "includes itself in ActionController::Base" do
5
+ ActionController::Base.should_receive(:helper).with(TruncateHtmlHelper)
6
+ load File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'truncate_html.rb'))
7
+ end
8
+
9
+ it "does not error if ActionController is undefined" do
10
+ hide_const("ActionController")
11
+ expect {
12
+ load File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'truncate_html.rb'))
13
+ }.not_to raise_error
14
+ end
15
+ end
@@ -1,13 +1,12 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "truncate_html/version"
2
+ require File.expand_path("../lib/truncate_html/version", __FILE__)
4
3
 
5
4
  Gem::Specification.new do |s|
6
5
  s.name = "truncate_html"
7
6
  s.version = TruncateHtml::VERSION
8
7
  s.authors = ["Harold Giménez"]
9
8
  s.email = ["harold.gimenez@gmail.com"]
10
- s.homepage = "https://github.com/hgimenez/truncate_html"
9
+ s.homepage = "https://github.com/hgmnz/truncate_html"
11
10
  s.summary = %q{Uses an API similar to Rails' truncate helper to truncate HTML and close any lingering open tags.}
12
11
  s.description = %q{Truncates html so you don't have to}
13
12
 
@@ -18,6 +17,6 @@ Gem::Specification.new do |s|
18
17
 
19
18
  s.required_ruby_version = '>= 1.9'
20
19
 
21
- s.add_development_dependency "rspec-rails", "~> 2.9"
22
- s.add_development_dependency "rails", "~> 3.0.3"
20
+ s.add_development_dependency "rspec-rails", "~> 2.13"
21
+ s.add_development_dependency "rails", "~> 3.2.13"
23
22
  end
metadata CHANGED
@@ -1,38 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truncate_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
5
- prerelease:
4
+ version: 0.9.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Harold Giménez
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-27 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec-rails
16
- requirement: &70161209065700 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '2.9'
19
+ version: '2.13'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *70161209065700
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.13'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rails
27
- requirement: &70161209065240 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
- version: 3.0.3
33
+ version: 3.2.13
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70161209065240
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.13
36
41
  description: Truncates html so you don't have to
37
42
  email:
38
43
  - harold.gimenez@gmail.com
@@ -40,8 +45,8 @@ executables: []
40
45
  extensions: []
41
46
  extra_rdoc_files: []
42
47
  files:
43
- - .gitignore
44
- - .travis.yml
48
+ - ".gitignore"
49
+ - ".travis.yml"
45
50
  - Gemfile
46
51
  - Gemfile.lock
47
52
  - History.txt
@@ -84,33 +89,30 @@ files:
84
89
  - spec/truncate_html/configuration_spec.rb
85
90
  - spec/truncate_html/html_string_spec.rb
86
91
  - spec/truncate_html/html_truncator_spec.rb
92
+ - spec/truncate_html/truncate_html_spec.rb
87
93
  - truncate_html.gemspec
88
- homepage: https://github.com/hgimenez/truncate_html
94
+ homepage: https://github.com/hgmnz/truncate_html
89
95
  licenses: []
96
+ metadata: {}
90
97
  post_install_message:
91
98
  rdoc_options: []
92
99
  require_paths:
93
100
  - lib
94
101
  required_ruby_version: !ruby/object:Gem::Requirement
95
- none: false
96
102
  requirements:
97
- - - ! '>='
103
+ - - ">="
98
104
  - !ruby/object:Gem::Version
99
105
  version: '1.9'
100
106
  required_rubygems_version: !ruby/object:Gem::Requirement
101
- none: false
102
107
  requirements:
103
- - - ! '>='
108
+ - - ">="
104
109
  - !ruby/object:Gem::Version
105
110
  version: '0'
106
- segments:
107
- - 0
108
- hash: -2711224977886415095
109
111
  requirements: []
110
112
  rubyforge_project:
111
- rubygems_version: 1.8.10
113
+ rubygems_version: 2.2.2
112
114
  signing_key:
113
- specification_version: 3
115
+ specification_version: 4
114
116
  summary: Uses an API similar to Rails' truncate helper to truncate HTML and close
115
117
  any lingering open tags.
116
118
  test_files:
@@ -142,3 +144,4 @@ test_files:
142
144
  - spec/truncate_html/configuration_spec.rb
143
145
  - spec/truncate_html/html_string_spec.rb
144
146
  - spec/truncate_html/html_truncator_spec.rb
147
+ - spec/truncate_html/truncate_html_spec.rb