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 begin
require 'rails' require 'rails'
require 'hamlit/railtie'
rescue LoadError rescue LoadError
end 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> <h1>Me!</h1>
<div id='foo'> <div id='foo'>
<p id='bar'>All</p> <p id='bar'>All</p>
<br /> <br>
<p class='baz'>This</p> <p class='baz'>This</p>
Should render Should render
</div> </div>

View File

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

View File

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

View File

@ -130,11 +130,11 @@ Bar</q>bar
<p><q></q></p> <p><q></q></p>
</p> </p>
<p> <p>
<p><q /></p> <p><q></p>
</p> </p>
<p> <p>
<p><q a='2'></q></p> <p><q a='2'></q></p>
</p> </p>
<p> <p>
<p><q a='2' /></p> <p><q a='2'></p>
</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> <html>
<head> <head>
<title>Stop. haml time</title> <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'> <html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>
<head> <head>
<title>Hampton Catlin Is Totally Awesome</title> <title>Hampton Catlin Is Totally Awesome</title>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' /> <meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
</head> </head>
<body> <body>
<!-- You're In my house now! --> <!-- You're In my house now! -->
<div class='header'> <div class='header'>
Yes, ladies and gentileman. He is just that egotistical. Yes, ladies and gentileman. He is just that egotistical.
Fantastic! This should be multi-line output Fantastic! This should be multi-line output
The question is if this would translate! Ahah! The question is if this would translate! Ahah!
20 20
</div> </div>
<div id='body'> Quotes should be loved! Just like people!</div> <div id='body'> Quotes should be loved! Just like people!</div>
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20
21 21
22 22
23 23
24 24
25 25
26 26
27 27
28 28
29 29
30 30
31 31
32 32
33 33
34 34
35 35
36 36
37 37
38 38
39 39
40 40
41 41
42 42
43 43
44 44
45 45
46 46
47 47
48 48
49 49
50 50
51 51
52 52
53 53
54 54
55 55
56 56
57 57
58 58
59 59
60 60
61 61
62 62
63 63
64 64
65 65
66 66
67 67
68 68
69 69
70 70
71 71
72 72
73 73
74 74
75 75
76 76
77 77
78 78
79 79
80 80
81 81
82 82
83 83
84 84
85 85
86 86
87 87
88 88
89 89
90 90
91 91
92 92
93 93
94 94
95 95
96 96
97 97
98 98
99 99
100 100
101 101
102 102
103 103
104 104
105 105
106 106
107 107
108 108
109 109
110 110
111 111
112 112
113 113
114 114
115 115
116 116
117 117
118 118
119 119
Wow.| Wow.|
<p code='3'> <p code='3'>
Holy cow multiline tags! A pipe (|) even! Holy cow multiline tags! A pipe (|) even!
PipesIgnored|PipesIgnored|PipesIgnored| PipesIgnored|PipesIgnored|PipesIgnored|
1|2|3 1|2|3
</p> </p>
<div class='silent' foo='17'> <div class='silent' foo='17'>
this shouldn't evaluate but now it should! this shouldn't evaluate but now it should!
</div> </div>
<ul class='really cool'> <ul class='really cool'>
<li>a</li> <li>a</li>
<li>b</li> <li>b</li>
<li>c</li> <li>c</li>
<li>d</li> <li>d</li>
<li>e</li> <li>e</li>
<li>f</li> <li>f</li>
</ul> </ul>
<div class='of_divs_with_underscore' id='combo'>with this text</div> <div class='of_divs_with_underscore' id='combo'>with this text</div>
foo foo<div class='footer'>
<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.
<strong class='shout'> So, I'm just making it *really* long. God, I hope this works</strong>
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. </div>
So, I'm just making it *really* long. God, I hope this works </body>
</strong>
</div>
</body>
</html> </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> <html>
<head></head> <head></head>
<body></body> <body></body>

View File

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