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 CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.3.0 2010-02-02
2
+ * Added the ability to set global configuration parameters
3
+ * Added the word_boundry option
4
+
1
5
  == 0.2.2 2009-12-23
2
6
  * Fix issue #4: Handle case when supplied length is smaller than omission. (ghazel)
3
7
 
data/README.markdown CHANGED
@@ -15,14 +15,25 @@ Example
15
15
 
16
16
  A few notes:
17
17
 
18
- * The default options are:
19
- * :length => 100
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 = ["hgimenez"]
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.0
1
+ 0.3.1
data/init.rb CHANGED
@@ -3,5 +3,5 @@ require 'truncate_html'
3
3
  TruncateHtml.configure do |config|
4
4
  config.length = 100
5
5
  config.omission = '...'
6
- config.word_boundry = true
6
+ config.word_boundary = true
7
7
  end
@@ -1,6 +1,6 @@
1
1
  module TruncateHtml
2
2
  class Configuration
3
- attr_accessor :length, :omission, :word_boundry
3
+ attr_accessor :length, :omission, :word_boundary
4
4
  end
5
5
 
6
6
  class << self
@@ -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
- @word_boundry = (options.has_key?(:word_boundry) ? options[:word_boundry] : TruncateHtml.configuration.word_boundry)
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 -= (@word_boundry ? token.length : token[0, @chars_remaining].length)
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 @word_boundry
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 word_boundry option is set to false' do
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 => '', :word_boundry => false).should == '<div>12345</div>'
14
+ truncate('<div>123456789</div>', :length => 5, :omission => '', :word_boundary => false).should == '<div>12345</div>'
15
15
  end
16
16
  end
17
17
 
@@ -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.0"
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 = ["hgimenez"]
12
- s.date = %q{2010-02-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.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
- - hgimenez
7
+ - Harold A. Gimenez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-02 00:00:00 -05:00
12
+ date: 2010-02-03 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15