truncate_html 0.3.2 → 0.4.0

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/.gitignore CHANGED
@@ -3,3 +3,5 @@ coverage
3
3
  profiling
4
4
  tmp
5
5
  spec/rails_root/log/*
6
+ log/*.log
7
+ .bundle
data/Gemfile ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2009 - 2010 Harold A. Giménez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -68,4 +68,4 @@ Make sure the following gems are installed
68
68
 
69
69
  Clone the repo and run rake from the project's root. All green? Go hack.
70
70
 
71
- Copyright (c) 2009 Harold A. Giménez, released under the MIT license
71
+ Copyright (c) 2009 - 2010 Harold A. Giménez, released under the MIT license
data/Rakefile CHANGED
@@ -1,20 +1,37 @@
1
1
  require 'rake'
2
- require 'spec/rake/spectask'
3
2
 
3
+ begin
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ rescue MissingSourceFile
7
+ module Rspec
8
+ module Core
9
+ class RakeTask
10
+ def initialize(name)
11
+ task name do
12
+ # if rspec-rails is a configured gem, this will output helpful material and exit ...
13
+ require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
14
+ # ... otherwise, do this:
15
+ raise <<-MSG
16
+ #{"*" * 80}
17
+ * You are trying to run an rspec rake task defined in
18
+ * #{__FILE__},
19
+ * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
20
+ #{"*" * 80}
21
+ MSG
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
4
28
 
5
- desc 'Default: run specs.'
6
29
  task :default => :spec
30
+ task :stats => "spec:statsetup"
7
31
 
8
- desc 'Run the specs'
9
- Spec::Rake::SpecTask.new(:spec) do |t|
10
- t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
11
- t.spec_files = FileList['spec/**/*_spec.rb']
12
- end
13
-
14
- Spec::Rake::SpecTask.new(:rcov) do |spec|
15
- spec.libs << 'lib' << 'spec'
16
- spec.pattern = 'spec/**/*_spec.rb'
17
- spec.rcov = true
32
+ desc "Run RSpec code examples"
33
+ Rspec::Core::RakeTask.new(:spec) do |t|
34
+ t.pattern = "./spec/**/*_spec.rb"
18
35
  end
19
36
 
20
37
  begin
@@ -34,7 +51,6 @@ rescue LoadError
34
51
  puts "Install metric_fu to run code metrics"
35
52
  end
36
53
 
37
-
38
54
  begin
39
55
  require 'jeweler'
40
56
  Jeweler::Tasks.new do |gem|
@@ -51,5 +67,3 @@ begin
51
67
  rescue LoadError
52
68
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
53
69
  end
54
-
55
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
@@ -3,7 +3,7 @@ module TruncateHtmlHelper
3
3
  def truncate_html(html, options={})
4
4
  return '' if html.nil?
5
5
  html_string = TruncateHtml::HtmlString.new(html)
6
- TruncateHtml::HtmlTruncator.new(html_string).truncate(options)
6
+ TruncateHtml::HtmlTruncator.new(html_string).truncate(options).html_safe
7
7
  end
8
8
 
9
9
  end
@@ -3,12 +3,10 @@ require File.join(File.dirname(__FILE__), 'truncate_html', 'html_string')
3
3
  require File.join(File.dirname(__FILE__), 'truncate_html', 'configuration')
4
4
  require File.join(File.dirname(__FILE__), 'app', 'helpers', 'truncate_html_helper')
5
5
 
6
- ActionView::Base.class_eval do
7
- include TruncateHtmlHelper
8
- end
9
-
10
6
  TruncateHtml.configure do |config|
11
7
  config.length = 100
12
8
  config.omission = '...'
13
9
  config.word_boundary = true
14
10
  end
11
+
12
+ ActionController::Base.helper(TruncateHtmlHelper)
@@ -18,17 +18,19 @@ describe TruncateHtmlHelper do
18
18
 
19
19
  before(:each) do
20
20
  @html_truncator_mock = mock(TruncateHtml::HtmlTruncator)
21
+ @original_html = '<p>foo</p>'
22
+ @original_html.stub!(:html_safe).and_return(@original_html)
21
23
  end
22
24
 
23
25
  it 'creates an instance of HtmlTruncator and calls truncate() on it' do
24
- @html_truncator_mock.stub!(:truncate)
26
+ @html_truncator_mock.stub!(:truncate).and_return(@original_html)
25
27
  TruncateHtml::HtmlTruncator.should_receive(:new).and_return(@html_truncator_mock)
