html_slicer 0.1.2 → 0.1.7
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/CHANGELOG +21 -0
- data/Gemfile +1 -1
- data/html_slicer.gemspec +5 -4
- data/lib/html_slicer/config.rb +1 -2
- data/lib/html_slicer/engine.rb +3 -0
- data/lib/html_slicer/helpers/action_view_extension.rb +5 -4
- data/lib/html_slicer/helpers/slicer.rb +5 -5
- data/lib/html_slicer/helpers/tags.rb +7 -5
- data/lib/html_slicer/mappers/resizing.rb +12 -16
- data/lib/html_slicer/utilities.rb +0 -89
- data/lib/html_slicer/version.rb +1 -1
- metadata +25 -10
- data/lib/html_slicer/helpers/smart_params.rb +0 -35
data/CHANGELOG
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
== 0.1.6
|
2
|
+
|
3
|
+
* Dependency bugfixes.
|
4
|
+
|
5
|
+
== 0.1.5
|
6
|
+
|
7
|
+
* Gem description updated.
|
8
|
+
|
9
|
+
== 0.1.4
|
10
|
+
|
11
|
+
* Dependency bugfixes. Update with 'bundle update html_slicer'!
|
12
|
+
|
13
|
+
== 0.1.3
|
14
|
+
|
15
|
+
* Code refactored. Specific tools and methods extracted to stand-alone 'active_tools' gem.
|
16
|
+
|
17
|
+
== 0.1.2
|
18
|
+
|
19
|
+
* Visual separating (:text_break) functionality improved.
|
20
|
+
* "Read more": Now, pass dynamic content to the end of slice, directly from ActionView environment.
|
21
|
+
|
1
22
|
== 0.1.1
|
2
23
|
|
3
24
|
* Code optimized for speed.
|
data/Gemfile
CHANGED
data/html_slicer.gemspec
CHANGED
@@ -10,11 +10,12 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.authors = ["Valery Kvon"]
|
11
11
|
s.email = ["addagger@gmail.com"]
|
12
12
|
s.homepage = %q{http://vkvon.ru/projects/html_slicer}
|
13
|
-
s.summary = %q{HTML text
|
14
|
-
s.description = %q{HTML truncation & pagination for Rails 3.
|
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).}
|
15
15
|
|
16
|
-
s.
|
17
|
-
s.
|
16
|
+
s.add_dependency "actionpack", ['>= 3.0.0']
|
17
|
+
s.add_dependency "activesupport", ['>= 3.0.0']
|
18
|
+
s.add_dependency "active_tools", ['>= 0.0.2']
|
18
19
|
|
19
20
|
s.rubyforge_project = "html_slicer"
|
20
21
|
|
data/lib/html_slicer/config.rb
CHANGED
@@ -46,7 +46,6 @@ module HtmlSlicer
|
|
46
46
|
class Configuration #:nodoc:
|
47
47
|
|
48
48
|
include ActiveSupport::Configurable
|
49
|
-
include HtmlSlicer::Utilities::Deepcopy
|
50
49
|
|
51
50
|
config_accessor :as
|
52
51
|
config_accessor :slice
|
@@ -69,7 +68,7 @@ module HtmlSlicer
|
|
69
68
|
|
70
69
|
def duplicate
|
71
70
|
Configuration.new.tap do |c|
|
72
|
-
|
71
|
+
c.config.replace(config.deep_copy)
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
data/lib/html_slicer/engine.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
# This part of code is almost completely ported from +Kaminari+ gem by Akira Matsuda.
|
2
|
-
# Look at http://github.com/amatsuda/kaminari/tree/master/lib/kaminari/helpers
|
3
1
|
module HtmlSlicer
|
4
|
-
|
2
|
+
# This part of code is almost completely ported from +Kaminari+ gem by Akira Matsuda.
|
3
|
+
# Look at http://github.com/amatsuda/kaminari/tree/master/lib/kaminari/helpers
|
4
|
+
# ===================================================================================
|
5
|
+
#
|
5
6
|
# The part of code, processing the +:param_name+ was rewritten by me.
|
6
7
|
# Now you can define +:param_name+ as a +symbol+ or +string+, or as an +array of any object that responses +.to_s+ method and returns +string+.
|
7
8
|
# Passing +array+ is the way to define nested :param_name.
|
@@ -54,7 +55,7 @@ module HtmlSlicer
|
|
54
55
|
def link_to_next_slice(object, name, options = {}, &block)
|
55
56
|
params = options[:params] ? self.params.merge(options.delete :params) : self.params
|
56
57
|
param_name = options.delete(:param_name) || object.options.param_name
|
57
|
-
link_to_unless object.last_slice?, name,
|
58
|
+
link_to_unless object.last_slice?, name, params.merge_hashup(*param_name, object.current_slice + 1), options.reverse_merge(:rel => 'next') do
|
58
59
|
block.call if block
|
59
60
|
end
|
60
61
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
# This part of code is almost completely ported from +Kaminari+ gem by Akira Matsuda.
|
2
|
-
# Look at http://github.com/amatsuda/kaminari/tree/master/lib/kaminari/helpers
|
3
|
-
|
4
1
|
require 'active_support/inflector'
|
5
2
|
require 'action_view'
|
6
3
|
require 'action_view/log_subscriber'
|
7
4
|
require 'action_view/context'
|
8
|
-
require 'html_slicer/helpers/smart_params'
|
9
5
|
require 'html_slicer/helpers/tags'
|
10
6
|
|
11
7
|
module HtmlSlicer
|
12
8
|
|
13
9
|
module Helpers
|
10
|
+
# This part of code is almost completely ported from +Kaminari+ gem by Akira Matsuda.
|
11
|
+
# Look at http://github.com/amatsuda/kaminari/tree/master/lib/kaminari/helpers
|
12
|
+
# ===================================================================================
|
13
|
+
#
|
14
14
|
# The main container tag
|
15
|
-
|
15
|
+
#
|
16
16
|
# Configure ActiveSupport inflections to pluralize 'slice' in a correct way = 'slices'. # By default would be 'slouse'.
|
17
17
|
ActiveSupport::Inflector.inflections do |inflect|
|
18
18
|
inflect.plural 'slice', 'slices'
|
@@ -1,8 +1,10 @@
|
|
1
|
-
# This part of code is almost completely ported from +Kaminari+ gem by Akira Matsuda.
|
2
|
-
# Look at http://github.com/amatsuda/kaminari/tree/master/lib/kaminari/helpers
|
3
1
|
module HtmlSlicer
|
2
|
+
|
4
3
|
module Helpers
|
5
|
-
|
4
|
+
# This part of code is almost completely ported from +Kaminari+ gem by Akira Matsuda.
|
5
|
+
# Look at http://github.com/amatsuda/kaminari/tree/master/lib/kaminari/helpers
|
6
|
+
# ===================================================================================
|
7
|
+
#
|
6
8
|
# A tag stands for an HTML tag inside the paginator.
|
7
9
|
# Basically, a tag has its own partial template file, so every tag can be
|
8
10
|
# rendered into String using its partial template.
|
@@ -29,8 +31,8 @@ module HtmlSlicer
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def slice_url_for(slice)
|
32
|
-
#
|
33
|
-
@template.url_for
|
34
|
+
# +@params.merge_hashup+: returns deep merged params with a new slice number value.
|
35
|
+
@template.url_for @params.merge_hashup(*@param_name, (slice <= 1 ? nil : slice))
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
@@ -67,14 +67,12 @@ 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 |
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
w
|
77
|
-
end
|
70
|
+
style.gsub!(/width:\s+\d+(?=px);/) do |w|
|
71
|
+
if block_given?
|
72
|
+
yield
|
73
|
+
else
|
74
|
+
values << w.to_i
|
75
|
+
w
|
78
76
|
end
|
79
77
|
end
|
80
78
|
end
|
@@ -89,14 +87,12 @@ module HtmlSlicer
|
|
89
87
|
values << absolute_resolution(node.attributes["height"])
|
90
88
|
end
|
91
89
|
if style = node.attributes["style"]
|
92
|
-
style.gsub!(/height:\s+\d+px;/) do |
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
h
|
99
|
-
end
|
90
|
+
style.gsub!(/height:\s+\d+(?=px);/) do |h|
|
91
|
+
if block_given?
|
92
|
+
yield
|
93
|
+
else
|
94
|
+
values << h.to_i
|
95
|
+
h
|
100
96
|
end
|
101
97
|
end
|
102
98
|
end
|
@@ -17,95 +17,6 @@ module HtmlSlicer
|
|
17
17
|
[node.line, node.position]
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
21
|
-
module Deepcopy
|
22
|
-
# Return the 'deep' brand new copy of Hash or Array. All nested hashes/arrays rebuilded at the same way.
|
23
|
-
def deepcopy(object)
|
24
|
-
array_copy = Proc.new do |a|
|
25
|
-
duplicate = Array.new
|
26
|
-
a.each do |value|
|
27
|
-
duplicate << case value
|
28
|
-
when Hash then hash_copy.call(value)
|
29
|
-
when Array then array_copy.call(value)
|
30
|
-
else value
|
31
|
-
end
|
32
|
-
end
|
33
|
-
duplicate
|
34
|
-
end
|
35
|
-
hash_copy = Proc.new do |h|
|
36
|
-
duplicate = Hash.new
|
37
|
-
h.each do |key, value|
|
38
|
-
duplicate[key] = case value
|
39
|
-
when Hash then hash_copy.call(value)
|
40
|
-
when Array then array_copy.call(value)
|
41
|
-
else value
|
42
|
-
end
|
43
|
-
end
|
44
|
-
duplicate
|
45
|
-
end
|
46
|
-
case object
|
47
|
-
when Hash then hash_copy.call(object)
|
48
|
-
when Array then array_copy.call(object)
|
49
|
-
else object
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
module HashupArray
|
55
|
-
# Return a nested Hash object from Array's elements sequence, where elements used as names of +hash+ keys.
|
56
|
-
# The last element of array would be the last nested value.
|
57
|
-
#
|
58
|
-
# === Example:
|
59
|
-
#
|
60
|
-
# hashup([:vehicle, :car, :ford, :mustang, "2 please"])
|
61
|
-
#
|
62
|
-
# #=> {:vehicle=>{:car=>{:ford=>{:mustang=>"2 please"}}}}
|
63
|
-
def hashup(array)
|
64
|
-
raise(TypeError, "Array expected!") unless array.is_a?(Array)
|
65
|
-
raise(Exception, "At least 2 elements needed!") if array.size < 2
|
66
|
-
value = array.delete_at(-1)
|
67
|
-
{}.tap do |hash|
|
68
|
-
index = 0
|
69
|
-
while index < array.size
|
70
|
-
hash = hash[array.at(index)] = (index + 1 == array.size) ? value : {}
|
71
|
-
index += 1
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
module NestedMergeHash
|
78
|
-
include Deepcopy
|
79
|
-
|
80
|
-
# Return the merged Hash with another +hash+, where the possible child hashes are also merged.
|
81
|
-
#
|
82
|
-
# === Example:
|
83
|
-
#
|
84
|
-
# h1 = {:breakfast => {:eggs => 2, :bread => 1}, :lunch => {:steak => 1, :salad => 1}}
|
85
|
-
# h2 = {:breakfast => {:coffee => :espresso, :juice => 1}, :lunch => {:tea => 2}, :dinner => :none}
|
86
|
-
# nested_merge(h1, h2)
|
87
|
-
# #=> {:breakfast=>{:eggs=>2, :bread=>1, :coffee=>:espresso, :juice=>1}, :lunch=>{:steak=>1, :salad=>1, :tea=>2}, :dinner=>:none}
|
88
|
-
#
|
89
|
-
def nested_merge(hash, other_hash = {})
|
90
|
-
raise(TypeError, "Hash expected!") unless hash.is_a?(Hash)
|
91
|
-
a = Proc.new do |original, change|
|
92
|
-
change.each do |key, value|
|
93
|
-
if !original.has_key?(key) || !original[key].is_a?(Hash)
|
94
|
-
original[key] = value
|
95
|
-
elsif original[key].is_a?(Hash) && value.is_a?(Hash)
|
96
|
-
a.call(original[key], value)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
original
|
100
|
-
end
|
101
|
-
a.call(deepcopy(hash), other_hash)
|
102
|
-
end
|
103
|
-
|
104
|
-
# .nested_merge replaces the source hash.
|
105
|
-
def nested_merge!(hash, other_hash = {})
|
106
|
-
hash.replace(nested_merge(hash, other_hash = {}))
|
107
|
-
end
|
108
|
-
end
|
109
20
|
|
110
21
|
module NodeMatchExtension
|
111
22
|
|
data/lib/html_slicer/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_slicer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 3.0.0
|
22
|
-
type: :
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: 3.0.0
|
38
|
-
type: :
|
38
|
+
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
@@ -43,9 +43,24 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 3.0.0
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: active_tools
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.0.2
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.2
|
62
|
+
description: ! 'HTML truncation & pagination for Rails 3. Optional feature: recalculate
|
63
|
+
resolution values of HTML tags (within width/height/style attributes).'
|
49
64
|
email:
|
50
65
|
- addagger@gmail.com
|
51
66
|
executables: []
|
@@ -87,7 +102,6 @@ files:
|
|
87
102
|
- lib/html_slicer/engine.rb
|
88
103
|
- lib/html_slicer/helpers/action_view_extension.rb
|
89
104
|
- lib/html_slicer/helpers/slicer.rb
|
90
|
-
- lib/html_slicer/helpers/smart_params.rb
|
91
105
|
- lib/html_slicer/helpers/tags.rb
|
92
106
|
- lib/html_slicer/installer.rb
|
93
107
|
- lib/html_slicer/interface.rb
|
@@ -120,8 +134,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
134
|
version: '0'
|
121
135
|
requirements: []
|
122
136
|
rubyforge_project: html_slicer
|
123
|
-
rubygems_version: 1.8.
|
137
|
+
rubygems_version: 1.8.25
|
124
138
|
signing_key:
|
125
139
|
specification_version: 3
|
126
|
-
summary: HTML text
|
140
|
+
summary: Paginate (split) long HTML text to pages and partials. Resize embeddings
|
141
|
+
on fly. Flexible configuration.
|
127
142
|
test_files: []
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module HtmlSlicer
|
2
|
-
|
3
|
-
class SmartParams < Hash
|
4
|
-
# Implements smart and flexible +params+ merging.
|
5
|
-
# Method accepts passed +params+ hash and merge it with a new :+param_name+ and it's value.
|
6
|
-
# In the case when you passed +param_name+ option as an Array, method returns merged new
|
7
|
-
# instance of hashed params where all subhashes merged into the same way.
|
8
|
-
#
|
9
|
-
# === Example:
|
10
|
-
#
|
11
|
-
# params = {:controller => "comments", :action => "show", :id => 34, :article_id => 3, :page => {:article => 2}}
|
12
|
-
#
|
13
|
-
# :slice_params => [:page, :comment]
|
14
|
-
#
|
15
|
-
# HtmlSlicer::SmartParams.new(params, slice_params, 34)
|
16
|
-
# # => {:controller => "comments", :action => "show", :id => 34, :article_id => 3, :page => {:article => 2, :comment => 34}}
|
17
|
-
#
|
18
|
-
def initialize(params = {}, param_name = nil, value = nil)
|
19
|
-
super()
|
20
|
-
param_subhash = case param_name
|
21
|
-
when Array then hashup(param_name.collect {|e| e.to_s} << value)
|
22
|
-
when String, Symbol then {param_name.to_s => value}
|
23
|
-
else {}
|
24
|
-
end
|
25
|
-
update(nested_merge(params, param_subhash))
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
include HtmlSlicer::Utilities::HashupArray
|
31
|
-
include HtmlSlicer::Utilities::NestedMergeHash
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|