html_slicer 0.1.8 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4c4fcc74a0356630d72498be76a169062014b80
4
- data.tar.gz: e4f4b2585a0f4408e93b85f6c442119fa90b5264
3
+ metadata.gz: 8db09b48ca101d1442befb97c3f6d9f898061fb4
4
+ data.tar.gz: 2c93428bd3ec22b662e589203c9b044d0fb40df7
5
5
  SHA512:
6
- metadata.gz: a7f979442c8dba55d1c5cc2547420aa1dbd18fdad635542d4b02be01636d5769079d3d872c8881a6547064cd7d4fc85e917d1d9fb568ed2fa6df5535b3b099f5
7
- data.tar.gz: 305e3c4bd510566c9c39e8f37d00cffa2a2bd94e8c53de945b491611a4a9a4b2c1d1562723986ee035aafe609a061499b09768b72201b3b2115ca70ed4c68dcc
6
+ metadata.gz: 78f8c07ec1c60824e6e4213ce67c655c03a1c6a5e088698d0b3902f9020005ed7735c197712bc16f8c1c6f63e595a3b2e6b0a5141909d834773bc0822961fcec
7
+ data.tar.gz: 911c0aef4eb8fe0916088404ebfd672a716b4515f8e9719696816ffd8d3a39aff1d05f84f4d014f752d7eda722352a0796cf1529dfa3174e4fcc29a03c90cf6c
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.2.0
2
+
3
+ * html-scanner has been a part of Rails for a long time up to version 4.1. Now it's been deprecated and used as a stand-alone dependency.
4
+
1
5
  == 0.1.6
2
6
 
3
7
  * Dependency bugfixes.
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in html_slicer.gemspec
4
- gemspec
4
+ gemspec
5
+ gem 'html-scanner', :github => 'addagger/html-scanner'
@@ -1,14 +1,14 @@
1
- = html_slicer
1
+ = HTML-slicer
2
2
 
3
- A little gem for Rails 3 helps you implement a smart way to split textual content. This is a quick approach to create ‘pageable’ views for ActiveRecord Model’s attributes, just independent strings, or any other Ruby classes. Or course it can split HTML content. More over, it can ‘resize’ HTML tags through <tt>width=</tt> attribute*.
3
+ A little gem for Rails 3+ helps you implement a smart way to split text/HTML content into pages. This is a short way to create ‘pageable’ views for models' string attributes or raw String objects. Optionally it can ‘resize’ on a fly any HTML elements having <tt>width=</tt> or <tt>style='width: *px;'</tt> attribute*.
4
4
 
5
- * Imagine you want to resize <iframe> embeddings from YouTube saved in static content.
5
+ * for example <iframe> embeddings from YouTube or images or any other objects.
6
6
 
7
7
 
8
8
  == Features
9
9
 
10
10
  === Clean
11
- Does not globally pollute +Array+, +Hash+, +Object+ or <tt>AR::Base</tt>.
11
+ Inspired by Kaminari. Does not globally pollute +Array+, +Hash+, +Object+ or <tt>AR::Base</tt>.
12
12
 
13
13
  === Easy to use
14
14
  Bundle the gem, then your models are ready to implement slicing.
@@ -20,7 +20,7 @@ Besides global configuration (default), you can create stylized app-level config
20
20
  You can split your text with any Regexp clause: set up which node from your HTML content you want to split, or which you don’t want to. You can also use processor(s) to transform the content before it has to be sliced. Param name, used as a slice number key accessor, can be nested in another param key (nested params). Resizing HTML tags having <tt>width=</tt> attribute is a helpful feature too.
21
21
 
22
22
  === ORM & template engine agnostic
23
- Supports Rails 3 and multiple template engines (ERB, Haml).
23
+ Supports Rails 3+ and multiple template engines (ERB, Haml).
24
24
 
25
25
  === Modern
26
26
  The slicer helper outputs the HTML5 <nav> tag by default. In addition, the helper supports Rails 3 unobtrusive Ajax.
@@ -28,9 +28,9 @@ The slicer helper outputs the HTML5 <nav> tag by default. In addition, the helpe
28
28
 
