diff --git a/.gitignore b/.gitignore index 00c0b86e..77685543 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ coverage rdoc pkg +.sass-cache +*.gemspec \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index d612a279..3ce13bf3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "vendor/sinatra-maruku"] path = vendor/sinatra-maruku url = git://github.com/wbzyl/sinatra-maruku.git +[submodule "vendor/rack-test"] + path = vendor/rack-test + url = git://github.com/brynary/rack-test.git diff --git a/bin/mm-build b/bin/mm-build index 80852c3f..606b9211 100755 --- a/bin/mm-build +++ b/bin/mm-build @@ -3,8 +3,8 @@ # Require app require 'rubygems' require 'templater' -require 'open-uri' require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman') +require File.join(File.dirname(__FILE__), '..', 'vendor', 'rack-test', 'lib', 'rack', 'test') module Generators extend Templater::Manifold @@ -19,7 +19,7 @@ module Generators def self.template(name, *args, &block) return if args.first.include?('layout') return if File.basename(args.first)[0,1] == '_' - + if (args[0] === args[1]) newext = case File.extname(args.first) when '.haml', '.mab', '.maruku' @@ -31,11 +31,12 @@ module Generators end args[1] = args[0].gsub(File.extname(args.first), newext).gsub('views/', '') end - + super(name, *args, &block) end def self.file(name, *args, &block) + puts args.inspect args[1] = args[0].gsub('views/', '') if (args[0] === args[1]) super(name, *args, &block) end @@ -53,16 +54,16 @@ module Generators add :build, Builder end -# Monkey-patch to use a dynamic renderer, not just ERb +Middleman.set :root, Dir.pwd + +# Monkey-patch to use a dynamic renderer class Templater::Actions::Template def render - return "" - #request_path = destination.gsub(File.join(Dir.pwd, 'build'), "") - #Rack Handler + request_path = destination.gsub(File.join(Dir.pwd, 'build'), "") + browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman)) + browser.get(request_path) + browser.last_response.body end end -# Start app -#Middleman.run!(:root => Dir.pwd) do - Generators.run_cli(Dir.pwd, 'mm-build', 1, %w(build --force).concat(ARGV)) -#end \ No newline at end of file +Generators.run_cli(Dir.pwd, 'mm-build', 1, %w(build --force).concat(ARGV)) \ No newline at end of file diff --git a/lib/middleman.rb b/lib/middleman.rb index 2f7b4cb1..dce63b66 100644 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -56,8 +56,10 @@ class Middleman < Sinatra::Base haml(template) elsif File.exists? File.join(options.views, "#{template}.maruku") maruku(template) - else + elsif File.exists? File.join(options.views, "#{template}.mab") markaby(template) + else + pass end elsif path.match /.css$/ content_type 'text/css', :charset => 'utf-8' diff --git a/spec/builder_spec.rb b/spec/builder_spec.rb index 7a34845f..a23f7c91 100644 --- a/spec/builder_spec.rb +++ b/spec/builder_spec.rb @@ -20,18 +20,22 @@ describe "Builder" do it "should build markaby files" do File.exists?("#{@root_dir}/build/markaby.html").should be_true + File.read("#{@root_dir}/build/markaby.html").should include("Hi Markaby") end it "should build haml files" do File.exists?("#{@root_dir}/build/index.html").should be_true + File.read("#{@root_dir}/build/index.html").should include("

Welcome

") end it "should build maruku files" do File.exists?("#{@root_dir}/build/maruku.html").should be_true + File.read("#{@root_dir}/build/maruku.html").should include("

Hello Maruku

") end it "should build static files" do File.exists?("#{@root_dir}/build/static.html").should be_true + File.read("#{@root_dir}/build/static.html").should include("Static, no code!") end it "should build subdirectory files" do @@ -40,6 +44,7 @@ describe "Builder" do it "should build sass files" do File.exists?("#{@root_dir}/build/stylesheets/site.css").should be_true + File.read("#{@root_dir}/build/stylesheets/site.css").should include("html, body, div, span, applet, object, iframe") end it "should build static css files" do diff --git a/spec/fixtures/sample/views/markaby.mab b/spec/fixtures/sample/views/markaby.mab index e69de29b..0e197f74 100644 --- a/spec/fixtures/sample/views/markaby.mab +++ b/spec/fixtures/sample/views/markaby.mab @@ -0,0 +1,5 @@ +mab.html do + head do + title "Hi Markaby" + end +end \ No newline at end of file diff --git a/spec/middleman_spec.rb b/spec/middleman_spec.rb deleted file mode 100644 index a22a6519..00000000 --- a/spec/middleman_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/spec_helper') - -describe "Middleman" do - it "fails" do - fail "hey buddy, you should probably rename this file and start specing for real" - end -end diff --git a/vendor/rack-test b/vendor/rack-test new file mode 160000 index 00000000..6d8c25af --- /dev/null +++ b/vendor/rack-test @@ -0,0 +1 @@ +Subproject commit 6d8c25af8592faf2efb3f5ab73b0219eadf30ea4