app/controllers/landable/api_controller.rb in landable-1.11.1 vs app/controllers/landable/api_controller.rb in landable-1.12.1

- old
+ new

@@ -62,9 +62,30 @@ def require_author! head :unauthorized if current_author.nil? end + def with_format(format, &block) + old_formats = formats + + begin + self.formats = [format] + return block.call + ensure + self.formats = old_formats + end + end + + def generate_preview_for(page) + if layout = page.theme.try(:file) || false + with_format(:html) do + render_to_string text: RenderService.call(page), layout: layout + end + else + RenderService.call(page, preview: true) + end + end + def current_author return @current_author if @current_author authenticate_with_http_basic do |username, token| @current_author = Author.authenticate!(username, token) end