26
- truncator.truncate_html('foo')
28
+ truncator.truncate_html(@original_html)
27
29
  end
28
30
 
29
31
  it 'calls truncate() on the HtmlTruncator object' do
30
32
  TruncateHtml::HtmlTruncator.stub!(:new).and_return(@html_truncator_mock)
31
- @html_truncator_mock.should_receive(:truncate).with({}).once
33
+ @html_truncator_mock.should_receive(:truncate).with({}).once.and_return(@original_html)
32
34
  truncator.truncate_html('foo')
33
35
  end
34
36
 
@@ -0,0 +1,4 @@
1
+ # Edit this Gemfile to bundle your application's dependencies.
2
+ source 'http://gemcutter.org'
3
+ gem "rails", "3.0.0.beta"
4
+ gem 'rspec-rails', '>=2.0.0.beta.4', :group => :test
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+
5
+ # Auto-require default libraries and those for the current Rails environment.
6
+ Bundler.require :default, Rails.env
7
+
8
+ module TruncateHtmlSpec
9
+ class Application < Rails::Application
10
+ config.action_controller.session = { :key => "_myapp_session",
11
+ :secret => "truncate_html_super_secret_dont_tell_anyone" }
12
+ end
13
+ end
@@ -1,110 +1,2 @@
1
- # Don't change this file!
2
- # Configure your app in config/environment.rb and config/environments/*.rb
3
-
4
- RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
-
6
- module Rails
7
- class << self
8
- def boot!
9
- unless booted?
10
- preinitialize
11
- pick_boot.run
12
- end
13
- end
14
-
15
- def booted?
16
- defined? Rails::Initializer
17
- end
18
-
19
- def pick_boot
20
- (vendor_rails? ? VendorBoot : GemBoot).new
21
- end
22
-
23
- def vendor_rails?
24
- File.exist?("#{RAILS_ROOT}/vendor/rails")
25
- end
26
-
27
- def preinitialize
28
- load(preinitializer_path) if File.exist?(preinitializer_path)
29
- end
30
-
31
- def preinitializer_path
32
- "#{RAILS_ROOT}/config/preinitializer.rb"
33
- end
34
- end
35
-
36
- class Boot
37
- def run
38
- load_initializer
39
- Rails::Initializer.run(:set_load_path)
40
- end
41
- end
42
-
43
- class VendorBoot < Boot
44
- def load_initializer
45
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
- Rails::Initializer.run(:install_gem_spec_stubs)
47
- Rails::GemDependency.add_frozen_gem_path
48
- end
49
- end
50
-
51
- class GemBoot < Boot
52
- def load_initializer
53
- self.class.load_rubygems
54
- load_rails_gem
55
- require 'initializer'
56
- end
57
-
58
- def load_rails_gem
59
- if version = self.class.gem_version
60
- gem 'rails', version
61
- else
62
- gem 'rails'
63
- end
64
- rescue Gem::LoadError => load_error
65
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
66
- exit 1
67
- end
68
-
69
- class << self
70
- def rubygems_version
71
- Gem::RubyGemsVersion rescue nil
72
- end
73
-
74
- def gem_version
75
- if defined? RAILS_GEM_VERSION
76
- RAILS_GEM_VERSION
77
- elsif ENV.include?('RAILS_GEM_VERSION')
78
- ENV['RAILS_GEM_VERSION']
79
- else
80
- parse_gem_version(read_environment_rb)
81
- end
82
- end
83
-
84
- def load_rubygems
85
- require 'rubygems'
86
- min_version = '1.3.1'
87
- unless rubygems_version >= min_version
88
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
89
- exit 1
90
- end
91
-
92
- rescue LoadError
93
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
94
- exit 1
95
- end
96
-
97
- def parse_gem_version(text)
98
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
99
- end
100
-
101
- private
102
- def read_environment_rb
103
- File.read("#{RAILS_ROOT}/config/environment.rb")
104
- end
105
- end
106
- end
107
- end
108
-
109
- # All that for this:
110
- Rails.boot!
1
+ require 'rubygems'
2
+ require 'bundler'
@@ -1,46 +1,5 @@
1
- # Be sure to restart your server when you modify this file
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
2
3
 
