hamlizer 0.0.3 → 0.0.4

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: 367d4b71fe6adf5eca2d1fb6714040b30fef3a74
4
- data.tar.gz: 04d83a5b169f332dc8fb613eaff0111b2b50352b
3
+ metadata.gz: 1ca7996fbf701443bb00171723fafac8f564a292
4
+ data.tar.gz: a5b584cc4513c41490b63c69dcdd939df8dbb661
5
5
  SHA512:
6
- metadata.gz: 07590ba8387e8cc60a8cd8ed49a994dc66db78d2d4890f696320a07c1b2892e5f8080c63fd58ce716431a59a27ec9ae3166e8d017d65fe903bdc2133e783ada7
7
- data.tar.gz: 2c9119ae7731393537a73e06e12457f98bb6f1aa18761deeba6269e80a71ca97cda0dc397a690a18f8f6881b392d0b1d92933fd6afd466b58039a67c8e2deda2
6
+ metadata.gz: 2cc8d74eaad65f544f6531729e0ddccebdc1d7bc4bb58df2c3e2d9c4cac7b2f460c73675b73f34732e5ae71eddf4dec0915c9307089cf041d21833eb61d4ed7e
7
+ data.tar.gz: 7b7623540838b0ca4a839b84924e6fa2f07816d767fdc1b399d2c99bae87383373bae18beb4a6172e83562f3590cc62db944f8e30c10d4f808c4bc6054901dcb
data/lib/hamlizer.rb CHANGED
@@ -15,9 +15,9 @@ module Hamlizer
15
15
  self.current_level = 0
16
16
  html.strip!
17
17
  html.squeeze! ' '
18
- convert_erb_to_parseable_xml!(html)
18
+ convert_erb_to_parseable_xml! html
19
19
 
20
- if html.start_with?('<html>')
20
+ if html.start_with? '<html>'
21
21
  root = Nokogiri::HTML.parse(html).root
22
22
  else
23
23
  root = Nokogiri::HTML::DocumentFragment.parse(html)
@@ -5,13 +5,17 @@ module Hamlizer
5
5
  end
6
6
 
7
7
  def haml
8
- element.has_attributes? ? (id_haml + class_haml + regular_attributes_haml) : ''
8
+ element.has_attributes? ? level_spacing + (id_haml + class_haml + regular_attributes_haml) : ''
9
9
  end
10
10
 
11
11
  private
12
12
 
13
13
  attr_reader :element
14
14
 
15
+ def level_spacing
16
+ element.div? ? (' ' * Hamlizer.current_level) : ''
17
+ end
18
+
15
19
  def attribute_haml(name, value)
16
20
  if name.match(/^\w+$/)
17
21
  attribute_name = "#{name}:"
@@ -1,3 +1,3 @@
1
1
  module Hamlizer
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -60,6 +60,10 @@ module Hamlizer
60
60
  expect(hamlize('<div>abc<p>hello<span>abc</span></p></div>')).to eq "%div\n abc\n %p\n hello\n %span abc"
61
61
  end
62
62
 
63
+ it 'converts nested divs with classes' do
64
+ expect(hamlize(content_from('nested_divs_with_classes.html.erb'))).to eq content_from('nested_divs_with_classes.html.haml')
65
+ end
66
+
63
67
  it 'converts a tag with attributes' do
64
68
  title = 'El Titulo'
65
69
  source = 'La Fuente'
@@ -0,0 +1,7 @@
1
+ <div class="class1 class2">
2
+ <div class="class3 class4">
3
+ <h1 class="class5">Control Center</h1>
4
+ <p> Hello There </p>
5
+ </div>
6
+ <div class="clear"></div>
7
+ </div>
@@ -0,0 +1,5 @@
1
+ .class1.class2
2
+ .class3.class4
3
+ %h1.class5 Control Center
4
+ %p Hello There
5
+ .clear
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamlizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lilibeth De La Cruz
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-24 00:00:00.000000000 Z
12
+ date: 2014-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -91,6 +91,8 @@ files:
91
91
  - spec/test_files/erb_on_root.html.haml
92
92
  - spec/test_files/if_else.html.erb
93
93
  - spec/test_files/if_else.html.haml
94
+ - spec/test_files/nested_divs_with_classes.html.erb
95
+ - spec/test_files/nested_divs_with_classes.html.haml
94
96
  - spec/test_files/spaces.html.erb
95
97
  - spec/test_files/spaces.html.haml
96
98
  - spec/test_files/with_extra_line_breaks.haml
@@ -115,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
117
  version: '0'
116
118
  requirements: []
117
119
  rubyforge_project:
118
- rubygems_version: 2.0.3
120
+ rubygems_version: 2.2.2
119
121
  signing_key:
120
122
  specification_version: 4
121
123
  summary: HTML/ERB to HAML converter
@@ -129,6 +131,8 @@ test_files:
129
131
  - spec/test_files/erb_on_root.html.haml
130
132
  - spec/test_files/if_else.html.erb
131
133
  - spec/test_files/if_else.html.haml
134
+ - spec/test_files/nested_divs_with_classes.html.erb
135
+ - spec/test_files/nested_divs_with_classes.html.haml
132
136
  - spec/test_files/spaces.html.erb
133
137
  - spec/test_files/spaces.html.haml
134
138
  - spec/test_files/with_extra_line_breaks.haml