erbeautifier 0.1.0

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.
@@ -0,0 +1,27 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{RUBYFORGE_USERNAME}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{RUBYFORGE_USERNAME}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,9 @@
1
+ # stubs for the website generation
2
+ # To install the website framework:
3
+ # script/generate website
4
+
5
+ task :website_generate
6
+
7
+ task :website_upload
8
+
9
+ task :website => :publish_docs
@@ -0,0 +1,19 @@
1
+ module HtmlBeautifierTestUtilities
2
+
3
+ def code(str)
4
+ str = str.gsub(/\A\n|\n\s*\Z/, '')
5
+ indentation = str[/\A +/]
6
+ lines = str.split(/\n/)
7
+ lines.map{ |line| line.sub(/^#{indentation}/, '') }.join("\n")
8
+ end
9
+
10
+ def assert_beautifies(expected, source)
11
+ actual = ''
12
+ beautifier = HtmlBeautifier::Beautifier.new(actual)
13
+ beautifier.scan(source)
14
+ # puts expected
15
+ # puts actual
16
+ assert_equal expected, actual
17
+ end
18
+
19
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/htmlbeautifier'
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'htmlbeautifier/beautifier'
3
+ require 'html_beautifier_test_utilities'
4
+
5
+ class TestHtmlBeautifierIntegration < Test::Unit::TestCase
6
+
7
+ include HtmlBeautifierTestUtilities
8
+
9
+ def test_should_correctly_indent_mixed_document
10
+ source = code(%q(
11
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
12
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
13
+ <head>
14
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
15
+ <script src="/javascripts/prototype.js" type="text/javascript"></script>
16
+ <link rel="stylesheet" type="text/css" href="/stylesheets/screen.css" media="screen"/>
17
+ <!--[if IE 6]>
18
+ <link rel="stylesheet" href="/stylesheets/screen_ie6.css" type="text/css" />
19
+ <![endif]-->
20
+ <title>Title Goes Here</title>
21
+ <script type="text/javascript" charset="utf-8">
22
+ doSomething();
23
+ </script>
24
+ </head>
25
+ <body>
26
+ <div id="something">
27
+ <h1>
28
+ Heading 1
29
+ </h1>
30
+ </div>
31
+ <div id="somethingElse">
32
+ <p>Lorem Ipsum</p>
33
+ <% if @x -%>
34
+ <% @ys.each do |y| %>
35
+ <p>
36
+ <%= h y %>
37
+ </p>
38
+ <% end %>
39
+ <% elsif @z %>
40
+ <hr />
41
+ <% end %>
42
+ </div>
43
+ </body>
44
+ </html>
45
+ ))
46
+ expected = code(%q(
47
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
48
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
49
+ <head>
50
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
51
+ <script src="/javascripts/prototype.js" type="text/javascript"></script>
52
+ <link rel="stylesheet" type="text/css" href="/stylesheets/screen.css" media="screen"/>
53
+ <!--[if IE 6]>
54
+ <link rel="stylesheet" href="/stylesheets/screen_ie6.css" type="text/css" />
55
+ <![endif]-->
56
+ <title>Title Goes Here</title>
57
+ <script type="text/javascript" charset="utf-8">
58
+ doSomething();
59
+ </script>
60
+ </head>
61
+ <body>
62
+ <div id="something">
63
+ <h1>
64
+ Heading 1
65
+ </h1>
66
+ </div>
67
+ <div id="somethingElse">
68
+ <p>Lorem Ipsum</p>
69
+ <% if @x -%>
70
+ <% @ys.each do |y| %>
71
+ <p>
72
+ <%= h y %>
73
+ </p>
74
+ <% end %>
75
+ <% elsif @z %>
76
+ <hr />
77
+ <% end %>
78
+ </div>
79
+ </body>
80
+ </html>
81
+ ))
82
+ assert_beautifies expected, source
83
+ end
84
+
85
+ end
@@ -0,0 +1,182 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'htmlbeautifier/beautifier'
3
+ require 'html_beautifier_test_utilities'
4
+
5
+ class HtmlBeautifierRegressionTest < Test::Unit::TestCase
6
+
7
+ include HtmlBeautifierTestUtilities
8
+
9
+ def setup
10
+ # HtmlBeautifier::Parser.debug_block{ |match, method| puts("#{match.inspect} => #{method}") }
11
+ end
12
+
13
+ def test_should_ignore_html_fragments_in_embedded_code
14
+ source = code(%q(
15
+ <div>
16
+ <%= a[:b].gsub("\n","<br />\n") %>
17
+ </div>
18
+ ))
19
+ expected = code(%q(
20
+ <div>
21
+ <%= a[:b].gsub("\n","<br />\n") %>
22
+ </div>
23
+ ))
24
+ assert_beautifies expected, source
25
+ end
26
+
27
+ def test_should_indent_scripts
28
+ source = code(%q(
29
+ <script>
30
+ function(f) {
31
+ g();
32
+ return 42;
33
+ }
34
+ </script>
35
+ ))
36
+ expected = code(%q(
37
+ <script>
38
+ function(f) {
39
+ g();
40
+ return 42;
41
+ }
42
+ </script>
43
+ ))
44
+ assert_beautifies expected, source
45
+ end
46
+
47
+ def test_should_remove_blank_lines_around_scripts
48
+ source = code(%q(
49
+ <script>
50
+
51
+ f();
52
+
53
+ </script>
54
+ ))
55
+ expected = code(%q(
56
+ <script>
57
+ f();
58
+ </script>
59
+ ))
60
+ assert_beautifies expected, source
61
+ end
62
+
63
+ def test_should_remove_trailing_space_from_script_lines
64
+ source = code(%q(
65
+ <script>
66
+ f();
67
+ </script>
68
+ ))
69
+ expected = code(%q(
70
+ <script>
71
+ f();
72
+ </script>
73
+ ))
74
+ assert_beautifies expected, source
75
+ end
76
+
77
+ def test_should_skip_over_empty_scripts
78
+ source = %q(<script src="/foo.js" type="text/javascript" charset="utf-8"></script>)
79
+ expected = source
80
+ assert_beautifies expected, source
81
+ end
82
+
83
+ def test_should_indent_styles
84
+ source = code(%q(
85
+ <style>
86
+ .foo{ margin: 0; }
87
+ .bar{
88
+ padding: 0;
89
+ margin: 0;
90
+ }
91
+ </style>
92
+ ))
93
+ expected = code(%q(
94
+ <style>
95
+ .foo{ margin: 0; }
96
+ .bar{
97
+ padding: 0;
98
+ margin: 0;
99
+ }
100
+ </style>
101
+ ))
102
+ assert_beautifies expected, source
103
+ end
104
+
105
+ def test_should_remove_blank_lines_around_styles
106
+ source = code(%q(
107
+ <style>
108
+
109
+ .foo{ margin: 0; }
110
+
111
+ </style>
112
+ ))
113
+ expected = code(%q(
114
+ <style>
115
+ .foo{ margin: 0; }
116
+ </style>
117
+ ))
118
+ assert_beautifies expected, source
119
+ end
120
+
121
+ def test_should_remove_trailing_space_from_style_lines
122
+ source = code(%q(
123
+ <style>
124
+ .foo{ margin: 0; }
125
+ </style>
126
+ ))
127
+ expected = code(%q(
128
+ <style>
129
+ .foo{ margin: 0; }
130
+ </style>
131
+ ))
132
+ assert_beautifies expected, source
133
+ end
134
+
135
+ def test_should_indent_divs_containing_standalone_elements
136
+ source = code(%q(
137
+ <div>
138
+ <div>
139
+ <img src="foo" alt="" />
140
+ </div>
141
+ <div>
142
+ <img src="foo" alt="" />
143
+ </div>
144
+ </div>
145
+ ))
146
+ expected = source
147
+ assert_beautifies expected, source
148
+ end
149
+
150
+ def test_should_not_break_line_on_embedded_code_within_script_opening_element
151
+ source = '<script src="<%= path %>" type="text/javascript"></script>'
152
+ expected = source
153
+ assert_beautifies expected, source
154
+ end
155
+
156
+ def test_should_not_break_line_on_embedded_code_within_normal_element
157
+ source = '<img src="<%= path %>" alt="foo" />'
158
+ expected = source
159
+ assert_beautifies expected, source
160
+ end
161
+
162
+ def test_should_indent_inside_IE_conditional_comments
163
+ source = code(%q(
164
+ <!--[if IE 6]>
165
+ <link rel="stylesheet" href="/stylesheets/ie6.css" type="text/css" />
166
+ <![endif]-->
167
+ <!--[if IE 5]>
168
+ <link rel="stylesheet" href="/stylesheets/ie5.css" type="text/css" />
169
+ <![endif]-->
170
+ ))
171
+ expected = code(%q(
172
+ <!--[if IE 6]>
173
+ <link rel="stylesheet" href="/stylesheets/ie6.css" type="text/css" />
174
+ <![endif]-->
175
+ <!--[if IE 5]>
176
+ <link rel="stylesheet" href="/stylesheets/ie5.css" type="text/css" />
177
+ <![endif]-->
178
+ ))
179
+ assert_beautifies expected, source
180
+ end
181
+
182
+ end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'htmlbeautifier/parser'
3
+
4
+ class TestParser < Test::Unit::TestCase
5
+
6
+ class Receiver
7
+ attr_reader :sequence
8
+
9
+ def initialize
10
+ @sequence = []
11
+ end
12
+
13
+ def method_missing(method, *params)
14
+ @sequence << [method, params]
15
+ end
16
+ end
17
+
18
+ def setup
19
+ # HtmlBeautifier::Parser.debug_block{ |match, method| puts("#{match.inspect} => #{method}") }
20
+ end
21
+
22
+ def test_should_dispatch_matching_sequence
23
+ receiver = Receiver.new
24
+ parser = HtmlBeautifier::Parser.new{
25
+ map %r{foo}, :foo
26
+ map %r{bar\s*}, :bar
27
+ map %r{\s+}, :whitespace
28
+ }
29
+ parser.scan('foo bar ', receiver)
30
+ assert_equal [[:foo, ['foo']], [:whitespace, [' ']], [:bar, ['bar ']]], receiver.sequence
31
+ end
32
+
33
+ def test_should_send_parenthesized_components_as_separate_parameters
34
+ receiver = Receiver.new
35
+ parser = HtmlBeautifier::Parser.new{
36
+ map %r{(foo)\((.*?)\)}, :foo
37
+ }
38
+ parser.scan('foo(bar)', receiver)
39
+ assert_equal [[:foo, ['foo', 'bar']]], receiver.sequence
40
+ end
41
+
42
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erbeautifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ho-Sheng Hsiao
8
+ - Midwire
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-02-05 00:00:00 -06:00
14
+ default_executable: htmlbeautifier
15
+ dependencies: []
16
+
17
+ description: A normaliser/beautifier for HTML that also understands embedded Ruby. Ideal for tidying up Rails templates.
18
+ email: midwire@midwiretech.com
19
+ executables:
20
+ - htmlbeautifier
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - README.txt
25
+ files:
26
+ - .gitignore
27
+ - History.txt
28
+ - License.txt
29
+ - Manifest.txt
30
+ - README.txt
31
+ - Rakefile
32
+ - VERSION
33
+ - bin/htmlbeautifier
34
+ - config/hoe.rb
35
+ - config/requirements.rb
36
+ - erbeautifier.gemspec
37
+ - lib/htmlbeautifier.rb
38
+ - lib/htmlbeautifier/beautifier.rb
39
+ - lib/htmlbeautifier/parser.rb
40
+ - lib/htmlbeautifier/version.rb
41
+ - script/destroy
42
+ - script/generate
43
+ - setup.rb
44
+ - tasks/deployment.rake
45
+ - tasks/environment.rake
46
+ - tasks/website.rake
47
+ - test/html_beautifier_test_utilities.rb
48
+ - test/test_helper.rb
49
+ - test/test_html_beautifier_integration.rb
50
+ - test/test_html_beautifier_regression.rb
51
+ - test/test_parser.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/midwire/htmlbeautifier
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.5
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Beautifies your HTML erb templates. Midwire's fork of Ho-Sheng Hsiao's code. Bug fixes, etc.
80
+ test_files:
81
+ - test/html_beautifier_test_utilities.rb
82
+ - test/test_helper.rb
83
+ - test/test_html_beautifier_integration.rb
84
+ - test/test_html_beautifier_regression.rb
85
+ - test/test_parser.rb