hamlet 0.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.
- data/.gitignore +1 -0
- data/Gemfile +25 -0
- data/LICENSE +21 -0
- data/README.md +52 -0
- data/Rakefile +57 -0
- data/bin/hamletrb +7 -0
- data/extra/slim-mode.el +409 -0
- data/extra/test.hamlet +50 -0
- data/hamlet.gemspec +36 -0
- data/lib/hamlet.rb +7 -0
- data/lib/hamlet/engine.rb +3 -0
- data/lib/hamlet/parser.rb +147 -0
- data/lib/hamlet/template.rb +19 -0
- data/test/rails/Rakefile +7 -0
- data/test/rails/app/controllers/application_controller.rb +3 -0
- data/test/rails/app/controllers/parents_controller.rb +84 -0
- data/test/rails/app/controllers/slim_controller.rb +32 -0
- data/test/rails/app/helpers/application_helper.rb +2 -0
- data/test/rails/app/models/child.rb +3 -0
- data/test/rails/app/models/parent.rb +4 -0
- data/test/rails/app/views/layouts/application.html.slim +10 -0
- data/test/rails/app/views/parents/_form.html.slim +7 -0
- data/test/rails/app/views/parents/edit.html.slim +1 -0
- data/test/rails/app/views/parents/new.html.slim +1 -0
- data/test/rails/app/views/parents/show.html.slim +5 -0
- data/test/rails/app/views/slim/_partial.html.slim +1 -0
- data/test/rails/app/views/slim/content_for.html.slim +7 -0
- data/test/rails/app/views/slim/erb.html.erb +1 -0
- data/test/rails/app/views/slim/integers.html.slim +1 -0
- data/test/rails/app/views/slim/nil.html.slim +1 -0
- data/test/rails/app/views/slim/no_layout.html.slim +1 -0
- data/test/rails/app/views/slim/normal.html.slim +1 -0
- data/test/rails/app/views/slim/partial.html.slim +2 -0
- data/test/rails/app/views/slim/variables.html.slim +1 -0
- data/test/rails/config.ru +4 -0
- data/test/rails/config/application.rb +45 -0
- data/test/rails/config/boot.rb +10 -0
- data/test/rails/config/database.yml +4 -0
- data/test/rails/config/environment.rb +5 -0
- data/test/rails/config/environments/development.rb +26 -0
- data/test/rails/config/environments/production.rb +49 -0
- data/test/rails/config/environments/test.rb +35 -0
- data/test/rails/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails/config/initializers/inflections.rb +10 -0
- data/test/rails/config/initializers/mime_types.rb +5 -0
- data/test/rails/config/initializers/secret_token.rb +7 -0
- data/test/rails/config/initializers/session_store.rb +8 -0
- data/test/rails/config/locales/en.yml +5 -0
- data/test/rails/config/routes.rb +60 -0
- data/test/rails/db/migrate/20101220223037_parents_and_children.rb +17 -0
- data/test/rails/script/rails +6 -0
- data/test/rails/test/helper.rb +10 -0
- data/test/rails/test/test_slim.rb +77 -0
- data/test/slim/helper.rb +200 -0
- data/test/slim/test_chain_manipulation.rb +42 -0
- data/test/slim/test_code_blocks.rb +68 -0
- data/test/slim/test_code_escaping.rb +53 -0
- data/test/slim/test_code_evaluation.rb +281 -0
- data/test/slim/test_code_output.rb +159 -0
- data/test/slim/test_code_structure.rb +95 -0
- data/test/slim/test_embedded_engines.rb +141 -0
- data/test/slim/test_html_escaping.rb +40 -0
- data/test/slim/test_html_structure.rb +438 -0
- data/test/slim/test_parser_errors.rb +107 -0
- data/test/slim/test_pretty.rb +75 -0
- data/test/slim/test_ruby_errors.rb +187 -0
- data/test/slim/test_sections.rb +90 -0
- data/test/slim/test_slim_template.rb +118 -0
- data/test/slim/test_text_interpolation.rb +78 -0
- data/test/slim/test_wrapper.rb +39 -0
- metadata +230 -0
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimCodeOutput < TestSlim
|
4
|
+
def test_render_with_call
|
5
|
+
source = %q{
|
6
|
+
p
|
7
|
+
= hello_world
|
8
|
+
}
|
9
|
+
|
10
|
+
assert_html '<p>Hello World from @env</p>', source
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_render_with_trailing_whitespace
|
14
|
+
source = %q{
|
15
|
+
p
|
16
|
+
=' hello_world
|
17
|
+
}
|
18
|
+
|
19
|
+
assert_html '<p>Hello World from @env </p>', source
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_render_with_trailing_whitespace_after_tag
|
23
|
+
source = %q{
|
24
|
+
p=' hello_world
|
25
|
+
}
|
26
|
+
|
27
|
+
assert_html '<p>Hello World from @env</p> ', source
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_no_escape_render_with_trailing_whitespace
|
31
|
+
source = %q{
|
32
|
+
p
|
33
|
+
==' hello_world
|
34
|
+
}
|
35
|
+
|
36
|
+
assert_html '<p>Hello World from @env </p>', source
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_no_escape_render_with_trailing_whitespace_after_tag
|
40
|
+
source = %q{
|
41
|
+
p==' hello_world
|
42
|
+
}
|
43
|
+
|
44
|
+
assert_html '<p>Hello World from @env</p> ', source
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_render_with_conditional_call
|
48
|
+
source = %q{
|
49
|
+
p
|
50
|
+
= hello_world if true
|
51
|
+
}
|
52
|
+
|
53
|
+
assert_html '<p>Hello World from @env</p>', source
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_render_with_parameterized_call
|
57
|
+
source = %q{
|
58
|
+
p
|
59
|
+
= hello_world("Hello Ruby!")
|
60
|
+
}
|
61
|
+
|
62
|
+
assert_html '<p>Hello Ruby!</p>', source
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_render_with_spaced_parameterized_call
|
66
|
+
source = %q{
|
67
|
+
p
|
68
|
+
= hello_world "Hello Ruby!"
|
69
|
+
}
|
70
|
+
|
71
|
+
assert_html '<p>Hello Ruby!</p>', source
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_render_with_spaced_parameterized_call_2
|
75
|
+
source = %q{
|
76
|
+
p
|
77
|
+
= hello_world "Hello Ruby!", :dummy => "value"
|
78
|
+
}
|
79
|
+
|
80
|
+
assert_html '<p>Hello Ruby!dummy value</p>', source
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_render_with_call_and_inline_text
|
84
|
+
source = %q{
|
85
|
+
h1 This is my title
|
86
|
+
p
|
87
|
+
= hello_world
|
88
|
+
}
|
89
|
+
|
90
|
+
assert_html '<h1>This is my title</h1><p>Hello World from @env</p>', source
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_render_with_attribute_starts_with_keyword
|
94
|
+
source = %q{
|
95
|
+
p = hello_world in_keyword
|
96
|
+
}
|
97
|
+
|
98
|
+
assert_html '<p>starts with keyword</p>', source
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_hash_call
|
102
|
+
source = %q{
|
103
|
+
p = hash[:a]
|
104
|
+
}
|
105
|
+
|
106
|
+
assert_html '<p>The letter a</p>', source
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_tag_output_without_space
|
110
|
+
source = %q{
|
111
|
+
p= hello_world
|
112
|
+
p=hello_world
|
113
|
+
}
|
114
|
+
|
115
|
+
assert_html '<p>Hello World from @env</p><p>Hello World from @env</p>', source
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_class_output_without_space
|
119
|
+
source = %q{
|
120
|
+
.test=hello_world
|
121
|
+
#test==hello_world
|
122
|
+
}
|
123
|
+
|
124
|
+
assert_html '<div class="test">Hello World from @env</div><div id="test">Hello World from @env</div>', source
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_attribute_output_without_space
|
128
|
+
source = %q{
|
129
|
+
p id="test"=hello_world
|
130
|
+
p(id="test")==hello_world
|
131
|
+
}
|
132
|
+
|
133
|
+
assert_html '<p id="test">Hello World from @env</p><p id="test">Hello World from @env</p>', source
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_render_with_backslash_end
|
137
|
+
# Keep trailing spaces!
|
138
|
+
source = %q{
|
139
|
+
p = \
|
140
|
+
"Hello" + \
|
141
|
+
" Ruby!"
|
142
|
+
- variable = 1 + \
|
143
|
+
2 + \
|
144
|
+
3
|
145
|
+
= variable + \
|
146
|
+
1
|
147
|
+
}
|
148
|
+
|
149
|
+
assert_html '<p>Hello Ruby!</p>7', source
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_render_with_no_trailing_character
|
153
|
+
source = %q{
|
154
|
+
p
|
155
|
+
= hello_world}
|
156
|
+
|
157
|
+
assert_html '<p>Hello World from @env</p>', source
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimCodeStructure < TestSlim
|
4
|
+
def test_render_with_conditional
|
5
|
+
source = %q{
|
6
|
+
div
|
7
|
+
- if show_first?
|
8
|
+
p The first paragraph
|
9
|
+
- else
|
10
|
+
p The second paragraph
|
11
|
+
}
|
12
|
+
|
13
|
+
assert_html '<div><p>The second paragraph</p></div>', source
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_render_with_consecutive_conditionals
|
17
|
+
source = %q{
|
18
|
+
div
|
19
|
+
- if show_first? true
|
20
|
+
p The first paragraph
|
21
|
+
- if show_first? true
|
22
|
+
p The second paragraph
|
23
|
+
}
|
24
|
+
|
25
|
+
assert_html '<div><p>The first paragraph</p><p>The second paragraph</p></div>', source
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_render_with_parameterized_conditional
|
29
|
+
source = %q{
|
30
|
+
div
|
31
|
+
- if show_first? false
|
32
|
+
p The first paragraph
|
33
|
+
- else
|
34
|
+
p The second paragraph
|
35
|
+
}
|
36
|
+
|
37
|
+
assert_html '<div><p>The second paragraph</p></div>', source
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_render_with_conditional_and_following_nonconditonal
|
41
|
+
source = %q{
|
42
|
+
div
|
43
|
+
- if true
|
44
|
+
p The first paragraph
|
45
|
+
- var = 42
|
46
|
+
= var
|
47
|
+
}
|
48
|
+
|
49
|
+
assert_html '<div><p>The first paragraph</p>42</div>', source
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_render_with_inline_condition
|
53
|
+
source = %q{
|
54
|
+
p = hello_world if true
|
55
|
+
}
|
56
|
+
|
57
|
+
assert_html '<p>Hello World from @env</p>', source
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_render_with_case
|
61
|
+
source = %q{
|
62
|
+
p
|
63
|
+
- case 42
|
64
|
+
- when 41
|
65
|
+
| 1
|
66
|
+
- when 42
|
67
|
+
| 42
|
68
|
+
| is the answer
|
69
|
+
}
|
70
|
+
|
71
|
+
assert_html '<p>42 is the answer</p>', source
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_render_with_slim_comments
|
75
|
+
source = %q{
|
76
|
+
p Hello
|
77
|
+
/ This is a comment
|
78
|
+
Another comment
|
79
|
+
p World
|
80
|
+
}
|
81
|
+
|
82
|
+
assert_html '<p>Hello</p><p>World</p>', source
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_render_with_yield
|
86
|
+
source = %q{
|
87
|
+
div
|
88
|
+
== yield :menu
|
89
|
+
}
|
90
|
+
|
91
|
+
assert_html '<div>This is the menu</div>', source do
|
92
|
+
'This is the menu'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimEmbeddedEngines < TestSlim
|
4
|
+
def test_render_with_erb
|
5
|
+
source = %q{
|
6
|
+
p
|
7
|
+
- text = 'before erb block'
|
8
|
+
erb:
|
9
|
+
<b>Hello from <%= text.upcase %>!</b>
|
10
|
+
Second Line!
|
11
|
+
<% if true %><%= true %><% end %>
|
12
|
+
}
|
13
|
+
|
14
|
+
assert_html "<p><b>Hello from BEFORE ERB BLOCK!</b>\nSecond Line!\ntrue</p>", source
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_render_with_markdown
|
18
|
+
# Keep the trailing spaces.
|
19
|
+
source = %q{
|
20
|
+
markdown:
|
21
|
+
#Header
|
22
|
+
Hello from #{"Markdown!"}
|
23
|
+
|
24
|
+
#{1+2}
|
25
|
+
|
26
|
+
* one
|
27
|
+
* two
|
28
|
+
}
|
29
|
+
assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
|
30
|
+
|
31
|
+
Slim::EmbeddedEngine.default_options[:markdown] = {:auto_ids => false}
|
32
|
+
assert_html "<h1>Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
|
33
|
+
Slim::EmbeddedEngine.default_options[:markdown] = nil
|
34
|
+
|
35
|
+
assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_render_with_creole
|
39
|
+
source = %q{
|
40
|
+
creole:
|
41
|
+
= head1
|
42
|
+
== head2
|
43
|
+
}
|
44
|
+
assert_html "<h1>head1</h1><h2>head2</h2>", source
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_render_with_builder
|
48
|
+
source = %q{
|
49
|
+
builder:
|
50
|
+
xml.p(:id => 'test') {
|
51
|
+
xml.text!('Hello')
|
52
|
+
}
|
53
|
+
}
|
54
|
+
assert_html "<p id=\"test\">\nHello</p>\n", source
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_render_with_wiki
|
58
|
+
source = %q{
|
59
|
+
wiki:
|
60
|
+
= head1
|
61
|
+
== head2
|
62
|
+
}
|
63
|
+
assert_html "<h1>head1</h1><h2>head2</h2>", source
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_render_with_javascript
|
67
|
+
# Keep the trailing space behind "javascript: "!
|
68
|
+
source = %q{
|
69
|
+
javascript:
|
70
|
+
$(function() {});
|
71
|
+
|
72
|
+
|
73
|
+
alert('hello')
|
74
|
+
p Hi
|
75
|
+
}
|
76
|
+
assert_html %{<script type="text/javascript">$(function() {});\n\n\nalert('hello')</script><p>Hi</p>}, source
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_render_with_javascript_including_variable
|
80
|
+
# Keep the trailing space behind "javascript: "!
|
81
|
+
source = %q{
|
82
|
+
- func = "alert('hello');"
|
83
|
+
javascript:
|
84
|
+
$(function() { #{func} });
|
85
|
+
}
|
86
|
+
assert_html %q|<script type="text/javascript">$(function() { alert('hello'); });</script>|, source
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_render_with_ruby
|
90
|
+
source = %q{
|
91
|
+
ruby:
|
92
|
+
variable = 1 +
|
93
|
+
2
|
94
|
+
= variable
|
95
|
+
}
|
96
|
+
assert_html '3', source
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_render_with_scss
|
100
|
+
source = %q{
|
101
|
+
scss:
|
102
|
+
$color: #f00;
|
103
|
+
body { color: $color; }
|
104
|
+
}
|
105
|
+
assert_html "<style type=\"text/css\">body{color:red}</style>", source
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_disabled_embedded_engine
|
109
|
+
source = %{
|
110
|
+
ruby:
|
111
|
+
Embedded Ruby
|
112
|
+
}
|
113
|
+
assert_runtime_error 'Embedded engine ruby is disabled', source, :enable_engines => %w(javascript)
|
114
|
+
|
115
|
+
source = %{
|
116
|
+
ruby:
|
117
|
+
Embedded Ruby
|
118
|
+
}
|
119
|
+
assert_runtime_error 'Embedded engine ruby is disabled', source, :enable_engines => %w(javascript)
|
120
|
+
|
121
|
+
source = %{
|
122
|
+
ruby:
|
123
|
+
Embedded Ruby
|
124
|
+
}
|
125
|
+
assert_runtime_error 'Embedded engine ruby is disabled', source, :disable_engines => %w(ruby)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_enabled_embedded_engine
|
129
|
+
source = %q{
|
130
|
+
javascript:
|
131
|
+
$(function() {});
|
132
|
+
}
|
133
|
+
assert_html '<script type="text/javascript">$(function() {});</script>', source, :disable_engines => %w(ruby)
|
134
|
+
|
135
|
+
source = %q{
|
136
|
+
javascript:
|
137
|
+
$(function() {});
|
138
|
+
}
|
139
|
+
assert_html '<script type="text/javascript">$(function() {});</script>', source, :enable_engines => %w(javascript)
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimHtmlEscaping < TestSlim
|
4
|
+
def test_html_will_not_be_escaped
|
5
|
+
source = %q{
|
6
|
+
p <Hello> World, meet "Slim".
|
7
|
+
}
|
8
|
+
|
9
|
+
assert_html '<p><Hello> World, meet "Slim".</p>', source
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_html_with_newline_will_not_be_escaped
|
13
|
+
source = %q{
|
14
|
+
p
|
15
|
+
|
|
16
|
+
<Hello> World,
|
17
|
+
meet "Slim".
|
18
|
+
}
|
19
|
+
|
20
|
+
assert_html "<p><Hello> World,\n meet \"Slim\".</p>", source
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_html_with_escaped_interpolation
|
24
|
+
source = %q{
|
25
|
+
- x = '"'
|
26
|
+
- content = '<x>'
|
27
|
+
p class="#{x}" test #{content}
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_html '<p class=""">test <x></p>', source
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_html_nested_escaping
|
34
|
+
source = %q{
|
35
|
+
= hello_world do
|
36
|
+
| escaped &
|
37
|
+
}
|
38
|
+
assert_html 'Hello World from @env escaped & Hello World from @env', source
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,438 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimHtmlStructure < TestSlim
|
4
|
+
def test_simple_render
|
5
|
+
# Keep the trailing space behind "body "!
|
6
|
+
source = %q{
|
7
|
+
html
|
8
|
+
head
|
9
|
+
title Simple Test Title
|
10
|
+
body
|
11
|
+
p Hello World, meet Slim.
|
12
|
+
}
|
13
|
+
|
14
|
+
assert_html '<html><head><title>Simple Test Title</title></head><body><p>Hello World, meet Slim.</p></body></html>', source
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_html_tag_with_text_and_empty_line
|
18
|
+
# Keep the trailing space behind "body "!
|
19
|
+
source = %q{
|
20
|
+
p Hello
|
21
|
+
|
22
|
+
p World
|
23
|
+
}
|
24
|
+
|
25
|
+
assert_html "<p>Hello</p><p>World</p>", source
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_html_namespaces
|
29
|
+
source = %q{
|
30
|
+
html:body
|
31
|
+
html:p html:id="test" Text
|
32
|
+
}
|
33
|
+
|
34
|
+
assert_html '<html:body><html:p html:id="test">Text</html:p></html:body>', source
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_doctype
|
38
|
+
source = %q{
|
39
|
+
doctype 1.1
|
40
|
+
html
|
41
|
+
}
|
42
|
+
|
43
|
+
assert_html '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html></html>', source, :format => :xhtml
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_doctype_new_syntax
|
47
|
+
source = %q{
|
48
|
+
doctype 5
|
49
|
+
html
|
50
|
+
}
|
51
|
+
|
52
|
+
assert_html '<!DOCTYPE html><html></html>', source, :format => :xhtml
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_doctype_new_syntax_html5
|
56
|
+
source = %q{
|
57
|
+
doctype html
|
58
|
+
html
|
59
|
+
}
|
60
|
+
|
61
|
+
assert_html '<!DOCTYPE html><html></html>', source, :format => :xhtml
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_render_with_shortcut_attributes
|
65
|
+
source = %q{
|
66
|
+
h1#title This is my title
|
67
|
+
#notice.hello.world
|
68
|
+
= hello_world
|
69
|
+
}
|
70
|
+
|
71
|
+
assert_html '<h1 id="title">This is my title</h1><div class="hello world" id="notice">Hello World from @env</div>', source
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_render_with_overwritten_default_tag
|
75
|
+
source = %q{
|
76
|
+
#notice.hello.world
|
77
|
+
= hello_world
|
78
|
+
}
|
79
|
+
|
80
|
+
assert_html '<section class="hello world" id="notice">Hello World from @env</section>', source, :default_tag => 'section'
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_render_with_text_block
|
84
|
+
source = %q{
|
85
|
+
p
|
86
|
+
|
|
87
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
88
|
+
}
|
89
|
+
|
90
|
+
assert_html '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>', source
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_render_with_text_block_with_subsequent_markup
|
94
|
+
source = %q{
|
95
|
+
p
|
96
|
+
|
|
97
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
98
|
+
p Some more markup
|
99
|
+
}
|
100
|
+
|
101
|
+
assert_html '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p><p>Some more markup</p>', source
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_render_with_text_block_with_trailing_whitespace
|
105
|
+
source = %q{
|
106
|
+
' this is
|
107
|
+
a link to
|
108
|
+
a href="link" page
|
109
|
+
}
|
110
|
+
|
111
|
+
assert_html "this is\na link to <a href=\"link\">page</a>", source
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_nested_text
|
115
|
+
source = %q{
|
116
|
+
p
|
117
|
+
|
|
118
|
+
This is line one.
|
119
|
+
This is line two.
|
120
|
+
This is line three.
|
121
|
+
This is line four.
|
122
|
+
p This is a new paragraph.
|
123
|
+
}
|
124
|
+
|
125
|
+
assert_html "<p>This is line one.\n This is line two.\n This is line three.\n This is line four.</p><p>This is a new paragraph.</p>", source
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_nested_text_with_nested_html_one_same_line
|
129
|
+
source = %q{
|
130
|
+
p
|
131
|
+
| This is line one.
|
132
|
+
This is line two.
|
133
|
+
span.bold This is a bold line in the paragraph.
|
134
|
+
| This is more content.
|
135
|
+
}
|
136
|
+
|
137
|
+
assert_html "<p>This is line one.\n This is line two.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>", source
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_nested_text_with_nested_html_one_same_line2
|
141
|
+
source = %q{
|
142
|
+
p
|
143
|
+
|This is line one.
|
144
|
+
This is line two.
|
145
|
+
span.bold This is a bold line in the paragraph.
|
146
|
+
| This is more content.
|
147
|
+
}
|
148
|
+
|
149
|
+
assert_html "<p>This is line one.\n This is line two.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>", source
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_nested_text_with_nested_html
|
153
|
+
source = %q{
|
154
|
+
p
|
155
|
+
|
|
156
|
+
This is line one.
|
157
|
+
This is line two.
|
158
|
+
This is line three.
|
159
|
+
This is line four.
|
160
|
+
span.bold This is a bold line in the paragraph.
|
161
|
+
| This is more content.
|
162
|
+
}
|
163
|
+
|
164
|
+
assert_html "<p>This is line one.\n This is line two.\n This is line three.\n This is line four.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>", source
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_simple_paragraph_with_padding
|
168
|
+
source = %q{
|
169
|
+
p There will be 3 spaces in front of this line.
|
170
|
+
}
|
171
|
+
|
172
|
+
assert_html '<p> There will be 3 spaces in front of this line.</p>', source
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_paragraph_with_nested_text
|
176
|
+
source = %q{
|
177
|
+
p This is line one.
|
178
|
+
This is line two.
|
179
|
+
}
|
180
|
+
|
181
|
+
assert_html "<p>This is line one.\n This is line two.</p>", source
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_paragraph_with_padded_nested_text
|
185
|
+
source = %q{
|
186
|
+
p This is line one.
|
187
|
+
This is line two.
|
188
|
+
}
|
189
|
+
|
190
|
+
assert_html "<p> This is line one.\n This is line two.</p>", source
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_paragraph_with_attributes_and_nested_text
|
194
|
+
source = %q{
|
195
|
+
p#test class="paragraph" This is line one.
|
196
|
+
This is line two.
|
197
|
+
}
|
198
|
+
|
199
|
+
assert_html "<p class=\"paragraph\" id=\"test\">This is line one.\nThis is line two.</p>", source
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_output_code_with_leading_spaces
|
203
|
+
source = %q{
|
204
|
+
p= hello_world
|
205
|
+
p = hello_world
|
206
|
+
p = hello_world
|
207
|
+
}
|
208
|
+
|
209
|
+
assert_html '<p>Hello World from @env</p><p>Hello World from @env</p><p>Hello World from @env</p>', source
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_single_quoted_attributes
|
213
|
+
source = %q{
|
214
|
+
p class='underscored_class_name' = output_number
|
215
|
+
}
|
216
|
+
|
217
|
+
assert_html '<p class="underscored_class_name">1337</p>', source
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_nonstandard_attributes
|
221
|
+
source = %q{
|
222
|
+
p id="dashed-id" class="underscored_class_name" = output_number
|
223
|
+
}
|
224
|
+
|
225
|
+
assert_html '<p class="underscored_class_name" id="dashed-id">1337</p>', source
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_nonstandard_shortcut_attributes
|
229
|
+
source = %q{
|
230
|
+
p#dashed-id.underscored_class_name = output_number
|
231
|
+
}
|
232
|
+
|
233
|
+
assert_html '<p class="underscored_class_name" id="dashed-id">1337</p>', source
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_dashed_attributes
|
237
|
+
source = %q{
|
238
|
+
p data-info="Illudium Q-36" = output_number
|
239
|
+
}
|
240
|
+
|
241
|
+
assert_html '<p data-info="Illudium Q-36">1337</p>', source
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_dashed_attributes_with_shortcuts
|
245
|
+
source = %q{
|
246
|
+
p#marvin.martian data-info="Illudium Q-36" = output_number
|
247
|
+
}
|
248
|
+
|
249
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_parens_around_attributes
|
253
|
+
source = %q{
|
254
|
+
p(id="marvin" class="martian" data-info="Illudium Q-36") = output_number
|
255
|
+
}
|
256
|
+
|
257
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_square_brackets_around_attributes
|
261
|
+
source = %q{
|
262
|
+
p[id="marvin" class="martian" data-info="Illudium Q-36"] = output_number
|
263
|
+
}
|
264
|
+
|
265
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_parens_around_attributes_with_equal_sign_snug_to_right_paren
|
269
|
+
source = %q{
|
270
|
+
p(id="marvin" class="martian" data-info="Illudium Q-36")= output_number
|
271
|
+
}
|
272
|
+
|
273
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_static_empty_attribute
|
277
|
+
source = %q{
|
278
|
+
p(id="marvin" class="" data-info="Illudium Q-36")= output_number
|
279
|
+
}
|
280
|
+
|
281
|
+
assert_html '<p class="" data-info="Illudium Q-36" id="marvin">1337</p>', source
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_dynamic_empty_attribute
|
285
|
+
source = %q{
|
286
|
+
p(id="marvin" class=nil other_empty=("".to_s) data-info="Illudium Q-36")= output_number
|
287
|
+
}
|
288
|
+
|
289
|
+
assert_html '<p data-info="Illudium Q-36" id="marvin">1337</p>', source
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_closed_tag
|
293
|
+
source = %q{
|
294
|
+
closed/
|
295
|
+
}
|
296
|
+
|
297
|
+
assert_html '<closed />', source, :format => :xhtml
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_attributs_with_parens_and_spaces
|
301
|
+
source = %q{label{ for='filter' }= hello_world}
|
302
|
+
assert_html '<label for="filter">Hello World from @env</label>', source
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_attributs_with_parens_and_spaces2
|
306
|
+
source = %q{label{ for='filter' } = hello_world}
|
307
|
+
assert_html '<label for="filter">Hello World from @env</label>', source
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_attributs_with_multiple_spaces
|
311
|
+
source = %q{label for='filter' class="test" = hello_world}
|
312
|
+
assert_html '<label class="test" for="filter">Hello World from @env</label>', source
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_closed_tag_with_attributes
|
316
|
+
source = %q{
|
317
|
+
closed id="test" /
|
318
|
+
}
|
319
|
+
|
320
|
+
assert_html '<closed id="test" />', source, :format => :xhtml
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_closed_tag_with_attributes_and_parens
|
324
|
+
source = %q{
|
325
|
+
closed(id="test")/
|
326
|
+
}
|
327
|
+
|
328
|
+
assert_html '<closed id="test" />', source, :format => :xhtml
|
329
|
+
end
|
330
|
+
|
331
|
+
def test_render_with_html_comments
|
332
|
+
source = %q{
|
333
|
+
p Hello
|
334
|
+
/! This is a comment
|
335
|
+
|
336
|
+
Another comment
|
337
|
+
p World
|
338
|
+
}
|
339
|
+
|
340
|
+
assert_html "<p>Hello</p><!--This is a comment\n\nAnother comment--><p>World</p>", source
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_render_with_html_conditional_and_tag
|
344
|
+
source = %q{
|
345
|
+
/[ if IE ]
|
346
|
+
p Get a better browser.
|
347
|
+
}
|
348
|
+
|
349
|
+
assert_html "<!--[if IE]><p>Get a better browser.</p><![endif]-->", source
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_render_with_html_conditional_and_method_output
|
353
|
+
source = %q{
|
354
|
+
/[ if IE ]
|
355
|
+
= message 'hello'
|
356
|
+
}
|
357
|
+
|
358
|
+
assert_html "<!--[if IE]>hello<![endif]-->", source
|
359
|
+
end
|
360
|
+
|
361
|
+
def test_multiline_attributes_with_method
|
362
|
+
source = %q{
|
363
|
+
p<id="marvin"
|
364
|
+
class="martian"
|
365
|
+
data-info="Illudium Q-36"> = output_number
|
366
|
+
}
|
367
|
+
Slim::Parser::DELIMITERS.each do |k,v|
|
368
|
+
str = source.sub('<',k).sub('>',v)
|
369
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">1337</p>', str
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_multiline_attributes_with_text_on_same_line
|
374
|
+
source = %q{
|
375
|
+
p<id="marvin"
|
376
|
+
class="martian"
|
377
|
+
data-info="Illudium Q-36"> THE space modulator
|
378
|
+
}
|
379
|
+
Slim::Parser::DELIMITERS.each do |k,v|
|
380
|
+
str = source.sub('<',k).sub('>',v)
|
381
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">THE space modulator</p>', str
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
def test_multiline_attributes_with_nested_text
|
386
|
+
source = %q{
|
387
|
+
p<id="marvin"
|
388
|
+
class="martian"
|
389
|
+
data-info="Illudium Q-36">
|
390
|
+
| THE space modulator
|
391
|
+
}
|
392
|
+
Slim::Parser::DELIMITERS.each do |k,v|
|
393
|
+
str = source.sub('<',k).sub('>',v)
|
394
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="marvin">THE space modulator</p>', str
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_multiline_attributes_with_dynamic_attr
|
399
|
+
source = %q{
|
400
|
+
p<id=id_helper
|
401
|
+
class="martian"
|
402
|
+
data-info="Illudium Q-36">
|
403
|
+
| THE space modulator
|
404
|
+
}
|
405
|
+
Slim::Parser::DELIMITERS.each do |k,v|
|
406
|
+
str = source.sub('<',k).sub('>',v)
|
407
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="notice">THE space modulator</p>', str
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
def test_multiline_attributes_with_nested_tag
|
412
|
+
source = %q{
|
413
|
+
p<id=id_helper
|
414
|
+
class="martian"
|
415
|
+
data-info="Illudium Q-36">
|
416
|
+
span.emphasis THE
|
417
|
+
| space modulator
|
418
|
+
}
|
419
|
+
Slim::Parser::DELIMITERS.each do |k,v|
|
420
|
+
str = source.sub('<',k).sub('>',v)
|
421
|
+
assert_html '<p class="martian" data-info="Illudium Q-36" id="notice"><span class="emphasis">THE</span> space modulator</p>', str
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
def test_multiline_attributes_with_nested_text_and_extra_indentation
|
426
|
+
source = %q{
|
427
|
+
li< id="myid"
|
428
|
+
class="myclass"
|
429
|
+
data-info="myinfo">
|
430
|
+
a href="link" My Link
|
431
|
+
}
|
432
|
+
Slim::Parser::DELIMITERS.each do |k,v|
|
433
|
+
str = source.sub('<',k).sub('>',v)
|
434
|
+
assert_html '<li class="myclass" data-info="myinfo" id="myid"><a href="link">My Link</a></li>', str
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
end
|