From 47e159cd44219f1d792e8aa170dcd0c0a1bdc2f0 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Wed, 18 Nov 2015 10:54:41 -0600 Subject: [PATCH] Support ActionView --- lib/hamlit.rb | 1 + lib/hamlit/rails_template.rb | 17 + lib/hamlit/railtie.rb | 10 + test/haml/results/eval_suppressed.xhtml | 2 +- test/haml/results/helpers.xhtml | 2 +- test/haml/results/just_stuff.xhtml | 27 +- test/haml/results/nuke_outer_whitespace.xhtml | 4 +- test/haml/results/original_engine.xhtml | 2 +- test/haml/results/standard.xhtml | 317 +++++++++--------- test/haml/results/very_basic.xhtml | 2 +- test/haml/template_test.rb | 14 +- 11 files changed, 210 insertions(+), 188 deletions(-) create mode 100644 lib/hamlit/rails_template.rb create mode 100644 lib/hamlit/railtie.rb diff --git a/lib/hamlit.rb b/lib/hamlit.rb index cd43ecdd..729fa195 100644 --- a/lib/hamlit.rb +++ b/lib/hamlit.rb @@ -5,5 +5,6 @@ require 'hamlit/template' begin require 'rails' + require 'hamlit/railtie' rescue LoadError end diff --git a/lib/hamlit/rails_template.rb b/lib/hamlit/rails_template.rb new file mode 100644 index 00000000..8053342a --- /dev/null +++ b/lib/hamlit/rails_template.rb @@ -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 diff --git a/lib/hamlit/railtie.rb b/lib/hamlit/railtie.rb new file mode 100644 index 00000000..c9ae8d0b --- /dev/null +++ b/lib/hamlit/railtie.rb @@ -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 diff --git a/test/haml/results/eval_suppressed.xhtml b/test/haml/results/eval_suppressed.xhtml index 70887a75..fb7bd330 100644 --- a/test/haml/results/eval_suppressed.xhtml +++ b/test/haml/results/eval_suppressed.xhtml @@ -3,7 +3,7 @@

Me!

All

-
+

This

Should render
diff --git a/test/haml/results/helpers.xhtml b/test/haml/results/helpers.xhtml index 89c2b442..1d6d8fa3 100644 --- a/test/haml/results/helpers.xhtml +++ b/test/haml/results/helpers.xhtml @@ -68,5 +68,5 @@ more_data -
+
diff --git a/test/haml/results/just_stuff.xhtml b/test/haml/results/just_stuff.xhtml index d31dd78b..3ce2adf1 100644 --- a/test/haml/results/just_stuff.xhtml +++ b/test/haml/results/just_stuff.xhtml @@ -1,11 +1,8 @@ - - - - - - - - + + + + + Boo! Embedded? false! Embedded? true! @@ -46,11 +43,11 @@ Or script! Woah a period. testtest -
- - -
- +
+ + +
+
Nested content @@ -62,10 +59,10 @@ Nested content

Whee

Woah inner quotes

-

+

hello

- +
diff --git a/test/haml/results/nuke_outer_whitespace.xhtml b/test/haml/results/nuke_outer_whitespace.xhtml index c33af098..913dc10d 100644 --- a/test/haml/results/nuke_outer_whitespace.xhtml +++ b/test/haml/results/nuke_outer_whitespace.xhtml @@ -130,11 +130,11 @@ Barbar

-

+

-

+

diff --git a/test/haml/results/original_engine.xhtml b/test/haml/results/original_engine.xhtml index d62f0897..e2774753 100644 --- a/test/haml/results/original_engine.xhtml +++ b/test/haml/results/original_engine.xhtml @@ -1,4 +1,4 @@ - + Stop. haml time diff --git a/test/haml/results/standard.xhtml b/test/haml/results/standard.xhtml index 6897fc30..7d7c6e4f 100644 --- a/test/haml/results/standard.xhtml +++ b/test/haml/results/standard.xhtml @@ -1,162 +1,159 @@ - + - - Hampton Catlin Is Totally Awesome - - - - -
- 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 -
-
Quotes should be loved! Just like people!
- 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.| -

- Holy cow multiline tags! A pipe (|) even! - PipesIgnored|PipesIgnored|PipesIgnored| - 1|2|3 -

-
- this shouldn't evaluate but now it should! -
- -
with this text
- foo - - + +Hampton Catlin Is Totally Awesome + + + + +
+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 +
+
Quotes should be loved! Just like people!
+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.| +

+Holy cow multiline tags! A pipe (|) even! +PipesIgnored|PipesIgnored|PipesIgnored| +1|2|3 +

+
+this shouldn't evaluate but now it should! +
+ +
with this text
+foo + diff --git a/test/haml/results/very_basic.xhtml b/test/haml/results/very_basic.xhtml index 20e7c9c1..25f83eb7 100644 --- a/test/haml/results/very_basic.xhtml +++ b/test/haml/results/very_basic.xhtml @@ -1,4 +1,4 @@ - + diff --git a/test/haml/template_test.rb b/test/haml/template_test.rb index db20f316..e73080d5 100644 --- a/test/haml/template_test.rb +++ b/test/haml/template_test.rb @@ -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