glam 0.1.0 → 0.1.1

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: a4a59bb7cf94a04f6965427b87ec36bdd271dda4
4
- data.tar.gz: 754b5ffb41d0b72f2b8bd049c32569e30dec667c
3
+ metadata.gz: ddedce9fb1adf54dfcc37baaa195c73359f18206
4
+ data.tar.gz: 4259c8efe06cf404a50e0456f1b782361adc6035
5
5
  SHA512:
6
- metadata.gz: 09830db411522642371cb0550b052da1b5276222649a71f11e4f6fd8804c3af876e3dec57f97f0b8bb2a3cf55f358f99e8212085b995ff501a88964671c2f5cb
7
- data.tar.gz: 87447b14ac94022d05d583f3e961164ffa9781c17cdbdbe1e8bf86bd7663cc61b96390ea9a53da23e99f391553d7ef96d130666f4de9c8a40c21c3d12785dc6a
6
+ metadata.gz: b798f1475de047e84359e59fbe6be3eeac59583385a396bef6c4592bd4ce4d924dea182ca7709103dc4879065112447b0bf9f3228c2c6b65da3add06dbe46ec4
7
+ data.tar.gz: 948a9bc1852b94a16c76122abb32e6d4b97eec583299be6f92a74621d20738ceebb79da131ad092f2930833ecc85e9d07e587b6dcfda8c248c29484d4c15cea0
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs = ["lib", "test"]
6
+ t.test_files = FileList["test/*_test.rb"]
7
+ end
8
+
9
+ task :default => :test
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "glam"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.1.1"
4
4
  spec.authors = ["Paul Barry"]
5
5
  spec.email = ["mail@paulbarry.com"]
6
6
  spec.description = %q{An HTML pretty printer}
@@ -1,7 +1,7 @@
1
1
  require 'glam/glamorizer'
2
2
 
3
3
  module Glam
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
6
6
 
7
7
  # Pretty-print the HTML
@@ -30,25 +30,36 @@ module Glam
30
30
  result = ''
31
31
  html
32
32
  else
33
- result = "<!doctype html>\n"
33
+ result = "<!doctype html>"
34
34
  Nokogiri::HTML(html).root
35
35
  end
36
36
 
37
37
  result << indented_node_with_attributes(node)
38
- self.current_indent += 1
39
- node.children.each do |child_node|
40
- if child_node.text?
41
- unless child_node.blank?
42
- result << "#{indent}#{child_node.content.strip}\n"
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
- elsif VOID_ELEMENTS.include?(child_node.name)
45
- result << indented_node_with_attributes(child_node)
55
+ end
56
+ self.current_indent -= 1
57
+ if current_indent < 1
58
+ result << "\n#{indent}</#{node.name}>\n"
46
59
  else
47
- result << glamorize(child_node)
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}>\n"
71
+ "\n#{indent}<#{node.name}#{node.attributes.map{|n,v| %{ #{n}="#{v}"}}.join}>"
61
72
  end
62
73
  end
63
74
 
@@ -0,0 +1,11 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>Comments</title>
5
+ </head>
6
+ <body>
7
+ <h1>Comments</h1>
8
+ <!-- What happens with comments? -->
9
+ <p>They should be preserved</p>
10
+ </body>
11
+ </html>
@@ -0,0 +1,14 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>Simple Example</title>
5
+ </head>
6
+ <body>
7
+ <h1>Simple Example</h1>
8
+ <p>
9
+ This is a paragraph with an
10
+ <a href="/">inline</a>
11
+ link
12
+ </p>
13
+ </body>
14
+ </html>
@@ -0,0 +1,11 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>Comments</title>
5
+ </head>
6
+ <body>
7
+ <h1>Comments</h1>
8
+ <!-- What happens with comments? -->
9
+ <p>They should be preserved</p>
10
+ </body>
11
+ </html>
@@ -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>
@@ -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.0
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-19 00:00:00.000000000 Z
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: