truncate_html 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ pkg
2
+ coverage
3
+ profiling
4
+ tmp
5
+ spec/rails_root/log/*
6
+ log/*.log
7
+ .bundle
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - jruby-18mode # JRuby in 1.8 mode
6
+ - jruby-19mode # JRuby in 1.9 mode
data/Gemfile CHANGED
@@ -1,7 +1,4 @@
1
- # Edit this Gemfile to bundle your application's dependencies.
2
- source 'http://gemcutter.org'
3
- group :development, :test do
4
- gem 'jeweler'
5
- gem "rails", "= 3.0.3"
6
- gem 'rspec-rails', '= 2.3'
7
- end
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in truncate_html.gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,5 +1,10 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ truncate_html (0.5.2)
5
+
1
6
  GEM
2
- remote: http://gemcutter.org/
7
+ remote: http://rubygems.org/
3
8
  specs:
4
9
  abstract (1.0.0)
5
10
  actionmailer (3.0.3)
@@ -33,12 +38,7 @@ GEM
33
38
  diff-lcs (1.1.2)
34
39
  erubis (2.6.6)
35
40
  abstract (>= 1.0.0)
36
- git (1.2.5)
37
41
  i18n (0.5.0)
38
- jeweler (1.5.2)
39
- bundler (~> 1.0.0)
40
- git (>= 1.2.5)
41
- rake
42
42
  mail (2.2.15)
43
43
  activesupport (>= 2.3.6)
44
44
  i18n (>= 0.4.0)
@@ -87,6 +87,6 @@ PLATFORMS
87
87
  ruby
88
88
 
89
89
  DEPENDENCIES
90
- jeweler
91
90
  rails (= 3.0.3)
92
91
  rspec-rails (= 2.3)
92
+ truncate_html!
data/README.markdown CHANGED
@@ -1,6 +1,8 @@
1
1
  TruncateHtml
2
2
  ============
3
3
 
4
+ [![Build Status](https://secure.travis-ci.org/hgimenez/truncate_html.png?branch=master)](http://travis-ci.org/hgimenez/truncate_html)
5
+
4
6
  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
7
 
6
8
  The API is very similar to Rails' own <code>truncate()</code> method.
data/Rakefile CHANGED
@@ -34,36 +34,22 @@ RSpec::Core::RakeTask.new(:spec) do |t|
34
34
  t.pattern = "./spec/**/*_spec.rb"
35
35
  end
36
36
 
37
- begin
38
- require 'metric_fu'
39
- MetricFu::Configuration.run do |config|
40
- config.metrics = [:saikuro, :flog, :flay, :reek, :roodi, :rcov]
41
- config.graphs = [:flog, :flay, :reek, :roodi, :rcov]
42
- config.rcov = { :environment => 'test',
43
- :test_files => ['spec/**/*_spec.rb'],
44
- :rcov_opts => ["--sort coverage",
45
- "--text-coverage",
46
- "--profile",
47
- "--exclude /gems/,/Library/"]}
48
- config.graph_engine = :bluff
37
+ namespace :gem do
38
+ def run(command)
39
+ puts "+ #{command}"
40
+ result = system(command)
41
+ puts "- #{result}"
49
42
  end
50
- rescue LoadError
51
- puts "Install metric_fu to run code metrics"
52
- end
53
-
54
- begin
55
- require 'jeweler'
56
- Jeweler::Tasks.new do |gem|
57
- gem.name = "truncate_html"
58
- gem.summary = %Q{Uses an API similar to Rails' truncate helper to truncate HTML and close any lingering open tags.}
59
- gem.description = %Q{Truncates html so you don't have to}
60
- gem.email = "harold.gimenez@gmail.com"
61
- gem.homepage = "http://github.com/hgimenez/truncate_html"
62
- gem.authors = ["Harold A. Gimenez"]
63
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
43
+ desc "Release to rubygems"
44
+ task :release do
45
+ require File.expand_path('lib/truncate_html/version', File.dirname(__FILE__))
46
+ version = TruncateHtml::VERSION
47
+ message = "Bump to version #{version}"
48
+ run "git tag -a -m '#{message}' v#{version}"
49
+ run "git push origin master"
50
+ run "git push origin $(git tag | tail -1)"
51
+ run "gem build truncate_html.gemspec"
52
+ run "gem push truncate_html-#{version}.gem"
53
+ run "rm truncate_html-#{version}.gem"
64
54
  end
65
- Jeweler::GemcutterTasks.new
66
-
67
- rescue LoadError
68
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
69
55
  end
@@ -40,8 +40,10 @@ module TruncateHtml
40
40
  end
41
41
 
42
42
  def append_to_result(token)
43
- if @word_boundary
44
- @truncated_html << token if token.html_tag? || @chars_remaining - token.length >= 0
43
+ if token.html_tag?
44
+ @truncated_html << token
45
+ elsif @word_boundary
46
+ @truncated_html << token if @chars_remaining - token.length >= 0
45
47
  else
46
48
  @truncated_html << token[0, @chars_remaining]
47
49
  end
@@ -0,0 +1,3 @@
1
+ module TruncateHtml
2
+ VERSION = "0.5.2"
3
+ end
data/lib/truncate_html.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), 'truncate_html', 'version')
1
2
  require File.join(File.dirname(__FILE__), 'truncate_html', 'html_truncator')
