-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53e4ea1
commit 16d8d58
Showing
5 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
require 'awestruct/handlers/base_handler' | ||
|
||
module Awestruct | ||
module Handlers | ||
class ErbHandler < BaseHandler | ||
|
||
def initialize(site, delegate) | ||
super( site, delegate ) | ||
end | ||
|
||
def simple_name | ||
File.basename( File.basename( relative_source_path, '.erb' ), output_extension ) | ||
end | ||
|
||
def output_filename | ||
File.basename( relative_source_path, '.erb' ) | ||
end | ||
|
||
def output_extension | ||
File.extname( output_filename ) | ||
end | ||
|
||
def content_syntax | ||
:erb | ||
end | ||
|
||
def rendered_content(context, with_layouts=true) | ||
erb = ERB.new( delegate.rendered_content( context, with_layouts) ) | ||
erb.result( context.send( :binding ) ) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
require 'awestruct/handlers/file_handler' | ||
require 'awestruct/handlers/erb_handler' | ||
|
||
require 'hashery/open_cascade' | ||
|
||
describe Awestruct::Handlers::ErbHandler do | ||
|
||
before :all do | ||
@site = OpenCascade.new :encoding=>false, :dir=>Pathname.new( File.dirname(__FILE__) + '/test-data/handlers' ) | ||
end | ||
|
||
def handler_file(path) | ||
"#{@site.dir}/#{path}" | ||
end | ||
|
||
def create_context | ||
OpenCascade.new :site=>@site | ||
end | ||
|
||
it "should provide a simple name for the page" do | ||
file_handler = Awestruct::Handlers::FileHandler.new( @site, handler_file( "erb-page.html.erb" ) ) | ||
erb_handler = Awestruct::Handlers::ErbHandler.new( @site, file_handler ) | ||
|
||
erb_handler.simple_name.should == 'erb-page' | ||
end | ||
|
||
it "should successfully render an ERB page" do | ||
file_handler = Awestruct::Handlers::FileHandler.new( @site, handler_file( "erb-page.html.erb" ) ) | ||
erb_handler = Awestruct::Handlers::ErbHandler.new( @site, file_handler ) | ||
|
||
rendered = erb_handler.rendered_content( create_context ) | ||
rendered.should_not be_nil | ||
rendered.should =~ %r(<h1>This is an ERB page</h1>) | ||
rendered.should =~ %r(<h2>The fruit of the day is: apples</h2>) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>This is an ERB page</h1> | ||
<h2>The fruit of the day is: <%= "apples" %></h2> |