From 9eccf59aece3e126d6f0fc62eafff327ecaae9b2 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 18 Nov 2011 21:35:25 -0800 Subject: [PATCH] fix per-engine layout_engine, add tests --- lib/middleman/base.rb | 64 ++++++++++++++++++++++++----------- middleman-x86-mingw32.gemspec | 1 + middleman.gemspec | 1 + 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index 16f8bae8..09056ef8 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -229,6 +229,9 @@ class Middleman::Base @options = context.has_key?(:options) ? context[:options] : {} @locals = context.has_key?(:locals) ? context[:locals] : {} + engine_options = respond_to?(engine.to_sym) ? send(engine.to_sym) : {} + @options.merge!(engine_options) + provides_metadata.each do |callback, matcher| next if !matcher.nil? && !path.match(matcher) instance_exec(path, &callback) @@ -246,9 +249,9 @@ class Middleman::Base instance_eval(&context[:block]) end - # content_type mime_type(File.extname(@request_path)) + content_type mime_type(File.extname(@request_path)) res.status = 200 - + output = if local_layout layout_engine = if options.has_key?(:layout_engine) options[:layout_engine] @@ -324,20 +327,6 @@ public self.class.map(map, &block) end - # def compiled_templates_cache - # @_compiled_templates_cache ||= {} - # end - # - # def read_compiled_template(path, locals, options, &block) - # key = [path, locals, options] - # - # if !raw_templates_cache.has_key?(key) - # raw_templates_cache[key] = yield - # end - # - # raw_templates_cache[key] - # end - def full_path(path) parts = path ? path.split('/') : [] if parts.last.nil? || parts.last.split('.').length == 1 @@ -395,10 +384,9 @@ public end def send_file(path) - - # matched_mime = mime_type(File.extname(request_path)) - # matched_mime = "application/octet-stream" if matched_mime.nil? - # content_type matched_mime + matched_mime = mime_type(File.extname(path)) + matched_mime = "application/octet-stream" if matched_mime.nil? + content_type matched_mime file = ::Rack::File.new nil file.path = path @@ -412,4 +400,40 @@ public template = ::Tilt.new(path, 1, options) { body } template.render(self, locals, &block) end + + def mime_type(type, value=nil) + return type if type.nil? || type.to_s.include?('/') + type = ".#{type}" unless type.to_s[0] == ?. + return ::Rack::Mime.mime_type(type, nil) unless value + ::Rack::Mime::MIME_TYPES[type] = value + end + + def content_type(type = nil, params={}) + return res['Content-Type'] unless type + default = params.delete :default + mime_type = mime_type(type) || default + throw "Unknown media type: %p" % type if mime_type.nil? + mime_type = mime_type.dup + unless params.include? :charset + params[:charset] = params.delete('charset') || "utf-8" + end + params.delete :charset if mime_type.include? 'charset' + unless params.empty? + mime_type << (mime_type.include?(';') ? ', ' : ';') + mime_type << params.map { |kv| kv.join('=') }.join(', ') + end + res['Content-Type'] = mime_type + end + + def helpers(*extensions, &block) + self.class.helpers(*extensions, &block) + end + + def use(middleware, *args, &block) + self.class.use(middleware, *args, &block) + end + + def map(map, &block) + self.class.map(map, &block) + end end \ No newline at end of file diff --git a/middleman-x86-mingw32.gemspec b/middleman-x86-mingw32.gemspec index 0066bca4..fced4245 100644 --- a/middleman-x86-mingw32.gemspec +++ b/middleman-x86-mingw32.gemspec @@ -24,6 +24,7 @@ Gem::Specification.new do |s| s.add_dependency("thin", ["~> 1.2.11"]) s.add_dependency("thor", ["~> 0.14.0"]) s.add_dependency("tilt", ["~> 1.3.1"]) + s.add_dependency("i18n", ["~> 0.6.0"]) s.add_dependency("rack-test", ["~> 0.6.1"]) s.add_dependency("uglifier", ["~> 1.1.0"]) s.add_dependency("haml", ["~> 3.1.0"]) diff --git a/middleman.gemspec b/middleman.gemspec index 200b580c..6acf175d 100644 --- a/middleman.gemspec +++ b/middleman.gemspec @@ -24,6 +24,7 @@ Gem::Specification.new do |s| s.add_dependency("thin", ["~> 1.2.11"]) s.add_dependency("thor", ["~> 0.14.0"]) s.add_dependency("tilt", ["~> 1.3.1"]) + s.add_dependency("i18n", ["~> 0.6.0"]) s.add_dependency("rack-test", ["~> 0.6.1"]) s.add_dependency("uglifier", ["~> 1.1.0"]) s.add_dependency("haml", ["~> 3.1.0"])