29
29
  == Supported versions
30
30
 
31
- * Ruby 1.9.2, 1.9.3
31
+ * Ruby 1.9.2+
32
32
 
33
- * Rails 3.0.x, 3.1, 3.2
33
+ * Rails 3+
34
34
 
35
35
  * Haml 3+
36
36
 
@@ -39,6 +39,9 @@ The slicer helper outputs the HTML5 <nav> tag by default. In addition, the helpe
39
39
 
40
40
  Put this line in your Gemfile:
41
41
  gem 'html_slicer'
42
+
43
+ Dependencies (for versions 0.2.0+ & Rails 4.2+)
44
+ gem 'html-scanner', :github => 'addagger/html-scanner' # (fork from Jakob Skjerning, 'koppen/html-scanner')
42
45
 
43
46
  Then bundle:
44
47
  % bundle
@@ -52,7 +55,7 @@ Then bundle:
52
55
 
53
56
  where:
54
57
  * <method_name> - any method name which returns source String (can be called with .send()).
55
- * <configuration> - Hash of configuration options and/or +:config+ parameter.
58
+ * <configuration> - Hash of configuration options and/or +:config+ parameter as a symbol.
56
59
 
57
60
  === Basic example
58
61
 
@@ -62,30 +65,30 @@ where:
62
65
 
63
66
  where:
64
67
  * <tt>:content</tt> is an attribute accessor for Article which returns a target String object.
65
- * <tt>:as</tt> is a name of basic accessor for result.
68
+ * <tt>:as</tt> is a name of basic accessor for the result.
66
69
  * <tt>:slice</tt> is a hash of <tt>slicing options</tt> as a part of configuration.
67
70
  * <tt>:resize</tt> is a hash of <tt>resizing options</tt> as a part of configuration.
68
71
  * <tt>:cache_to</tt> is an accessor name used to store the cache. +True+ value make it by default.
69
72
 
70
73
  You can define any configuration key you want. Otherwise, default configuration options (if available) will be picked up automatically.
71
74
 
72
- Console:
75
+ Console example:
73
76
 
74
77
  @article = Article.find(1)
75
78
  @article.content
76
79
  # => "Words like violence break the silence\r\nCome crashing in into my little world\r\n<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/ms0bd_hCZsk\" frameborder=\"0\" allowfullscreen></iframe>\r\nPainful to me, pierce right through me\r\nCan't you understand, oh my little girl?"
77
80
 
78
81
  @article_paged = @article.paged
79
- # => "Words like violence bre"
82
+ # => "Words like violence bre" # Page 1
80
83
 
81
- @article_paged.slice!(2)
84
+ @article_paged.slice!(2) # Page 2
82
85
  # => "ak the silence"
83
86
 
84
- @article_paged.slice!(4)
87
+ @article_paged.slice!(4) # Page 4
85
88
  # => "rld
86
89
  <iframe width="300" height="169" src="http://www.youtube.com/embed/ms0bd_hCZsk" frameborder="0" allowfullscreen></iframe>"
87
90
 
88
- The <tt>.slice!()</tt> method accepts number of slice (page). No argument (or +nil+) assumes it is number +1+. Passed slice number is remembered.
91
+ The <tt>.slice!()</tt> method accepts slice number (page) as an integer. Blank argument (or +nil+) assumes it is number +1+.
89
92
 
90
93
  === Configuration options
91
94
 
@@ -108,8 +111,8 @@ All configuration keys:
108
111
 
109
112
  * <tt>:unit</tt> is a +Regexp/String/Hash+ description of text units counted to split the text by slices.
110
113
  When value is a +Hash+, it assumes the unit is a HTML tag (look at <tt>:only/:except</tt> options for details).
111
- Undefined value or +nil+ assumes it by default regular expression <tt>/&#?\w+;|\S/</tt>. As you can see it counts any regular character or HTML special character as a unit.
112
- * <tt>:maximum</tt> is a +Fixnum+ number of units to be a one slice.
114
+ Undefined value or +nil+ assumes it by default regular expression <tt>/&#?\w+;|\S/</tt>. As you can see it counts any regular character or HTML special character as a one unit.
115
+ * <tt>:maximum</tt> is a +Fixnum+ number of units to be in a one slice.
113
116
 
