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_path = SHARED_SERVER.reroute_builder(destination, request_path)
    
    request_path.gsub!(/\s/, "%20")
    response = Middleman::Builder.shared_rack.get(request_path)
    
    create_file destination, nil, config do
      response.body
    end if response.status == 200
  rescue
  end
end