app/controllers/landable/api/templates_controller.rb in landable-1.11.1 vs app/controllers/landable/api/templates_controller.rb in landable-1.12.1
- old
+ new
@@ -2,11 +2,11 @@
module Landable
module Api
class TemplatesController < ApiController
# filters
- before_filter :load_template, except: [:create, :index]
+ before_filter :load_template, except: [:create, :index, :preview]
# RESTful methods
def create
template = Template.new(template_params)
template.save!
@@ -44,9 +44,29 @@
def reactivate
@template.try(:reactivate)
respond_with @template
+ end
+
+ # custom methods
+ def preview
+ template = Template.new(template_params)
+ theme = Theme.most_used_on_pages
+
+ page = Page.example(theme: theme, body: template.body)
+
+ content = generate_preview_for(page)
+
+ respond_to do |format|
+ format.html do
+ render text: content, layout: false, content_type: 'text/html'
+ end
+
+ format.json do
+ render json: { template: { preview: content } }
+ end
+ end
end
private
def template_params
params.require(:template).permit(:id, :name, :body, :description, :thumbnail_url,