truncate_html_text 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 086f01f8c351b7033c715cc1d272ca43ae91a0ed
4
+ data.tar.gz: 0b2c6323e6ccc4bdc5335c09aa7bd7612d5cd028
5
+ SHA512:
6
+ metadata.gz: 71cbf1b72c591316440fb61a34073f4bf3c32a24103dcb70834cbef18ce70765613f8797c7b8cfacf56cfe928e7227708b60f846030aad30cf439fb25e863cb9
7
+ data.tar.gz: 71e3efdd657b0eb24c161534b87f89b737cd65ad1225aff8282f31d6ff74e484e6350f1dae001f69b2d81836b4bbd9191d19812d771a77f85cb7a85d04af8197
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in truncate_html_text.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # TruncateHtmlText
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'truncate_html_text'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install truncate_html_text
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/truncate_html_text/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,82 @@
1
+ (function($) {
2
+
3
+ // Matches trailing non-space characters.
4
+ var chop = /(\s*\S+|\s)$/;
5
+
6
+ // Return a truncated html string. Delegates to $.fn.truncate.
7
+ $.truncate = function(html, options) {
8
+ return $('<div></div>').append(html).truncate(options).html();
9
+ };
10
+
11
+ // Truncate the contents of an element in place.
12
+ $.fn.truncate = function(options) {
13
+ if ($.isNumeric(options)) options = {length: options};
14
+ var o = $.extend({}, $.truncate.defaults, options);
15
+
16
+ return this.each(function() {
17
+ var self = $(this);
18
+
19
+ if (o.noBreaks) self.find('br').replaceWith(' ');
20
+
21
+ var text = self.text();
22
+ var excess = text.length - o.length;
23
+
24
+ if (o.stripTags) self.text(text);
25
+
26
+ // Chop off any partial words if appropriate.
27
+ if (o.words && excess > 0) {
28
+ excess = text.length - text.slice(0, o.length).replace(chop, '').length - 1;
29
+ }
30
+
31
+ if (excess < 0 || !excess && !o.truncated) return;
32
+
33
+ // Iterate over each child node in reverse, removing excess text.
34
+ $.each(self.contents().get().reverse(), function(i, el) {
35
+ var $el = $(el);
36
+ var text = $el.text();
37
+ var length = text.length;
38
+
39
+ // If the text is longer than the excess, remove the node and continue.
40
+ if (length <= excess) {
41
+ o.truncated = true;
42
+ excess -= length;
43
+ $el.remove();
44
+ return;
45
+ }
46
+
47
+ // Remove the excess text and append the ellipsis.
48
+ if (el.nodeType === 3) {
49
+ $(el.splitText(length - excess - 1)).replaceWith(o.ellipsis);
50
+ return false;
51
+ }
52
+
53
+ // Recursively truncate child nodes.
54
+ $el.truncate($.extend(o, {length: length - excess}));
55
+ return false;
56
+ });
57
+ });
58
+ };
59
+
60
+ $.truncate.defaults = {
61
+
62
+ // Strip all html elements, leaving only plain text.
63
+ stripTags: false,
64
+
65
+ // Only truncate at word boundaries.
66
+ words: false,
67
+
68
+ // Replace instances of <br> with a single space.
69
+ noBreaks: false,
70
+
71
+ // The maximum length of the truncated html.
72
+ length: Infinity,
73
+
74
+ // The character to use as the ellipsis. The word joiner (U+2060) can be
75
+ // used to prevent a hanging ellipsis, but displays incorrectly in Chrome
76
+ // on Windows 7.
77
+ // http://code.google.com/p/chromium/issues/detail?id=68323
78
+ ellipsis: '\u2026' // '\u2060\u2026'
79
+
80
+ };
81
+
82
+ })(jQuery);
@@ -0,0 +1,5 @@
1
+ $(function() {
2
+ options = $(".truncate").data();
3
+ text = $(".truncate").text();
4
+ $(".truncate").html($.truncate(text, options));
5
+ });
@@ -0,0 +1 @@
1
+ //= require_tree
@@ -0,0 +1,4 @@
1
+ module TruncateHtmlText
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+
2
+ class Railtie < Rails::Railtie
3
+
4
+ initializer "truncate_html_text.initialize_truncate_html_text_helper" do |app|
5
+ ActiveSupport.on_load(:action_view) do
6
+ include TruncateHtmlText
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,30 @@
1
+ # Contains code for html text truncate helper
2
+
3
+ module TruncateHtmlText
4
+ def truncate_html_text_tag(*args, &block)
5
+ options = insert_truncate_class(args.extract_options!)
6
+ args << options
7
+ content_tag(*args, &block)
8
+ end
9
+
10
+ def insert_truncate_class(options)
11
+ class_name = "truncate"
12
+ if options.key?(:class)
13
+ options[:class] += " #{class_name}"
14
+ elsif options.key?('class')
15
+ options['class'] += " #{class_name}"
16
+ else
17
+ options[:class] = class_name
18
+ end
19
+ if options.key?(:data)
20
+ data=Hash[options[:data].map {|k, v| ["data-"<<k.to_s, v] }]
21
+ options.delete(:data)
22
+ options.merge!(data)
23
+ elsif options.key?('data')
24
+ data=Hash[options["data"].map {|k, v| ["data-"<<k.to_s, v] }]
25
+ options.delete("data")
26
+ options.merge!(data)
27
+ end
28
+ options
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module TruncateHtmlText
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require_relative "truncate_html_text/version"
2
+ require_relative "truncate_html_text/engine"
3
+ require_relative "truncate_html_text/truncate_html_text_helper"
4
+ require_relative "truncate_html_text/railtie"
5
+
6
+ #module TruncateHtmlText
7
+ # Your code goes here...
8
+ #end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'truncate_html_text/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "truncate_html_text"
8
+ spec.version = TruncateHtmlText::VERSION
9
+ spec.authors = ["Tarun Agrawal"]
10
+ spec.email = ["tarun7588@gmail.com"]
11
+ spec.summary = %q{Rails HTML Text Truncate}
12
+ spec.description = %q{This is a Rails gem for Html Text Truncate}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ #spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: truncate_html_text
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tarun Agrawal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This is a Rails gem for Html Text Truncate
42
+ email:
43
+ - tarun7588@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - app/assets/javascripts/truncate_html_text.js
54
+ - app/assets/javascripts/truncate_html_text_initializer.js
55
+ - app/assets/javascripts/truncate_html_text_main.js
56
+ - lib/truncate_html_text.rb
57
+ - lib/truncate_html_text/engine.rb
58
+ - lib/truncate_html_text/railtie.rb
59
+ - lib/truncate_html_text/truncate_html_text_helper.rb
60
+ - lib/truncate_html_text/version.rb
61
+ - truncate_html_text.gemspec
62
+ homepage: ''
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Rails HTML Text Truncate
86
+ test_files: []