3
- # Specifies gem version of Rails to use when vendor/rails is not present
4
- RAILS_GEM_VERSION = '>= 2.3.4' unless defined? RAILS_GEM_VERSION
5
-
6
- # Bootstrap the Rails environment, frameworks, and default configuration
7
- require File.join(File.dirname(__FILE__), 'boot')
8
-
9
- Rails::Initializer.run do |config|
10
- # Settings in config/environments/* take precedence over those specified here.
11
- # Application configuration should go into files in config/initializers
12
- # -- all .rb files in that directory are automatically loaded.
13
-
14
- # Add additional load paths for your own custom dirs
15
- # config.load_paths += %W( #{RAILS_ROOT}/extras )
16
-
17
- # Specify gems that this application depends on and have them installed with rake gems:install
18
- # config.gem "bj"
19
- # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
20
- # config.gem "sqlite3-ruby", :lib => "sqlite3"
21
- # config.gem "aws-s3", :lib => "aws/s3"
22
-
23
- # Only load the plugins named here, in the order given (default is alphabetical).
24
- # :all can be used as a placeholder for all plugins not explicitly named
25
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
-
27
- # Skip frameworks you're not going to use. To use Rails without a database,
28
- # you must remove the Active Record framework.
29
- config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
30
-
31
- # Activate observers that should always be running
32
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33
-
34
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35
- # Run "rake -D time" for a list of tasks for finding time zone names.
36
- config.time_zone = 'UTC'
37
-
38
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
40
- # config.i18n.default_locale = :de
41
-
42
- config.gem 'rspec-rails',
43
- :lib => false
44
- config.gem 'rspec',
45
- :lib => false
46
- end
4
+ # Initialize the rails application
5
+ TruncateHtmlSpec::Application.initialize!
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -1,4 +1,11 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
1
2
  rails_root = File.dirname(__FILE__) + '/rails_root'
2
3
  require rails_root + '/config/environment.rb'
3
4
 
5
+ require 'rspec/rails'
6
+
4
7
  require File.join(File.dirname(__FILE__), '..', 'lib', 'truncate_html')
8
+
9
+ Rspec.configure do |config|
10
+ config.mock_with :rspec
11
+ end
@@ -5,32 +5,37 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{truncate_html}
8
- s.version = "0.3.2"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Harold A. Gimenez"]
12
- s.date = %q{2010-03-23}
12
+ s.date = %q{2010-03-30}
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 = [
16
- "README.markdown"
16
+ "LICENSE",
17
+ "README.markdown"
17
18
  ]
18
19
  s.files = [
19
20
  ".gitignore",
21
+ "Gemfile",
20
22
  "History.txt",
23
+ "LICENSE",
21
24
  "README.markdown",
22
25
  "Rakefile",
23
26
  "VERSION",
24
27
  "init.rb",
25
- "install.rb",
26
28
  "lib/app/helpers/truncate_html_helper.rb",
27
29
  "lib/truncate_html.rb",
28
30
  "lib/truncate_html/configuration.rb",
29
31
  "lib/truncate_html/html_string.rb",
30
32
  "lib/truncate_html/html_truncator.rb",
31
33
  "spec/helpers/truncate_html_helper_spec.rb",
34
+ "spec/rails_root/.bundle/config",
35
+ "spec/rails_root/Gemfile",
32
36
  "spec/rails_root/app/controllers/application_controller.rb",
33
37
  "spec/rails_root/app/helpers/application_helper.rb",
38
+ "spec/rails_root/config/application.rb",
34
39
  "spec/rails_root/config/boot.rb",
35
40
  "spec/rails_root/config/database.yml",
36
41
  "spec/rails_root/config/environment.rb",
@@ -47,23 +52,23 @@ Gem::Specification.new do |s|
47
52
  "spec/rails_root/init.rb",
48
53
  "spec/rails_root/lib/app/helpers/truncate_html_helper.rb",
49
54
  "spec/rails_root/lib/tasks/rspec.rake",
55
+ "spec/spec.opts",
50
56
  "spec/spec_helper.rb",
51
57
  "spec/truncate_html/configuration_spec.rb",
52
58
  "spec/truncate_html/html_string_spec.rb",
53
59
  "spec/truncate_html/html_truncator_spec.rb",
54
- "tasks/truncate_html_tasks.rake",
55
- "truncate_html.gemspec",
56
- "uninstall.rb"
60
+ "truncate_html.gemspec"
57
61
  ]