2
3
  require File.join(File.dirname(__FILE__), 'truncate_html', 'html_string')
3
4
  require File.join(File.dirname(__FILE__), 'truncate_html', 'configuration')
@@ -14,6 +14,11 @@ describe TruncateHtml::HtmlTruncator do
14
14
  it 'truncates to the exact length specified' do
15
15
  truncate('<div>123456789</div>', :length => 5, :omission => '', :word_boundary => false).should == '<div>12345</div>'
16
16
  end
17
+
18
+ it 'retains the tags within the text' do
19
+ html = 'some text <span class="caps">CAPS</span> some text'
20
+ truncate(html, :length => 25, :word_boundary => false).should == 'some text <span class="caps">CAPS</span> some te'
21
+ end
17
22
  end
18
23
 
19
24
  it "includes the omission text's length in the returned truncated html" do
@@ -1,109 +1,21 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "truncate_html/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{truncate_html}
8
- s.version = "0.5.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Harold A. Gimenez"]
12
- s.date = %q{2011-04-08}
6
+ s.name = "truncate_html"
7
+ s.version = TruncateHtml::VERSION
8
+ s.authors = ["Harold Giménez"]
9
+ s.email = ["harold.gimenez@gmail.com"]
10
+ s.homepage = "https://github.com/hgimenez/truncate_html"
11
+ s.summary = %q{Uses an API similar to Rails' truncate helper to truncate HTML and close any lingering open tags.}
13
12
  s.description = %q{Truncates html so you don't have to}
14
- s.email = %q{harold.gimenez@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.markdown"
18
- ]
19
- s.files = [
20
- "Gemfile",
21
- "Gemfile.lock",
22
- "History.txt",
23
- "LICENSE",
24
- "README.markdown",
25
- "Rakefile",
26
- "VERSION",
27
- "init.rb",
28
- "lib/app/helpers/truncate_html_helper.rb",
29
- "lib/truncate_html.rb",
30
- "lib/truncate_html/configuration.rb",
31
- "lib/truncate_html/html_string.rb",
32
- "lib/truncate_html/html_truncator.rb",
33
- "spec/helpers/truncate_html_helper_spec.rb",
34
- "spec/rails_root/.bundle/config",
35
- "spec/rails_root/Gemfile",
36
- "spec/rails_root/Gemfile.lock",
37
- "spec/rails_root/app/controllers/application_controller.rb",
38
- "spec/rails_root/app/helpers/application_helper.rb",
39
- "spec/rails_root/config/application.rb",
40
- "spec/rails_root/config/boot.rb",
41
- "spec/rails_root/config/database.yml",
42
- "spec/rails_root/config/environment.rb",
43
- "spec/rails_root/config/environments/development.rb",
44
- "spec/rails_root/config/environments/production.rb",
45
- "spec/rails_root/config/environments/test.rb",
46
- "spec/rails_root/config/initializers/backtrace_silencers.rb",
47
- "spec/rails_root/config/initializers/inflections.rb",
48
- "spec/rails_root/config/initializers/mime_types.rb",
49
- "spec/rails_root/config/initializers/new_rails_defaults.rb",
50
- "spec/rails_root/config/initializers/session_store.rb",
51
- "spec/rails_root/config/locales/en.yml",
52
- "spec/rails_root/config/routes.rb",
53
- "spec/rails_root/init.rb",
54
- "spec/rails_root/lib/app/helpers/truncate_html_helper.rb",
55
- "spec/rails_root/lib/tasks/rspec.rake",
56
- "spec/spec.opts",
57
- "spec/spec_helper.rb",
58
- "spec/truncate_html/configuration_spec.rb",
59
- "spec/truncate_html/html_string_spec.rb",
60
- "spec/truncate_html/html_truncator_spec.rb",
61
- "truncate_html.gemspec"
62
- ]
63
- s.homepage = %q{http://github.com/hgimenez/truncate_html}
64
- s.require_paths = ["lib"]
65
- s.rubygems_version = %q{1.6.2}
66
- s.summary = %q{Uses an API similar to Rails' truncate helper to truncate HTML and close any lingering open tags.}
67
- s.test_files = [
68
- "spec/helpers/truncate_html_helper_spec.rb",
69
- "spec/rails_root/app/controllers/application_controller.rb",
70
- "spec/rails_root/app/helpers/application_helper.rb",
71
- "spec/rails_root/config/application.rb",
72
- "spec/rails_root/config/boot.rb",
73
- "spec/rails_root/config/environment.rb",
74
- "spec/rails_root/config/environments/development.rb",
75
- "spec/rails_root/config/environments/production.rb",
76
- "spec/rails_root/config/environments/test.rb",
77
- "spec/rails_root/config/initializers/backtrace_silencers.rb",
78
- "spec/rails_root/config/initializers/inflections.rb",
79
- "spec/rails_root/config/initializers/mime_types.rb",
80
- "spec/rails_root/config/initializers/new_rails_defaults.rb",
81
- "spec/rails_root/config/initializers/session_store.rb",
82
- "spec/rails_root/config/routes.rb",
83
- "spec/rails_root/init.rb",
84
- "spec/rails_root/lib/app/helpers/truncate_html_helper.rb",
85
- "spec/spec_helper.rb",
86
- "spec/truncate_html/configuration_spec.rb",
87
- "spec/truncate_html/html_string_spec.rb",
88
- "spec/truncate_html/html_truncator_spec.rb"
89
- ]
90
13
 
91
- if s.respond_to? :specification_version then
92
- s.specification_version = 3
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
93
18
 
94
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
95
- s.add_development_dependency(%q<jeweler>, [">= 0"])
96
- s.add_development_dependency(%q<rails>, ["= 3.0.3"])
97
- s.add_development_dependency(%q<rspec-rails>, ["= 2.3"])
98
- else
99
- s.add_dependency(%q<jeweler>, [">= 0"])
100
- s.add_dependency(%q<rails>, ["= 3.0.3"])
101
- s.add_dependency(%q<rspec-rails>, ["= 2.3"])
102
- end
103
- else
104
- s.add_dependency(%q<jeweler>, [">= 0"])
105
- s.add_dependency(%q<rails>, ["= 3.0.3"])
106
- s.add_dependency(%q<rspec-rails>, ["= 2.3"])
107
- end
19
+ s.add_development_dependency "rspec-rails", "2.3"
20
+ s.add_development_dependency "rails", "3.0.3"
108
21
  end
109
-
metadata CHANGED
@@ -1,78 +1,47 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: truncate_html
3
- version: !ruby/object:Gem::Version
4
- hash: 9
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 1
10
- version: 0.5.1
11
6
  platform: ruby
12
- authors:
13
- - Harold A. Gimenez
7
+ authors:
8
+ - Harold Giménez
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-04-08 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- type: :development
23
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-02-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec-rails
16
+ requirement: &70300852391320 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
32
- name: jeweler
33
- version_requirements: *id001
34
- prerelease: false
35
- - !ruby/object:Gem::Dependency
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: '2.3'
36
22
  type: :development
37
- requirement: &id002 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ version_requirements: *70300852391320
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &70300852390700 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - "="
41
- - !ruby/object:Gem::Version
42
- hash: 1
43
- segments:
44
- - 3
45
- - 0
46
- - 3
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
47
32
  version: 3.0.3
48
- name: rails
49
- version_requirements: *id002
50
- prerelease: false
51
- - !ruby/object:Gem::Dependency
52
33
  type: :development
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - "="
57
- - !ruby/object:Gem::Version
58
- hash: 5
59
- segments:
60
- - 2
61
- - 3
62
- version: "2.3"
63
- name: rspec-rails
64
- version_requirements: *id003
65
34
  prerelease: false
35
+ version_requirements: *70300852390700
66
36
  description: Truncates html so you don't have to
67
- email: harold.gimenez@gmail.com
37
+ email:
38
+ - harold.gimenez@gmail.com
68
39
  executables: []
69
-
70
40
  extensions: []
71
-
72
- extra_rdoc_files:
73
- - LICENSE
74
- - README.markdown
75
- files:
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .travis.yml
76
45
  - Gemfile
77
46
  - Gemfile.lock
78
47
  - History.txt
@@ -86,6 +55,7 @@ files:
86
55
  - lib/truncate_html/configuration.rb
87
56
  - lib/truncate_html/html_string.rb
88
57
  - lib/truncate_html/html_truncator.rb
58
+ - lib/truncate_html/version.rb
89
59
  - spec/helpers/truncate_html_helper_spec.rb
90
60
  - spec/rails_root/.bundle/config
91
61
  - spec/rails_root/Gemfile
@@ -115,46 +85,47 @@ files:
115
85
  - spec/truncate_html/html_string_spec.rb
116
86
  - spec/truncate_html/html_truncator_spec.rb
117
87
  - truncate_html.gemspec
118
- has_rdoc: true
119
- homepage: http://github.com/hgimenez/truncate_html
88
+ homepage: https://github.com/hgimenez/truncate_html
120
89
  licenses: []
121
-
122
90
  post_install_message:
123
91
  rdoc_options: []
124
-
125
- require_paths:
92
+ require_paths:
126
93
  - lib
127
- required_ruby_version: !ruby/object:Gem::Requirement
94
+ required_ruby_version: !ruby/object:Gem::Requirement
128
95
  none: false
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- hash: 3
133
- segments:
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ segments:
134
101
  - 0
135
- version: "0"
136
- required_rubygems_version: !ruby/object:Gem::Requirement
102
+ hash: -4030667347302923269
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
104
  none: false
138
- requirements:
139
- - - ">="
140
- - !ruby/object:Gem::Version
141
- hash: 3
142
- segments:
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
143
110
  - 0
144
- version: "0"
111
+ hash: -4030667347302923269
145
112
  requirements: []
146
-
147
113
  rubyforge_project:
148
- rubygems_version: 1.6.2
114
+ rubygems_version: 1.8.10
149
115
  signing_key:
150
116
  specification_version: 3
151
- summary: Uses an API similar to Rails' truncate helper to truncate HTML and close any lingering open tags.
152
- test_files:
117
+ summary: Uses an API similar to Rails' truncate helper to truncate HTML and close
118
+ any lingering open tags.
119
+ test_files:
153
120
  - spec/helpers/truncate_html_helper_spec.rb
121
+ - spec/rails_root/.bundle/config
122
+ - spec/rails_root/Gemfile
123
+ - spec/rails_root/Gemfile.lock
154
124
  - spec/rails_root/app/controllers/application_controller.rb
155
125
  - spec/rails_root/app/helpers/application_helper.rb
156
126
  - spec/rails_root/config/application.rb
157
127
  - spec/rails_root/config/boot.rb
128
+ - spec/rails_root/config/database.yml
158
129
  - spec/rails_root/config/environment.rb
159
130
  - spec/rails_root/config/environments/development.rb
160
131
  - spec/rails_root/config/environments/production.rb
@@ -164,9 +135,12 @@ test_files:
164
135
  - spec/rails_root/config/initializers/mime_types.rb
165
136
  - spec/rails_root/config/initializers/new_rails_defaults.rb
166
137
  - spec/rails_root/config/initializers/session_store.rb
138
+ - spec/rails_root/config/locales/en.yml
167
139
  - spec/rails_root/config/routes.rb
168
140
  - spec/rails_root/init.rb
169
141
  - spec/rails_root/lib/app/helpers/truncate_html_helper.rb
142
+ - spec/rails_root/lib/tasks/rspec.rake
143
+ - spec/spec.opts
170
144
  - spec/spec_helper.rb
171
145
  - spec/truncate_html/configuration_spec.rb
172
146
  - spec/truncate_html/html_string_spec.rb