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

63 lines
1.8 KiB
Text
Raw Normal View History

2009-07-27 19:25:32 -04:00
#!/usr/bin/env ruby
require 'templater'
2009-09-29 13:10:47 -04:00
ENV['MM_ENV'] = "build"
2009-09-28 22:43:08 -04:00
# Require app
2009-09-29 13:10:47 -04:00
require File.join(File.dirname(__FILE__), "..", "lib", "middleman")
2009-09-28 22:43:08 -04:00
require 'middleman/builder'
2009-07-27 19:25:32 -04:00
2009-09-29 13:10:47 -04:00
Middleman::Base.init!
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
2009-09-29 13:10:47 -04:00
def destination_root; File.join(Dir.pwd, Middleman::Base.build_dir); end
2009-07-27 19:25:32 -04:00
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)
2009-09-29 13:10:47 -04:00
return if args[0].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-29 13:10:47 -04:00
args[1] = args[0].gsub("#{File.basename(Middleman::Base.views)}/", "")
.gsub("#{File.basename(Middleman::Base.public)}/", "")
2009-09-29 17:30:01 -04:00
if File.extname(args[1]) != ".js"
args[1] = args[1].gsub!(File.extname(args[1]), "") if File.basename(args[1]).split('.').length > 2
end
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)
2009-09-29 13:10:47 -04:00
if (args[0] === args[1])
args[1] = args[0].gsub("#{File.basename(Middleman::Base.views)}/", "")
.gsub("#{File.basename(Middleman::Base.public)}/", "")
2009-09-17 12:40:29 -04:00
end
2009-09-29 13:10:47 -04:00
super(name, *args, &block)
2009-07-27 19:25:32 -04:00
end
2009-09-29 13:10:47 -04:00
glob! File.basename(Middleman::Base.public), Middleman::Base.supported_formats
2009-09-30 18:23:59 -04:00
glob! File.basename(Middleman::Base.views), Middleman::Base.supported_formats
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-29 13:10:47 -04:00
::Middleman::Builder.render_file(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))