Permalink
Browse files

Add TemplateVars class

Start extracting out the use of templates into its own class to cleanup
the response code.
  • Loading branch information...
1 parent 66da63d commit 7f0ca65a4e916a2bf235697459face959a99f201 @copiousfreetime committed Jul 7, 2013
Showing with 31 additions and 0 deletions.
  1. +1 −0 lib/heel.rb
  2. +8 −0 lib/heel/template_vars.rb
  3. +22 −0 spec/template_vars_spec.rb
View
@@ -14,3 +14,4 @@ module Heel
require 'heel/rackapp'
require 'heel/request'
require 'heel/server'
+require 'heel/template_vars'
@@ -0,0 +1,8 @@
+require 'ostruct'
+module Heel
+ class TemplateVars < OpenStruct
+ def binding_for_template()
+ return binding()
+ end
+ end
+end
View
@@ -0,0 +1,22 @@
+require 'spec_helper'
+require 'pathname'
+
+describe Heel::TemplateVars do
+ before do
+ @template = ERB.new( "<%= foo %> && <%= bar %>" )
+ end
+
+ it "exposes all its data members in a binding" do
+ t = Heel::TemplateVars.new( :foo => 'foo', :bar => 'bar' )
+ s = @template.result( t.binding_for_template )
+ s.must_equal( "foo && bar")
+ end
+
+ it "data members may be added after instantiation" do
+ t = Heel::TemplateVars.new
+ t.foo = 'foo'
+ t.bar = 'bar'
+ s = @template.result( t.binding_for_template )
+ s.must_equal( "foo && bar")
+ end
+end

0 comments on commit 7f0ca65

Please sign in to comment.