Created
June 13, 2015 02:59
-
-
Save liushooter/beb70f1c7e98fd30c377 to your computer and use it in GitHub Desktop.
💋 扩展grape的formatter, 支持返回 html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Grape | |
module ContentTypes | |
def self.content_types_for(from_settings) | |
if from_settings.present? | |
from_settings | |
else | |
ActiveSupport::OrderedHash[ | |
:xml, 'application/xml', | |
:serializable_hash, 'application/json', | |
:json, 'application/json', | |
:binary, 'application/octet-stream', | |
:txt, 'text/plain', | |
:html, 'text/html' | |
] | |
end | |
end | |
end | |
end | |
module Grape | |
module Formatter | |
module Html | |
class << self | |
def call(object, env) | |
end | |
end | |
end | |
end | |
end | |
Grape::Formatter::Base.formatters({html: Grape::Formatter::Html}) | |
##### | |
class Doc < Grape::API | |
format :html | |
content_type :html, 'text/html' | |
get '/path' do | |
#render erb template | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment