content_truncate 0.0.7 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,7 +22,24 @@ Or install it yourself as:
22
22
 
23
23
  String#content_truncate(limit_length, "<br/>", "\n", " ", ...)
24
24
 
25
- In the example, It truncate a String to `limit_length`, as long as possible end with `<br/>` or `\n` or ` ` or ...
25
+ By the way, It truncate a String to `limit_length`, as long as possible end with `<br/>` or `\n` or ` ` or ...
26
+
27
+ But In most cases, you only need call
28
+
29
+ String#content_truncate(limit_length)
30
+
31
+ directly, the default separators is `"<br/>", "\n", "。", ".", " "`
32
+
33
+ eg:
34
+
35
+ > The Model layer represents your domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic that is specific to your application. In Rails, database-backed model classes are derived from ActiveRecord::Base. Active Record allows you to present the data from database rows as objects and embellish these data objects with business logic methods. Although most Rails models are backed by a database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as provided by the Active Model module. You can read more about Active Record in its README.
36
+
37
+ convert to
38
+
39
+ > The Model layer represents your domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic that is specific to your application.
40
+
41
+ by call `String#content_truncate(180)`
42
+
26
43
 
27
44
  ## Contributing
28
45
 
@@ -17,8 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
-
21
- spec.add_dependency "activesupport", "> 3.0.0"
20
+
22
21
  spec.add_development_dependency "bundler", "~> 1.3"
23
22
  spec.add_development_dependency "rake"
24
23
  end
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/string'
1
+ # encoding: utf-8
2
2
 
3
3
  module ContentTruncate
4
4
  module String
@@ -8,7 +8,7 @@ module ContentTruncate
8
8
  if sep
9
9
  sub_string.send(:smart_truncate, limit_length, sep, *separators)
10
10
  else
11
- sub_string.truncate(limit_length, separator: sep)
11
+ sub_string.send(:smart_truncate, limit_length, "<br/>", "\n", "。", ".", " ")
12
12
  end
13
13
  end
14
14
 
@@ -1,3 +1,3 @@
1
1
  module ContentTruncate
2
- VERSION = "0.0.7"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -3,15 +3,12 @@ require 'test/unit'
3
3
  require_relative '../lib/content_truncate'
4
4
 
5
5
  class ContentTruncateTest < Test::Unit::TestCase
6
+ include ContentTruncate::String
6
7
 
7
8
  def mock_string
8
9
  "Truncate a string down to \n x characters. <br/>Beware of truncating \n text that has HTML elements in it."
9
10
  end
10
11
 
11
- def test_content_truncate_for_no_separator
12
- assert_equal "Truncate a string...", mock_string.content_truncate(20)
13
- end
14
-
15
12
  def test_content_truncate_for_one_separator
16
13
  assert_equal "Truncate a string down to \n x characters. <br/>", mock_string.content_truncate(100, "<br/>")
17
14
  end
@@ -31,4 +28,12 @@ class ContentTruncateTest < Test::Unit::TestCase
31
28
  def test_content_truncate_for_nil_match
32
29
  assert_equal "测试中文无", "测试中文无符号".content_truncate(5, "。", "<br/>")
33
30
  end
31
+
32
+ def test_content_truncate_default_behaviour
33
+ assert_equal "Truncate a string down to \n x characters. <br/>", mock_string.content_truncate(48)
34
+ end
35
+
36
+ def test_example
37
+ assert_equal "The Model layer represents your domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic that is specific to your application.", "The Model layer represents your domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic that is specific to your application. In Rails, database-backed model classes are derived from ActiveRecord::Base. Active Record allows you to present the data from database rows as objects and embellish these data objects with business logic methods. Although most Rails models are backed by a database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as provided by the Active Model module. You can read more about Active Record in its README.".content_truncate(180)
38
+ end
34
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_truncate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-30 00:00:00.000000000 Z
12
+ date: 2013-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: activesupport
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>'
20
- - !ruby/object:Gem::Version
21
- version: 3.0.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>'
28
- - !ruby/object:Gem::Version
29
- version: 3.0.0
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: bundler
32
16
  requirement: !ruby/object:Gem::Requirement