114
117
  If +:unit+ defined as Regexp or String, default value is 300.
115
118
 
@@ -126,8 +129,8 @@ It can be an ellipsis or any other symbol.
126
129
  * <tt>:only</tt> is a +Hash+ or +Array+ of hashes, describes which exactly nodes of HTML content to slice.*
127
130
  * <tt>:except</tt> is a +Hash+ or +Array+ of hashes, describes which exactly nodes of HTML content NOT to slice.*
128
131
 
129
- * Actually the hash is an argument for HTML::Conditions class (the part of ActionPack's html_scanner code). Look at http://github.com/rails/rails/blob/master/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb
130
- This is a very flexible utility to navigate via HTML content. Read native documentation for details.
132
+ * Actually the hash is an argument for ::HTML::Conditions class (the part of <tt>html_scanner</tt> code). Look at http://github.com/koppen/html-scanner/blob/master/lib/html/node.rb
133
+ This is a very useful utility to navigate via HTML content. Read native documentation for details and thank you, Assaf Arkin for that legendary code being with Rails up to 4.1 since 2006.
131
134
 
132
135
  For example: ID for <tt><hr class="break"></tt> tag is a hash: <tt>{:tag => "hr", :attributes => {:class => "break"}}</tt>
133
136
 
@@ -9,13 +9,12 @@ Gem::Specification.new do |s|
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Valery Kvon"]
11
11
  s.email = ["addagger@gmail.com"]
12
- s.homepage = %q{http://vkvon.ru/projects/html_slicer}
12
+ s.homepage = %q{http://github.com/addagger/html_slicer}
13
13
  s.summary = %q{Paginate (split) long HTML text to pages and partials. Resize embeddings on fly. Flexible configuration.}
14
- s.description = %q{HTML truncation & pagination for Rails 3. Optional feature: recalculate resolution values of HTML tags (within width/height/style attributes).}
14
+ s.description = %q{HTML truncation & pagination for Rails 3+. Optional feature: recalculate resolution values of HTML tags (within width/height/style attributes).}
15
15
 
16
- s.add_dependency "actionpack", ['>= 3.0.0']
17
16
  s.add_dependency "activesupport", ['>= 3.0.0']
18
- s.add_dependency "active_tools", ['>= 0.0.2']
17
+ s.add_dependency "active_tools", ['>= 0.0.18']
19
18
 
20
19
  s.rubyforge_project = "html_slicer"
21
20
 
@@ -3,7 +3,6 @@
3
3
  require "html_slicer/version"
4
4
 
5
5
  module HtmlSlicer
6
-
7
6
  def self.load!
8
7
  require 'html_slicer/utilities'
9
8
  require 'html_slicer/config'
@@ -13,7 +12,6 @@ module HtmlSlicer
13
12
  require 'html_slicer/helpers/slicer'
14
13
  require 'html_slicer/railtie'
15
14
  end
16
-
17
15
  end
18
16
 
19
17
  HtmlSlicer.load!
@@ -31,6 +31,10 @@ module HtmlSlicer
31
31
  load!
32
32
  end
33
33
 
34
+ def inspect
35
+ "'#{to_s}'"
36
+ end
37
+
34
38
  # Getting source content
35
39
  def source
36
40
  case options[:processors].present?
@@ -60,7 +64,7 @@ module HtmlSlicer
60
64
  CachedStuff.new
61
65
  end
62
66
  if @document.blank? || !@cached_stuff.valid_text?(text) # Initialize new @document if not exist or content has been changed
63
- @document = HTML::Document.new(text)
67
+ @document = ::HTML::Document.new(text)
64
68
  @cached_stuff.hexdigest_for = text
65
69
  end
66
70
  if @cached_stuff.changed? || !@cached_stuff.valid_resizing_options?(@resizing_options) # Initialize new resizing process if the content or options has been changed
@@ -133,8 +137,8 @@ module HtmlSlicer
133
137
  def view(node, slice, &block)
134
138
  slice = slice.to_i
135
139
  case node
136
- when HTML::Tag then
137
- children_view = node.children.collect {|child| view(child, slice, &block)}.compact.join
140
+ when ::HTML::Tag then
141
+ children_view = node.children.map {|child| view(child, slice, &block)}.compact.join
138
142
  if resized?
139
143
  resizing.resize_node(node)
140
144
  end
@@ -158,7 +162,7 @@ module HtmlSlicer
158
162
  else
159
163
  node.to_s
160
164
  end
161
- when HTML::Text then
165
+ when ::HTML::Text then
162
166
  if sliced?
163
167
  if range = slicing.map.get(node, slice)
164
168
  (range.is_a?(Array) ? node.content[Range.new(*range)] : node.content).tap do |export|
@@ -173,10 +177,10 @@ module HtmlSlicer
173
177
  else
174
178
  node.to_s
175
179
  end
176
- when HTML::CDATA then
180
+ when ::HTML::CDATA then
177
181
  node.to_s
178
- when HTML::Node then
179
- node.children.collect {|child| view(child, slice, &block)}.compact.join
182
+ when ::HTML::Node then
183
+ node.children.map {|child| view(child, slice, &block)}.compact.join
180
184
  end
181
185
  end
182
186
 
@@ -19,7 +19,7 @@ module HtmlSlicer
19
19
  end
20
20
 
21
21
  def initialize(document, options)
22
- raise(TypeError, "HTML::Document expected, '#{document.class}' passed") unless document.is_a?(HTML::Document)
22
+ raise(TypeError, "::HTML::Document expected, '#{document.class}' passed") unless document.is_a?(::HTML::Document)
23
23
  raise(TypeError, "HtmlSlicer::Options expected, '#{options.class}' passed") unless options.is_a?(HtmlSlicer::Options)
24
24
  @options = options
25
25
  @map = Map.new
@@ -42,8 +42,8 @@ module HtmlSlicer
42
42
 
43
43
  def process!(root)
44
44
  parse(root) do |node|
45
- if node.is_a?(HTML::Tag) && resizeable?(node)
46
- target_width = node.parent.is_a?(HTML::Tag) ? @map.width(node.parent)||@options.width : @options.width
45
+ if node.is_a?(::HTML::Tag) && resizeable?(node)
46
+ target_width = node.parent.is_a?(::HTML::Tag) ? @map.width(node.parent)||@options.width : @options.width
47
47
  if target_width.present? && node_width = width(node)
48
48
  node_height = height(node)
49
49
  if node_width > target_width
@@ -67,7 +67,7 @@ module HtmlSlicer
67
67
  values << absolute_resolution(node.attributes["width"])
68
68
  end
69
69
  if style = node.attributes["style"]
70
- style.gsub!(/width:\s+\d+(?=px);/) do |w|
70
+ style.gsub!(/(?<width:\s*>)(\d+)(?=px)/) do |w|
71
71
  if block_given?
72
72
  yield
73
73
  else
@@ -87,7 +87,7 @@ module HtmlSlicer
87
87
  values << absolute_resolution(node.attributes["height"])
88
88
  end
89
89
  if style = node.attributes["style"]
90
- style.gsub!(/height:\s+\d+(?=px);/) do |h|
90
+ style.gsub!(/(?<height:\s*>)(\d+)(?=px)/) do |h|
91
91
  if block_given?
92
92
  yield
93
93
  else
@@ -18,7 +18,7 @@ module HtmlSlicer
18
18
  end
19
19
 
20
20
  def initialize(document, options)
21
- raise(TypeError, "HTML::Document expected, '#{document.class}' passed") unless document.is_a?(HTML::Document)
21
+ raise(TypeError, "::HTML::Document expected, '#{document.class}' passed") unless document.is_a?(::HTML::Document)
22
22
  raise(TypeError, "HtmlSlicer::Options expected, '#{options.class}' passed") unless options.is_a?(HtmlSlicer::Options)
23
23
  @options = options
24
24
  @map = Map.new
@@ -34,7 +34,7 @@ module HtmlSlicer
34
34
  def process_by_text!(root)
35
35
  units_count = 0
36
36
  parse(root) do |node|
37
- if node.is_a?(HTML::Text) && sliceable?(node)
37
+ if node.is_a?(::HTML::Text) && sliceable?(node)
38
38
  sanitize_content!(node)
39
39
  content = node.to_s
40
40
  begin
@@ -87,7 +87,7 @@ module HtmlSlicer
87
87
  end
88
88
 
89
89
  def sanitize_content!(node)
90
- content = HTML::FullSanitizer.new.sanitize(node.to_s)
90
+ content = ::HTML::FullSanitizer.new.sanitize(node.to_s)
91
91
  node.instance_variable_set(:@content, content)
92
92
  end
93
93
 
@@ -2,7 +2,7 @@ require 'html_slicer/installer'
2
2
 
3
3
  module HtmlSlicer
4
4
  module ActiveRecordExtension
5
-
5
+
6
6
  def self.included(base)
7
7
  base.extend(ClassMethods)
8
8
  end
@@ -14,8 +14,7 @@ module HtmlSlicer
14
14
  end
15
15
 
16
16
  module InstanceMethods
17
-
18
17
  end
19
-
18
+
20
19
  end
21
20
  end
@@ -19,7 +19,7 @@ module HtmlSlicer
19
19
  end
20
20
 
21
21
  def string_value
22
- instance_variables.collect {|name| name.to_s + ":" + instance_variable_get(name).to_s}.join
22
+ instance_variables.map {|name| name.to_s + ":" + instance_variable_get(name).to_s}.join
23
23
  end
24
24
 
25
25
  end
@@ -5,7 +5,7 @@ module HtmlSlicer
5
5
  def parse(node, &block)
6
6
  node.children.each do |node|
7
7
  yield node if block_given?
8
- if node.is_a?(HTML::Tag)
8
+ if node.is_a?(::HTML::Tag)
9
9
  parse(node, &block)
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module HtmlSlicer
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,58 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_slicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valery Kvon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-05 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: actionpack
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: 3.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: 3.0.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: activesupport
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - '>='
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
19
  version: 3.0.0
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - '>='
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
26
  version: 3.0.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: active_tools
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - '>='
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: 0.0.2
33
+ version: 0.0.18
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - '>='
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: 0.0.2
55
- description: 'HTML truncation & pagination for Rails 3. Optional feature: recalculate
40
+ version: 0.0.18
41
+ description: 'HTML truncation & pagination for Rails 3+. Optional feature: recalculate
56
42
  resolution values of HTML tags (within width/height/style attributes).'
57
43
  email:
58
44
  - addagger@gmail.com
@@ -60,7 +46,7 @@ executables: []
60
46
  extensions: []
61
47
  extra_rdoc_files: []
62
48
  files:
63
- - .gitignore
49
+ - ".gitignore"
64
50
  - CHANGELOG
65
51
  - Gemfile
66
52
  - MIT-LICENSE
@@ -106,7 +92,7 @@ files:
106
92
  - lib/html_slicer/railtie.rb
107
93
  - lib/html_slicer/utilities.rb
108
94
  - lib/html_slicer/version.rb
109
- homepage: http://vkvon.ru/projects/html_slicer
95
+ homepage: http://github.com/addagger/html_slicer
110
96
  licenses:
111
97
  - MIT
112
98
  metadata: {}
@@ -116,17 +102,17 @@ require_paths:
116
102
  - lib
117
103
  required_ruby_version: !ruby/object:Gem::Requirement
118
104
  requirements:
119
- - - '>='
105
+ - - ">="
120
106
  - !ruby/object:Gem::Version
121
107
  version: '0'
122
108
  required_rubygems_version: !ruby/object:Gem::Requirement
123
109
  requirements:
124
- - - '>='
110
+ - - ">="
125
111
  - !ruby/object:Gem::Version
126
112
  version: '0'
127
113
  requirements: []
128
114
  rubyforge_project: html_slicer
129
- rubygems_version: 2.0.4
115
+ rubygems_version: 2.4.6
130
116
  signing_key:
131
117
  specification_version: 4
132
118
  summary: Paginate (split) long HTML text to pages and partials. Resize embeddings