glam 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/Rakefile +8 -0
- data/glam.gemspec +1 -1
- data/lib/glam.rb +1 -1
- data/lib/glam/glamorizer.rb +23 -12
- data/test/examples/expected/comments.html +11 -0
- data/test/examples/expected/simple.html +14 -0
- data/test/examples/source/comments.html +11 -0
- data/test/examples/source/simple.html +1 -0
- data/test/glam_test.rb +34 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddedce9fb1adf54dfcc37baaa195c73359f18206
|
4
|
+
data.tar.gz: 4259c8efe06cf404a50e0456f1b782361adc6035
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b798f1475de047e84359e59fbe6be3eeac59583385a396bef6c4592bd4ce4d924dea182ca7709103dc4879065112447b0bf9f3228c2c6b65da3add06dbe46ec4
|
7
|
+
data.tar.gz: 948a9bc1852b94a16c76122abb32e6d4b97eec583299be6f92a74621d20738ceebb79da131ad092f2930833ecc85e9d07e587b6dcfda8c248c29484d4c15cea0
|
data/Rakefile
CHANGED
data/glam.gemspec
CHANGED
data/lib/glam.rb
CHANGED
data/lib/glam/glamorizer.rb
CHANGED
@@ -30,25 +30,36 @@ module Glam
|
|
30
30
|
result = ''
|
31
31
|
html
|
32
32
|
else
|
33
|
-
result = "<!doctype html
|
33
|
+
result = "<!doctype html>"
|
34
34
|
Nokogiri::HTML(html).root
|
35
35
|
end
|
36
36
|
|
37
37
|
result << indented_node_with_attributes(node)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
if node.children.size == 1 and node.children.first.text?
|
39
|
+
child_node = node.children.first
|
40
|
+
result << "#{child_node.content.strip}</#{node.name}>"
|
41
|
+
else
|
42
|
+
self.current_indent += 1
|
43
|
+
node.children.each do |child_node|
|
44
|
+
if child_node.text?
|
45
|
+
unless child_node.blank?
|
46
|
+
result << "\n#{indent}#{child_node.content.strip}"
|
47
|
+
end
|
48
|
+
elsif child_node.comment?
|
49
|
+
result << "\n#{indent}<!-- #{child_node.content.strip} -->"
|
50
|
+
elsif VOID_ELEMENTS.include?(child_node.name)
|
51
|
+
result << "\n#{indented_node_with_attributes(child_node)}"
|
52
|
+
else
|
53
|
+
result << glamorize(child_node)
|
43
54
|
end
|
44
|
-
|
45
|
-
|
55
|
+
end
|
56
|
+
self.current_indent -= 1
|
57
|
+
if current_indent < 1
|
58
|
+
result << "\n#{indent}</#{node.name}>\n"
|
46
59
|
else
|
47
|
-
result <<
|
60
|
+
result << "\n#{indent}</#{node.name}>"
|
48
61
|
end
|
49
62
|
end
|
50
|
-
self.current_indent -= 1
|
51
|
-
result << "#{indent}</#{node.name}>\n"
|
52
63
|
end
|
53
64
|
|
54
65
|
private
|
@@ -57,7 +68,7 @@ module Glam
|
|
57
68
|
end
|
58
69
|
|
59
70
|
def indented_node_with_attributes(node)
|
60
|
-
"#{indent}<#{node.name}#{node.attributes.map{|n,v| %{ #{n}="#{v}"}}.join}
|
71
|
+
"\n#{indent}<#{node.name}#{node.attributes.map{|n,v| %{ #{n}="#{v}"}}.join}>"
|
61
72
|
end
|
62
73
|
end
|
63
74
|
|
@@ -0,0 +1 @@
|
|
1
|
+
<html><head><title>Simple Example</title></head><body><h1>Simple Example</h1><p>This is a paragraph with an <a href="/">inline</a>link</body></html>
|
data/test/glam_test.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'glam'
|
3
|
+
|
4
|
+
class GlamTest < MiniTest::Unit::TestCase
|
5
|
+
def initialize(name=nil)
|
6
|
+
@test_name = name
|
7
|
+
super(name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.test(name, &block)
|
11
|
+
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
12
|
+
defined = instance_method(test_name) rescue false
|
13
|
+
raise "#{test_name} is already defined in #{self}" if defined
|
14
|
+
if block_given?
|
15
|
+
define_method(test_name, &block)
|
16
|
+
else
|
17
|
+
define_method(test_name) do
|
18
|
+
flunk "No implementation provided for #{name}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
source_dir = File.expand_path("examples/source/*.html", File.dirname(__FILE__))
|
24
|
+
Dir[source_dir].each do |example|
|
25
|
+
test File.basename(example, '.html') do
|
26
|
+
actual = Glam(File.read(example))
|
27
|
+
#puts actual
|
28
|
+
assert_equal(
|
29
|
+
File.read(example.sub(/(.*)(source)(.*)/, '\1expected\3')),
|
30
|
+
actual)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -70,6 +70,11 @@ files:
|
|
70
70
|
- lib/glam.rb
|
71
71
|
- lib/glam/cli.rb
|
72
72
|
- lib/glam/glamorizer.rb
|
73
|
+
- test/examples/expected/comments.html
|
74
|
+
- test/examples/expected/simple.html
|
75
|
+
- test/examples/source/comments.html
|
76
|
+
- test/examples/source/simple.html
|
77
|
+
- test/glam_test.rb
|
73
78
|
homepage: http://github.com/pjb3/glam
|
74
79
|
licenses:
|
75
80
|
- MIT
|
@@ -94,5 +99,10 @@ rubygems_version: 2.0.14
|
|
94
99
|
signing_key:
|
95
100
|
specification_version: 4
|
96
101
|
summary: Make your HTML look glamorous!
|
97
|
-
test_files:
|
102
|
+
test_files:
|
103
|
+
- test/examples/expected/comments.html
|
104
|
+
- test/examples/expected/simple.html
|
105
|
+
- test/examples/source/comments.html
|
106
|
+
- test/examples/source/simple.html
|
107
|
+
- test/glam_test.rb
|
98
108
|
has_rdoc:
|