hosh / htmlbeautifier

Beautifies your HTML erb templates. Imported from svn upstream; additional fixes to parse broken code properly.

htmlbeautifier / test / test_html_beautifier_integration.rb
100644 86 lines (81 sloc) 2.667 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require File.dirname(__FILE__) + '/test_helper'
require 'htmlbeautifier/beautifier'
require 'html_beautifier_test_utilities'
 
class TestHtmlBeautifierIntegration < Test::Unit::TestCase
  
  include HtmlBeautifierTestUtilities
  
  def test_should_correctly_indent_mixed_document
    source = code(%q(
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="/javascripts/prototype.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="/stylesheets/screen.css" media="screen"/>
<!--[if IE 6]>
<link rel="stylesheet" href="/stylesheets/screen_ie6.css" type="text/css" />
<![endif]-->
<title>Title Goes Here</title>
<script type="text/javascript" charset="utf-8">
doSomething();
</script>
</head>
<body>
<div id="something">
<h1>
Heading 1
</h1>
</div>
<div id="somethingElse">
<p>Lorem Ipsum</p>
<% if @x %>
<% @ys.each do |y| %>
<p>
<%= h y %>
</p>
<% end %>
<% elsif @z %>
<hr />
<% end %>
</div>
</body>
</html>
))
    expected = code(%q(
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="/javascripts/prototype.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="/stylesheets/screen.css" media="screen"/>
<!--[if IE 6]>
<link rel="stylesheet" href="/stylesheets/screen_ie6.css" type="text/css" />
<![endif]-->
<title>Title Goes Here</title>
<script type="text/javascript" charset="utf-8">
doSomething();
</script>
</head>
<body>
<div id="something">
<h1>
Heading 1
</h1>
</div>
<div id="somethingElse">
<p>Lorem Ipsum</p>
<% if @x %>
<% @ys.each do |y| %>
<p>
<%= h y %>
</p>
<% end %>
<% elsif @z %>
<hr />
<% end %>
</div>
</body>
</html>
))
    assert_beautifies expected, source
  end
 
end