module Middleman::ThorActions

def tilt_template(source, *args, &block)

def tilt_template(source, *args, &block)
  config = args.last.is_a?(Hash) ? args.pop : {}
  destination = args.first || source
  
  # source  = File.expand_path(find_in_source_paths(source.to_s))
  context = instance_eval('binding')
  
  request_path = destination.sub(/^#{SHARED_SERVER.build_dir}/, "")
  
  begin        
    destination, request_page = SHARED_SERVER.reroute_builder(destination, request_path)
  
    create_file destination, nil, config do
      Middleman::Builder.shared_rack.get(request_path.gsub(/\s/, "%20"))
      Middleman::Builder.shared_rack.last_response.body
    end
  rescue
  end
end