reorg build constants. Update docs

This commit is contained in:
Thomas Reynolds 2011-11-27 20:49:46 -08:00
parent d12b3a95d2
commit 0ef8de6106
4 changed files with 44 additions and 34 deletions

View file

@ -14,7 +14,7 @@ http://middlemanapp.com
If you have questions, answers can be found on community forum: https://convore.com/middleman/ If you have questions, answers can be found on community forum: https://convore.com/middleman/
# Generated Source Documentation ## Generated Source Documentation
http://rubydoc.info/github/tdreyno/middleman/master/frames http://rubydoc.info/github/tdreyno/middleman/master/frames
## Copyright ## Copyright

View file

@ -1,40 +1,26 @@
require "thor" require "thor"
require "thor/group" require "thor/group"
require 'rack/test' require "rack/test"
require 'find' require "find"
SHARED_SERVER_INST = Middleman.server.inst do
set :environment, :build
end
SHARED_SERVER = SHARED_SERVER_INST.class
module Middleman module Middleman
module ThorActions
def tilt_template(source, *args, &block)
config = args.last.is_a?(Hash) ? args.pop : {}
destination = args.first || source
request_path = destination.sub(/^#{SHARED_SERVER_INST.build_dir}/, "")
begin
destination, request_path = SHARED_SERVER_INST.reroute_builder(destination, request_path)
response = Middleman::Builder.shared_rack.get(request_path.gsub(/\s/, "%20"))
create_file(destination, response.body, config) if response.status == 200
rescue
say_status :error, destination, :red
end
end
end
class Builder < Thor::Group class Builder < Thor::Group
include Thor::Actions include Thor::Actions
include Middleman::ThorActions
class << self class << self
def shared_instance
@_shared_instance ||= ::Middleman.server.inst do
set :environment, :build
end
end
def shared_server
@_shared_server ||= shared_instance.class
end
def shared_rack def shared_rack
@shared_rack ||= begin @_shared_rack ||= begin
mock = ::Rack::MockSession.new(SHARED_SERVER.to_rack_app) mock = ::Rack::MockSession.new(shared_server.to_rack_app)
sess = ::Rack::Test::Session.new(mock) sess = ::Rack::Test::Session.new(mock)
response = sess.get("__middleman__") response = sess.get("__middleman__")
sess sess
@ -42,6 +28,26 @@ module Middleman
end end
end end
# @private
module ThorActions
def tilt_template(source, *args, &block)
config = args.last.is_a?(Hash) ? args.pop : {}
destination = args.first || source
request_path = destination.sub(/^#{::Middleman::Builder.shared_instance.build_dir}/, "")
# begin
destination, request_path = ::Middleman::Builder.shared_instance.reroute_builder(destination, request_path)
response = ::Middleman::Builder.shared_rack.get(request_path.gsub(/\s/, "%20"))
create_file(destination, response.body, config) if response.status == 200
# rescue
# say_status :error, destination, :red
# end
end
end
include ThorActions
class_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls' class_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
class_option :glob, :type => :string, :aliases => "-g", :default => nil, :desc => 'Build a subset of the project' class_option :glob, :type => :string, :aliases => "-g", :default => nil, :desc => 'Build a subset of the project'
@ -49,13 +55,13 @@ module Middleman
super super
if options.has_key?("relative") && options["relative"] if options.has_key?("relative") && options["relative"]
SHARED_SERVER_INST.activate :relative_assets self.class.shared_instance.activate :relative_assets
end end
end end
def source_paths def source_paths
@source_paths ||= [ @source_paths ||= [
SHARED_SERVER_INST.root self.class.shared_instance.root
] ]
end end
@ -66,12 +72,13 @@ module Middleman
opts[:glob] = options["glob"] if options.has_key?("glob") opts[:glob] = options["glob"] if options.has_key?("glob")
opts[:clean] = options["clean"] if options.has_key?("clean") opts[:clean] = options["clean"] if options.has_key?("clean")
action GlobAction.new(self, SHARED_SERVER_INST, opts) action GlobAction.new(self, self.class.shared_instance, opts)
SHARED_SERVER_INST.run_hook :after_build, self self.class.shared_instance.run_hook :after_build, self
end end
end end
# @private
class GlobAction < ::Thor::Actions::EmptyDirectory class GlobAction < ::Thor::Actions::EmptyDirectory
attr_reader :source attr_reader :source
@ -117,7 +124,7 @@ module Middleman
end end
def directory_empty?(directory) def directory_empty?(directory)
Dir["#{directory}/*"].empty? Dir[File.join(directory, "*")].empty?
end end
def queue_current_paths def queue_current_paths

View file

@ -33,6 +33,7 @@ module Middleman
end end
end end
# @private
module Guard module Guard
class Middleman < Guard class Middleman < Guard
def initialize(watchers = [], options = {}) def initialize(watchers = [], options = {})

View file

@ -3,5 +3,7 @@ require "rubygems"
module Middleman module Middleman
VERSION = "3.0.0.alpha.3" VERSION = "3.0.0.alpha.3"
# @private
GEM_VERSION = ::Gem::Version.create(VERSION) GEM_VERSION = ::Gem::Version.create(VERSION)
end end