summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-01-06 10:07:38 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2012-01-06 10:07:38 +0100
commit8dd007b3978d855ee3984b3c3f59b3eb4281b8fa (patch)
tree6c7137fb9db8aa5b64935c7865139bc5554cf428
parentdf5e1a8e31104b6cb92689c3d82b0c47b77230f1 (diff)
downloadzorglub-8dd007b3978d855ee3984b3c3f59b3eb4281b8fa.zip
zorglub-8dd007b3978d855ee3984b3c3f59b3eb4281b8fa.tar.gz
fix haml engine, add spec
-rw-r--r--lib/zorglub/engines/haml.rb4
-rw-r--r--spec/data/view/node0/engines.haml1
-rw-r--r--spec/node_spec.rb6
-rw-r--r--spec/spec_helper.rb8
4 files changed, 17 insertions, 2 deletions
diff --git a/lib/zorglub/engines/haml.rb b/lib/zorglub/engines/haml.rb
index a0353f7..458f29a 100644
--- a/lib/zorglub/engines/haml.rb
+++ b/lib/zorglub/engines/haml.rb
@@ -9,9 +9,9 @@ module Zorglub
def self.proc path,obj
if Zorglub::Config.engines_cache_enabled
key = path.sub Zorglub::Config.root,''
- haml = obj.app.engines_cache[key] ||= ::Haml::Engine.new( File.open(path,'r'){|f| f.read }, Zorglub::Config.haml_options )
+ haml = obj.app.engines_cache[key] ||= ::Haml::Engine.new( ::File.open(path,'r'){|f| f.read }, Zorglub::Config.haml_options )
else
- haml = ::Haml::Engine.new( File.open(path,'r'){|f| f.read }, Zorglub::Config.haml_options )
+ haml = ::Haml::Engine.new( ::File.open(path,'r'){|f| f.read }, Zorglub::Config.haml_options )
end
html = haml.render(obj)
return html, 'text/html'
diff --git a/spec/data/view/node0/engines.haml b/spec/data/view/node0/engines.haml
new file mode 100644
index 0000000..b9ea984
--- /dev/null
+++ b/spec/data/view/node0/engines.haml
@@ -0,0 +1 @@
+%h1="Hello world"
diff --git a/spec/node_spec.rb b/spec/node_spec.rb
index 701c700..3e1c957 100644
--- a/spec/node_spec.rb
+++ b/spec/node_spec.rb
@@ -199,6 +199,12 @@ describe Zorglub do
r = Node0.my_call '/plain_file'
r.body[0].should == "plain file\n"
end
+ #
+ it "haml engine should work" do
+ r = Node0.my_call '/engines/haml'
+ r.body[0].should == "<h1>Hello world</h1>\n"
+ end
+ #
end
#
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2e402a5..a531ce9 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -12,6 +12,7 @@ require 'yaml'
#
require 'zorglub'
require 'zorglub/engines/file'
+require 'zorglub/engines/haml'
#
HASH_PROC = Proc.new { |path,obj| {:path=>path,:layout=>obj.layout,:view=>obj.view,:args=>obj.args,:map=>obj.map}.to_yaml }
STATIC_PROC = Proc.new { |path,obj| ["VAL #{obj.value}",'text/static'] }
@@ -79,6 +80,13 @@ class Node0 < Zorglub::Node
engine :file
ext 'txt'
end
+ def engines name
+ no_layout
+ case name
+ when 'haml'
+ engine :haml
+ end
+ end
end
#
class Node1 < Zorglub::Node