html_slicer 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
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 (или the?) 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.
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).
@@ -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
- parent_width = node.parent.is_a?(HTML::Tag) ? absolute_resolution(node.parent.attributes["width"]) : nil
29
- target_width = parent_width.present? ? parent_width.to_i : @options.width
30
- if target_width.present? && node_width = absolute_resolution(node.attributes["width"])
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.attributes["width"] = target_width.to_s
35
- node.attributes["height"] = (node_height/ratio).round.to_s if node_height
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"].hashup
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
- # h1.nested_merge(h2)
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 = {})
@@ -1,3 +1,3 @@
1
1
  module HtmlSlicer
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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.5
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-02-20 00:00:00.000000000 Z
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: &70305272402260 !ruby/object:Gem::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: *70305272402260
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.16
101
+ rubygems_version: 1.8.10
102
102
  signing_key:
103
103
  specification_version: 3
104
104
  summary: HTML text slicer