Skip to content

Commit

Permalink
Mix org-mode support back in.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmcwhirter committed May 2, 2012
1 parent d57c0f4 commit 53e4ea1
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/awestruct/handler_chains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'awestruct/handlers/front_matter_handler'
require 'awestruct/handlers/interpolation_handler'
require 'awestruct/handlers/markdown_handler'
require 'awestruct/handlers/orgmode_handler'
require 'awestruct/handlers/textile_handler'
require 'awestruct/handlers/haml_handler'
require 'awestruct/handlers/sass_handler'
Expand Down Expand Up @@ -30,6 +31,13 @@ class HandlerChains
Awestruct::Handlers::TextileHandler,
Awestruct::Handlers::LayoutHandler
),
HandlerChain.new( /\.org$/,
Awestruct::Handlers::FileHandler,
Awestruct::Handlers::FrontMatterHandler,
Awestruct::Handlers::InterpolationHandler,
Awestruct::Handlers::OrgmodeHandler,
Awestruct::Handlers::LayoutHandler
),
HandlerChain.new( /\.haml$/,
Awestruct::Handlers::FileHandler,
Awestruct::Handlers::FrontMatterHandler,
Expand Down
35 changes: 35 additions & 0 deletions lib/awestruct/handlers/orgmode_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

require 'awestruct/handlers/base_handler'
require 'org-ruby'

module Awestruct
module Handlers
class OrgmodeHandler < BaseHandler

def initialize(site, delegate)
super( site, delegate )
end

def simple_name
File.basename( relative_source_path, '.org' )
end

def output_filename
File.basename( relative_source_path, '.org' ) + '.html'
end

def output_extension
'.html'
end

def content_syntax
:orgmode
end

def rendered_content(context, with_layouts=true)
Orgmode::Parser.new(super( context, with_layouts) ).to_html
end

end
end
end
38 changes: 38 additions & 0 deletions spec/orgmode_handler_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

require 'awestruct/handlers/file_handler'
require 'awestruct/handlers/orgmode_handler'

require 'hashery/open_cascade'

describe Awestruct::Handlers::OrgmodeHandler 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( "orgmode-page.org" ) )
orgmode_handler = Awestruct::Handlers::OrgmodeHandler.new( @site, file_handler )

orgmode_handler.simple_name.should == 'orgmode-page'
end

it "should successfully render an org-mode page" do
file_handler = Awestruct::Handlers::FileHandler.new( @site, handler_file( "orgmode-page.org" ) )
orgmode_handler = Awestruct::Handlers::OrgmodeHandler.new( @site, file_handler )

rendered = orgmode_handler.rendered_content( create_context )
rendered.should_not be_nil
rendered.should =~ %r(<h1 class="title">Fruit</h1>)
rendered.should =~ %r(<p>Apples are red</p>)
end

end
6 changes: 6 additions & 0 deletions spec/test-data/handlers/orgmode-page.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* Fruit
** Apples
Apples are red
** Oranges
Oranges are orange
*Vegetables

0 comments on commit 53e4ea1

Please sign in to comment.