app/controllers/landable/api_controller.rb in landable-1.13.1 vs app/controllers/landable/api_controller.rb in landable-1.13.2
- old
+ new
@@ -1,8 +1,8 @@
-require_dependency "landable/application_controller"
-require_dependency "landable/api_responder"
-require_dependency "landable/author"
+require_dependency 'landable/application_controller'
+require_dependency 'landable/api_responder'
+require_dependency 'landable/author'
module Landable
class ApiController < ApplicationController
# skip any of these that may have been inherited from ::ApplicationController
skip_before_filter :protect_from_forgery
@@ -14,19 +14,19 @@
before_filter :require_author!
respond_to :json
self.responder = Landable::ApiResponder
- rescue_from ActiveRecord::RecordNotFound do |ex|
+ rescue_from ActiveRecord::RecordNotFound do
head 404
end
rescue_from ActiveRecord::RecordInvalid do |ex|
render json: { errors: ex.record.errors }, status: :unprocessable_entity
end
- rescue_from ActionController::UnknownFormat do |ex|
+ rescue_from ActionController::UnknownFormat do
head :not_acceptable
end
rescue_from ActiveRecord::StaleObjectError do |ex|
render json: { author: ex.record.updated_by_author }, status: 409
@@ -34,28 +34,27 @@
rescue_from PG::Error do |ex|
if ex.message =~ /invalid input syntax for uuid/
head :not_found
else
- raise ex
+ fail ex
end
end
-
# here's looking at you, http://developer.github.com/v3/media/
# mime type matching is still handled by rails - see lib/landable/mime_types.rb
- API_MEDIA_REGEX = /^application\/vnd\.landable(\.v(?<version>[\w\-]+))?(\.(?<param>(?:[\w\-]+)))?(\+(?<format>[\w\-]+))?/
+ API_MEDIA_REGEX = %r{^application\/vnd\.landable(\.v(?<version>[\w\-]+))?(\.(?<param>(?:[\w\-]+)))?(\+(?<format>[\w\-]+))?}
def api_media
@api_media ||= begin
accept = request.headers['Accept'].match(API_MEDIA_REGEX) || {}
{
version: Landable::VERSION::STRING,
format: request.format.symbol,
- param: accept['param'].presence,
+ param: accept['param'].presence
}
end
end
protected
@@ -74,11 +73,12 @@
self.formats = old_formats
end
end
def generate_preview_for(page)
- if layout = page.theme.try(:file) || false
+ layout = page.theme.try(:file)
+ if layout
with_format(:html) do
render_to_string text: RenderService.call(page), layout: layout
end
else
RenderService.call(page, preview: true)
@@ -89,8 +89,7 @@
return @current_author if @current_author
authenticate_with_http_basic do |username, token|
@current_author = Author.authenticate!(username, token)
end
end
-
end
end