1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/bin/mm-build

70 lines
2 KiB
Text
Raw Normal View History

2009-07-27 19:25:32 -04:00
#!/usr/bin/env ruby
# Require app
require 'rubygems'
require 'templater'
2009-07-29 13:39:00 -04:00
MIDDLEMAN_BUILDER = true
2009-07-27 19:25:32 -04:00
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
2009-07-28 14:06:45 -04:00
require File.join(File.dirname(__FILE__), '..', 'vendor', 'rack-test', 'lib', 'rack', 'test')
2009-07-27 19:25:32 -04:00
module Generators
extend Templater::Manifold
desc "Build a staticmatic site"
class Builder < Templater::Generator
# Define source and desintation
def self.source_root; Dir.pwd; end
def destination_root; File.join(Dir.pwd, 'build'); end
# Override template to ask staticmatic for the correct extension to output
def self.template(name, *args, &block)
return if args.first.include?('layout')
2009-08-11 19:26:08 -04:00
args.first.split('/').each do |part|
return if part[0,1] == '_'
end
2009-07-28 14:06:45 -04:00
2009-07-27 19:25:32 -04:00
if (args[0] === args[1])
newext = case File.extname(args.first)
2009-07-28 16:44:56 -04:00
when '.haml', '.erb', '.mab', '.maruku'
2009-07-27 19:25:32 -04:00
'.html'
when '.sass'
'.css'
else
File.extname(args.first)
end
args[1] = args[0].gsub(File.extname(args.first), newext).gsub('views/', '')
end
2009-07-28 14:06:45 -04:00
2009-07-27 19:25:32 -04:00
super(name, *args, &block)
end
def self.file(name, *args, &block)
args[1] = args[0].gsub('views/', '') if (args[0] === args[1])
super(name, *args, &block)
end
public_files_glob = File.join(source_root, "public", '**/*')
Dir[public_files_glob].each do |action|
next if File.directory?(action)
action = action.sub("#{source_root}/", '')
file(action.downcase.gsub(/[^a-z0-9]+/, '_').to_sym, action, action.gsub('public/', ''))
end
2009-07-28 16:44:56 -04:00
glob! "views", %w(haml sass erb builder mab maruku)
2009-07-27 19:25:32 -04:00
end
add :build, Builder
end
2009-07-28 14:06:45 -04:00
# Monkey-patch to use a dynamic renderer
2009-07-27 19:25:32 -04:00
class Templater::Actions::Template
def render
2009-07-28 14:06:45 -04:00
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
2009-07-27 19:25:32 -04:00
end
end
2009-07-28 14:06:45 -04:00
Generators.run_cli(Dir.pwd, 'mm-build', 1, %w(build --force).concat(ARGV))