lib/rasti/web/render.rb in rasti-web-2.0.1 vs lib/rasti/web/render.rb in rasti-web-2.1.0

- old
+ new

@@ -9,63 +9,66 @@ @response = response @view_context = ViewContext.new request, response end def status(status, *args) - respond_with status, - extract_headers(args), + respond_with status, + extract_headers(args), extract_body(args) end def text(text, *args) - respond_with extract_status(args), - extract_headers(args).merge('Content-Type' => 'text/plain; charset=utf-8'), + respond_with extract_status(args), + extract_headers(args).merge(Headers.for_text), text end def html(html, *args) - respond_with extract_status(args), - extract_headers(args).merge('Content-Type' => 'text/html; charset=utf-8'), + respond_with extract_status(args), + extract_headers(args).merge(Headers.for_html), html end def json(object, *args) - respond_with extract_status(args), - extract_headers(args).merge('Content-Type' => 'application/json; charset=utf-8'), + respond_with extract_status(args), + extract_headers(args).merge(Headers.for_json), object.is_a?(String) ? object : JSON.dump(object) end def js(script, *args) - respond_with extract_status(args), - extract_headers(args).merge('Content-Type' => 'application/javascript; charset=utf-8'), + respond_with extract_status(args), + extract_headers(args).merge(Headers.for_js), script end def css(stylesheet, *args) - respond_with extract_status(args), - extract_headers(args).merge('Content-Type' => 'text/css; charset=utf-8'), + respond_with extract_status(args), + extract_headers(args).merge(Headers.for_css), stylesheet end def file(filename, *args) - content_type = MIME::Types.of(filename).first.content_type - body = File.read filename + respond_with extract_status(args), + Headers.for_file(filename).merge(extract_headers(args)), + File.read(filename) + end - respond_with extract_status(args), - extract_headers(args).merge('Content-Type' => content_type), - body + def data(content, *args) + respond_with extract_status(args), + extract_headers(args), + content end def partial(template, locals={}) - response['Content-Type'] = 'text/html; charset=utf-8' + response.headers.merge! Headers.for_html response.write view_context.render(template, locals) end def layout(template=nil, &block) content = block.call if block layout = view_context.render(template || Web.default_layout) { content } - - response['Content-Type'] = 'text/html; charset=utf-8' + + response.headers.merge! Headers.for_html response.write layout end def view(template, locals={}, layout_template=nil) layout(layout_template) { view_context.render template, locals } \ No newline at end of file