html_slicer 0.0.5 → 0.0.6
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/README.rdoc +1 -1
- data/lib/html_slicer/resizing.rb +49 -6
- data/lib/html_slicer/utilities.rb +2 -2
- data/lib/html_slicer/version.rb +1 -1
- metadata +5 -5
data/README.rdoc
CHANGED
@@ -17,7 +17,7 @@ Bundle the gem, then your models are ready to implement slicing.
|
|
17
17
|
Besides global configuration (default), you can create stylized app-level configurations; also any configuration can be tuned for every single implementation.
|
18
18
|
|
19
19
|
=== Flexible options
|
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
|
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
23
|
Supports Rails 3 and multiple template engines (ERB, Haml).
|
data/lib/html_slicer/resizing.rb
CHANGED
@@ -24,15 +24,58 @@ module HtmlSlicer
|
|
24
24
|
able_to?(node, @options)
|
25
25
|
end
|
26
26
|
|
27
|
+
def width(node)
|
28
|
+
values = []
|
29
|
+
if block_given?
|
30
|
+
node.attributes["width"] = yield
|
31
|
+
else
|
32
|
+
values << absolute_resolution(node.attributes["width"])
|
33
|
+
end
|
34
|
+
if style = node.attributes["style"]
|
35
|
+
style.gsub!(/width:\s+\d+px;/) do |t|
|
36
|
+
t.gsub(/\d+/) do |w|
|
37
|
+
if block_given?
|
38
|
+
yield
|
39
|
+
else
|
40
|
+
values << w.to_i
|
41
|
+
w
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
values.compact.min
|
47
|
+
end
|
48
|
+
|
49
|
+
def height(node)
|
50
|
+
values = []
|
51
|
+
if block_given?
|
52
|
+
node.attributes["height"] = yield
|
53
|
+
else
|
54
|
+
values << absolute_resolution(node.attributes["height"])
|
55
|
+
end
|
56
|
+
if style = node.attributes["style"]
|
57
|
+
style.gsub!(/height:\s+\d+px;/) do |t|
|
58
|
+
t.gsub(/\d+/) do |h|
|
59
|
+
if block_given?
|
60
|
+
yield
|
61
|
+
else
|
62
|
+
values << h.to_i
|
63
|
+
h
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
values.compact.min
|
69
|
+
end
|
70
|
+
|
27
71
|
def resize!(node)
|
28
|
-
|
29
|
-
target_width
|
30
|
-
|
31
|
-
node_height = absolute_resolution(node.attributes["height"])
|
72
|
+
target_width = node.parent.is_a?(HTML::Tag) ? width(node.parent)||@options.width : nil
|
73
|
+
if target_width.present? && node_width = width(node)
|
74
|
+
node_height = height(node)
|
32
75
|
if node_width > target_width
|
33
76
|
ratio = node_width.to_f/target_width
|
34
|
-
node
|
35
|
-
node
|
77
|
+
width(node) { target_width.to_s }
|
78
|
+
height(node) { (node_height/ratio).round.to_s } if node_height
|
36
79
|
end
|
37
80
|
end
|
38
81
|
end
|
@@ -50,7 +50,7 @@ module HtmlSlicer
|
|
50
50
|
#
|
51
51
|
# === Example:
|
52
52
|
#
|
53
|
-
# [:vehicle, :car, :ford, :mustang, "2 please"]
|
53
|
+
# hashup([:vehicle, :car, :ford, :mustang, "2 please"])
|
54
54
|
#
|
55
55
|
# #=> {:vehicle=>{:car=>{:ford=>{:mustang=>"2 please"}}}}
|
56
56
|
def hashup(array)
|
@@ -77,7 +77,7 @@ module HtmlSlicer
|
|
77
77
|
#
|
78
78
|
# h1 = {:breakfast => {:eggs => 2, :bread => 1}, :lunch => {:steak => 1, :salad => 1}}
|
79
79
|
# h2 = {:breakfast => {:coffee => :espresso, :juice => 1}, :lunch => {:tea => 2}, :dinner => :none}
|
80
|
-
#
|
80
|
+
# nested_merge(h1, h2)
|
81
81
|
# #=> {:breakfast=>{:eggs=>2, :bread=>1, :coffee=>:espresso, :juice=>1}, :lunch=>{:steak=>1, :salad=>1, :tea=>2}, :dinner=>:none}
|
82
82
|
#
|
83
83
|
def nested_merge(hash, other_hash = {})
|
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.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70294283808420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70294283808420
|
25
25
|
description: HtmlSlicer is a smart way to cut an HTML text into pieces. It also provides
|
26
26
|
on option to resize "width"/"height" attributes of HTML tags, such as <iframe>,
|
27
27
|
<object>, <img> or any other.
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
100
|
rubyforge_project: html_slicer
|
101
|
-
rubygems_version: 1.8.
|
101
|
+
rubygems_version: 1.8.10
|
102
102
|
signing_key:
|
103
103
|
specification_version: 3
|
104
104
|
summary: HTML text slicer
|