lib/happy/controller_ext/actions.rb in happy-0.1.0.pre.3 vs lib/happy/controller_ext/actions.rb in happy-0.1.0.pre.4

- old
+ new

@@ -8,20 +8,25 @@ # Don't serve is data is not a string. return unless data.is_a?(String) # Mix in default options options = { - layout: context.layout + :layout => context.layout }.merge(options) - # Add optional headers et al - response.status = options[:status] if options.has_key?(:status) - response['Content-type'] = options[:content_type] if options.has_key?(:content_type) + # Add status code from options + response.status = options.delete(:status) if options.has_key?(:status) + # Extract layout + layout = options.delete(:layout) + + # Treat remaining options as headers + options.each { |k, v| header k, v } + # Apply layout, if available - if options[:layout] - data = render(options[:layout]) { data } + if layout + data = render(layout) { data } end # Set response body and finish request response.body = [data] halt! @@ -30,21 +35,21 @@ def halt!(message = :done) throw message end def redirect!(to, status = 302) - header "Location", url_for(to) + header :location, url_for(to) response.status = status halt! end def layout(name) context.layout = name end def content_type(type) - header 'Content-type', type + header :content_type, type end def max_age(t, options = {}) options = { :public => true, @@ -58,13 +63,14 @@ cache_control s.join(', ') end def cache_control(s) - header 'Cache-control', s + header :cache_control, s end def header(name, value) + name = name.to_s.dasherize.humanize if name.is_a?(Symbol) response[name] = value end def invoke(klass, options = {}, &blk) klass.new(env, options, &blk).perform