Created
August 1, 2012 08:04
-
-
Save pauldijou/3224800 to your computer and use it in GitHub Desktop.
javascript_handler.rb & javascript_handler_spec.rb
This file contains hidden or 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
| require 'awestruct/handler_chain' | |
| require 'awestruct/handlers/file_handler' | |
| require 'awestruct/handlers/markdown_handler' | |
| require 'awestruct/handlers/orgmode_handler' | |
| require 'awestruct/handlers/asciidoc_handler' | |
| require 'awestruct/handlers/restructuredtext_handler' | |
| require 'awestruct/handlers/textile_handler' | |
| require 'awestruct/handlers/erb_handler' | |
| require 'awestruct/handlers/haml_handler' | |
| require 'awestruct/handlers/sass_handler' | |
| require 'awestruct/handlers/scss_handler' | |
| require 'awestruct/handlers/javascript_handler' | |
| require 'awestruct/handlers/coffeescript_handler' | |
| module Awestruct | |
| class HandlerChains | |
| DEFAULTS = [ | |
| Awestruct::Handlers::MarkdownHandler::CHAIN, | |
| Awestruct::Handlers::TextileHandler::CHAIN, | |
| Awestruct::Handlers::ErbHandler::CHAIN, | |
| Awestruct::Handlers::OrgmodeHandler::CHAIN, | |
| Awestruct::Handlers::AsciidocHandler::CHAIN, | |
| Awestruct::Handlers::RestructuredtextHandler::CHAIN, | |
| Awestruct::Handlers::HamlHandler::CHAIN, | |
| Awestruct::Handlers::SassHandler::CHAIN, | |
| Awestruct::Handlers::ScssHandler::CHAIN, | |
| Awestruct::Handlers::JavascriptHandler::CHAIN, | |
| Awestruct::Handlers::CoffeescriptHandler::CHAIN, | |
| HandlerChain.new( /.*/, Awestruct::Handlers::FileHandler ) | |
| ] | |
| def initialize(include_defaults=true) | |
| @chains = [] | |
| self << :defaults if include_defaults | |
| end | |
| def[](path) | |
| @chains.detect{|e| e.matches?( path.to_s ) } | |
| end | |
| def <<(chain) | |
| @chains += DEFAULTS and return if ( chain == :defaults ) | |
| @chains << chain | |
| end | |
| end | |
| end |
This file contains hidden or 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
| 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=true) | |
| delegate.rendered_content( context, with_layouts ) | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or 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
| 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' ) | |
| end | |
| def handler_file(path) | |
| "#{@site.dir}/#{path}" | |
| end | |
| def create_context | |
| OpenCascade.new :site=>@site | |
| end | |
| it "should interpolate Javascript files" do | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment