-
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.
[Issue #139] Add variable interpolation to *.js files.
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
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,47 @@ | ||
|
||
require 'awestruct/handler_chain' | ||
require 'awestruct/handlers/base_handler' | ||
require 'awestruct/handlers/file_handler' | ||
require 'awestruct/handlers/front_matter_handler' | ||
require 'awestruct/handlers/interpolation_handler' | ||
|
||
module Awestruct | ||
module Handlers | ||
class JavascriptHandler < BaseHandler | ||
|
||
|
||
CHAIN = Awestruct::HandlerChain.new( /\.js$/, | ||
Awestruct::Handlers::FileHandler, | ||
Awestruct::Handlers::FrontMatterHandler, | ||
Awestruct::Handlers::InterpolationHandler, | ||
Awestruct::Handlers::JavascriptHandler | ||
) | ||
|
||
def initialize(site, delegate) | ||
super( site, delegate ) | ||
end | ||
|
||
def simple_name | ||
File.basename( relative_source_path, '.js' ) | ||
end | ||
|
||
def output_filename | ||
File.basename( relative_source_path ) | ||
end | ||
|
||
def output_extension | ||
'.js' | ||
end | ||
|
||
def content_syntax | ||
:javascript | ||
end | ||
|
||
def rendered_content(context, with_layouts=false) | ||
delegate.rendered_content( context, with_layouts ) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'awestruct/handlers/file_handler' | ||
require 'awestruct/handlers/javascript_handler' | ||
|
||
require 'hashery/open_cascade' | ||
|
||
describe Awestruct::Handlers::JavascriptHandler do | ||
|
||
before :all do | ||
@site = OpenCascade.new :encoding=>false, :dir=>Pathname.new( File.dirname(__FILE__) + '/test-data/handlers' ), :foo => "bacon" | ||
end | ||
|
||
def handler_file(path) | ||
File.dirname( __FILE__ ) + "/test-data/handlers/#{path}" | ||
end | ||
|
||
def create_context | ||
OpenCascade.new :site=>@site | ||
end | ||
|
||
it "should render a Javascript file" do | ||
file_handler = Awestruct::Handlers::FileHandler.new( @site, handler_file( "javascript-page.js" ) ) | ||
javascript_handler = Awestruct::Handlers::JavascriptHandler.new( @site, file_handler ) | ||
|
||
rendered = javascript_handler.rendered_content( create_context ) | ||
rendered.should_not be_nil | ||
rendered.should =~ %r(var crunchy = "bacon") | ||
|
||
end | ||
|
||
it "should interpolate Javascript files" do | ||
Awestruct::Handlers::JavascriptHandler::CHAIN.handler_classes.include?( Awestruct::Handlers::InterpolationHandler ).should be_true | ||
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 @@ | ||
var crunchy = "bacon" |