58
62
  s.homepage = %q{http://github.com/hgimenez/truncate_html}
59
63
  s.rdoc_options = ["--charset=UTF-8"]
60
64
  s.require_paths = ["lib"]
61
- s.rubygems_version = %q{1.3.5}
65
+ s.rubygems_version = %q{1.3.6}
62
66
  s.summary = %q{Uses an API similar to Rails' truncate helper to truncate HTML and close any lingering open tags.}
63
67
  s.test_files = [
64
68
  "spec/helpers/truncate_html_helper_spec.rb",
65
69
  "spec/rails_root/app/controllers/application_controller.rb",
66
70
  "spec/rails_root/app/helpers/application_helper.rb",
71
+ "spec/rails_root/config/application.rb",
67
72
  "spec/rails_root/config/boot.rb",
68
73
  "spec/rails_root/config/environment.rb",
69
74
  "spec/rails_root/config/environments/development.rb",
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truncate_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Harold A. Gimenez
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-03-23 00:00:00 -04:00
17
+ date: 2010-03-30 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -20,23 +25,28 @@ executables: []
20
25
  extensions: []
21
26
 
22
27
  extra_rdoc_files:
28
+ - LICENSE
23
29
  - README.markdown
24
30
  files:
25
31
  - .gitignore
32
+ - Gemfile
26
33
  - History.txt
34
+ - LICENSE
27
35
  - README.markdown
28
36
  - Rakefile
29
37
  - VERSION
30
38
  - init.rb
31
- - install.rb
32
39
  - lib/app/helpers/truncate_html_helper.rb
33
40
  - lib/truncate_html.rb
34
41
  - lib/truncate_html/configuration.rb
35
42
  - lib/truncate_html/html_string.rb
36
43
  - lib/truncate_html/html_truncator.rb
37
44
  - spec/helpers/truncate_html_helper_spec.rb
45
+ - spec/rails_root/.bundle/config
46
+ - spec/rails_root/Gemfile
38
47
  - spec/rails_root/app/controllers/application_controller.rb
39
48
  - spec/rails_root/app/helpers/application_helper.rb
49
+ - spec/rails_root/config/application.rb
40
50
  - spec/rails_root/config/boot.rb
41
51
  - spec/rails_root/config/database.yml
42
52
  - spec/rails_root/config/environment.rb
@@ -53,13 +63,12 @@ files:
53
63
  - spec/rails_root/init.rb
54
64
  - spec/rails_root/lib/app/helpers/truncate_html_helper.rb
55
65
  - spec/rails_root/lib/tasks/rspec.rake
66
+ - spec/spec.opts
56
67
  - spec/spec_helper.rb
57
68
  - spec/truncate_html/configuration_spec.rb
58
69
  - spec/truncate_html/html_string_spec.rb
59
70
  - spec/truncate_html/html_truncator_spec.rb
60
- - tasks/truncate_html_tasks.rake
61
71
  - truncate_html.gemspec
62
- - uninstall.rb
63
72
  has_rdoc: true
64
73
  homepage: http://github.com/hgimenez/truncate_html
65
74
  licenses: []
@@ -73,18 +82,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
82
  requirements:
74
83
  - - ">="
75
84
  - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
76
87
  version: "0"
77
- version:
78
88
  required_rubygems_version: !ruby/object:Gem::Requirement
79
89
  requirements:
80
90
  - - ">="
81
91
  - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
82
94
  version: "0"
83
- version:
84
95
  requirements: []
85
96
 
86
97
  rubyforge_project:
87
- rubygems_version: 1.3.5
98
+ rubygems_version: 1.3.6
88
99
  signing_key:
89
100
  specification_version: 3
90
101
  summary: Uses an API similar to Rails' truncate helper to truncate HTML and close any lingering open tags.
@@ -92,6 +103,7 @@ test_files:
92
103
  - spec/helpers/truncate_html_helper_spec.rb
93
104
  - spec/rails_root/app/controllers/application_controller.rb
94
105
  - spec/rails_root/app/helpers/application_helper.rb
106
+ - spec/rails_root/config/application.rb
95
107
  - spec/rails_root/config/boot.rb
96
108
  - spec/rails_root/config/environment.rb
97
109
  - spec/rails_root/config/environments/development.rb
data/install.rb DELETED
@@ -1 +0,0 @@
1
- # Install hook code here
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :truncate_html do
3
- # # Task goes here
4
- # end
@@ -1 +0,0 @@
1
- # Uninstall hook code here