Support ActionView

This commit is contained in:
Takashi Kokubun 2015-11-18 10:54:41 -06:00
parent 50091f4e72
commit 47e159cd44
11 changed files with 210 additions and 188 deletions

View File

@ -5,5 +5,6 @@ require 'hamlit/template'
begin
require 'rails'
require 'hamlit/railtie'
rescue LoadError
end

View File

@ -0,0 +1,17 @@
require 'temple'
require 'hamlit/engine'
require 'hamlit/rails_helpers'
module Hamlit
RailsTemplate = Temple::Templates::Rails.create(
Hamlit::Engine,
generator: Temple::Generators::RailsOutputBuffer,
register_as: :haml,
escape_html: true,
streaming: true,
)
end
# Haml extends Haml::Helpers in ActionView each time.
# It costs much, so Hamlit includes a compatible module at first.
ActionView::Base.send :include, Hamlit::RailsHelpers

10
lib/hamlit/railtie.rb Normal file
View File

@ -0,0 +1,10 @@
require 'rails'
require 'temple'
module Hamlit
class Railtie < ::Rails::Railtie
initializer :hamlit do |app|
require 'hamlit/rails_template'
end
end
end

View File

@ -3,7 +3,7 @@
<h1>Me!</h1>
<div id='foo'>
<p id='bar'>All</p>
<br />
<br>
<p class='baz'>This</p>
Should render
</div>

View File

@ -68,5 +68,5 @@ more_data
</td>
</tr>
</table>
<hr />
<hr>
<div></div>

View File

@ -1,11 +1,8 @@
<?xml version='1.0' encoding='utf-8' ?>
<?xml version='1.0' encoding='iso-8859-1' ?>
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<!DOCTYPE html>
<!DOCTYPE html>
<!DOCTYPE html>
<!DOCTYPE html>
<!DOCTYPE html>
<strong apos="Foo's bar!">Boo!</strong>
Embedded? false!
Embedded? true!
@ -46,11 +43,11 @@ Or script!
Woah a period.
<![endif]-->
testtest
<br />
<meta foo='bar' />
<img />
<hr />
<link />
<br>
<meta foo='bar'>
<img>
<hr>
<link>
<script>Inline content</script>
<br>
Nested content
@ -62,10 +59,10 @@ Nested content
<p class='article' id='foo_bar_baz_article_1'>Whee</p>
Woah inner quotes
<p class='dynamic_quote' dyn='3' quotes="single '"></p>
<p class='dynamic_self_closing' dyn='3' />
<p class='dynamic_self_closing' dyn='3'>
<body>
hello
<div>
<img />
<img>
</div>
</body>

View File

@ -130,11 +130,11 @@ Bar</q>bar
<p><q></q></p>
</p>
<p>
<p><q /></p>
<p><q></p>
</p>
<p>
<p><q a='2'></q></p>
</p>
<p>
<p><q a='2' /></p>
<p><q a='2'></p>
</p>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html>
<html>
<head>
<title>Stop. haml time</title>

View File

@ -1,162 +1,159 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html>
<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Hampton Catlin Is Totally Awesome</title>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
</head>
<body>
<!-- You're In my house now! -->
<div class='header'>
Yes, ladies and gentileman. He is just that egotistical.
Fantastic! This should be multi-line output
The question is if this would translate! Ahah!
20
</div>
<div id='body'> Quotes should be loved! Just like people!</div>
0
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Wow.|
<p code='3'>
Holy cow multiline tags! A pipe (|) even!
PipesIgnored|PipesIgnored|PipesIgnored|
1|2|3
</p>
<div class='silent' foo='17'>
this shouldn't evaluate but now it should!
</div>
<ul class='really cool'>
<li>a</li>
<li>b</li>
<li>c</li>
<li>d</li>
<li>e</li>
<li>f</li>
</ul>
<div class='of_divs_with_underscore' id='combo'>with this text</div>
foo
<div class='footer'>
<strong class='shout'>
This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.
So, I'm just making it *really* long. God, I hope this works
</strong>
</div>
</body>
<head>
<title>Hampton Catlin Is Totally Awesome</title>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
</head>
<body>
<!-- You're In my house now! -->
<div class='header'>
Yes, ladies and gentileman. He is just that egotistical.
Fantastic! This should be multi-line output
The question is if this would translate! Ahah!
20
</div>
<div id='body'> Quotes should be loved! Just like people!</div>
0
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Wow.|
<p code='3'>
Holy cow multiline tags! A pipe (|) even!
PipesIgnored|PipesIgnored|PipesIgnored|
1|2|3
</p>
<div class='silent' foo='17'>
this shouldn't evaluate but now it should!
</div>
<ul class='really cool'>
<li>a</li>
<li>b</li>
<li>c</li>
<li>d</li>
<li>e</li>
<li>f</li>
</ul>
<div class='of_divs_with_underscore' id='combo'>with this text</div>
foo<div class='footer'>
<strong class='shout'>This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid.
So, I'm just making it *really* long. God, I hope this works</strong>
</div>
</body>
</html>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html>
<html>
<head></head>
<body></body>

View File

@ -2,6 +2,7 @@ require 'test_helper'
require 'haml/mocks/article'
require 'action_pack/version'
require 'hamlit/rails_template'
module Haml::Filters::Test
include Haml::Filters::Base
@ -11,9 +12,9 @@ module Haml::Filters::Test
end
end
module Haml::Helpers
module Hamlit::RailsHelpers
def test_partial(name, locals = {})
Haml::Engine.new(File.read(File.join(TemplateTest::TEMPLATE_PATH, "_#{name}.haml"))).render(self, locals)
Hamlit::Template.new { File.read(File.join(TemplateTest::TEMPLATE_PATH, "_#{name}.haml")) }.render(self, locals)
end
end
@ -41,14 +42,14 @@ end
class TemplateTest < Haml::TestCase
TEMPLATE_PATH = File.join(File.dirname(__FILE__), "templates")
TEMPLATES = [
#'very_basic',
'very_basic',
#'standard',
#'helpers',
#'whitespace_handling',
#'original_engine',
'original_engine',
'list',
#'helpful',
#'silent_script',
'silent_script',
'tag_parsing',
#'just_stuff',
#'partials',
@ -56,7 +57,7 @@ class TemplateTest < Haml::TestCase
#'nuke_inner_whitespace',
#'render_layout',
#'partial_layout',
#'partial_layout_erb',
'partial_layout_erb',
]
def setup
@ -120,7 +121,6 @@ class TemplateTest < Haml::TestCase
TEMPLATES.each do |template|
define_method "test_template_should_render_correctly [template: #{template}]" do
skip
assert_renders_correctly template
end
end