2009-07-27 19:25:32 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'templater'
|
2009-09-24 19:35:03 -04:00
|
|
|
require 'rack-test'
|
2009-09-28 22:43:08 -04:00
|
|
|
|
|
|
|
# Require app
|
|
|
|
require 'middleman/builder'
|
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
|
|
|
|
|
2009-09-17 12:40:29 -04:00
|
|
|
# Override template to ask middleman for the correct extension to output
|
2009-07-27 19:25:32 -04:00
|
|
|
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])
|
2009-09-18 12:59:07 -04:00
|
|
|
file_name_parts = File.basename(args.first).split('.')
|
|
|
|
|
|
|
|
if file_name_parts.length > 2
|
|
|
|
# static ext embedded in filename
|
|
|
|
newext = ""
|
2009-07-27 19:25:32 -04:00
|
|
|
else
|
2009-09-18 12:59:07 -04:00
|
|
|
# use defaults
|
|
|
|
newext = case file_name_parts.last
|
|
|
|
when 'haml', 'erb', 'mab', 'maruku'
|
|
|
|
'.html'
|
|
|
|
when 'sass'
|
|
|
|
'.css'
|
|
|
|
end
|
2009-07-27 19:25:32 -04:00
|
|
|
end
|
2009-09-18 12:59:07 -04:00
|
|
|
|
|
|
|
args[1] = args[0].gsub(".#{file_name_parts.last}", newext).gsub('views/', '')
|
2009-07-27 19:25:32 -04:00
|
|
|
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}/", '')
|
2009-09-17 12:40:29 -04:00
|
|
|
template_sym = action.downcase.gsub(/[^a-z0-9]+/, '_').to_sym
|
|
|
|
|
|
|
|
if File.extname(action) == '.js' && !action.include?('min')
|
|
|
|
template(template_sym, action, action.gsub('public/', ''))
|
|
|
|
else
|
|
|
|
file(template_sym, action, action.gsub('public/', ''))
|
|
|
|
end
|
2009-07-27 19:25:32 -04:00
|
|
|
end
|
|
|
|
|
2009-08-12 13:00:06 -04:00
|
|
|
glob! "views", (Middleman.supported_formats << "sass")
|
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-09-28 22:43:08 -04:00
|
|
|
::Middleman::Builder.render(source, destination)
|
2009-09-17 12:40:29 -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))
|