Sha256: a8a01734b79b4ab4ec253ebc1623f90632530f4fbe9f153809a58cc2d08037e7

Contents?: true

Size: 1.69 KB

Versions: 14

Compression:

Stored size: 1.69 KB

Contents

require_dependency 'landable/api_controller'

module Landable
  module Api
    class ThemesController < ApiController
      # filters
      before_filter :load_theme, except: [:create, :index, :preview]

      # RESTful methods
      def create
        theme = Theme.new(theme_params)
        theme.save!
        
        respond_with theme, status: :created, location: theme_url(theme)
      end

      def destroy
        @theme.try(:deactivate)
        
        respond_with @theme
      end

      def index
        respond_with Theme.all
      end

      def reactivate
        @theme.try(:reactivate)
        
        respond_with @theme
      end

      def show
        respond_with @theme
      end

      def update
        @theme.update_attributes!(theme_params)
        
        respond_with @theme
      end

      # custom methods
      def preview
        theme = Theme.new(theme_params)
        page  = Page.example(theme: theme)

        params[:theme][:asset_ids].try(:each) do |asset_id|
          theme.attachments.add Asset.find(asset_id)
        end
        
        content = render_to_string(
          text: RenderService.call(page),
          layout: page.theme.file || false
        )
        
        respond_to do |format|
          format.html do
            render text: content, layout: false, content_type: 'text/html'
          end
          
          format.json do
            render json: {theme: {preview: content}}
          end
        end
      end

      private
        def load_theme
          @theme = Theme.find(params[:id])
        end

        def theme_params
          params.require(:theme).permit(:id, :name, :body, :description, :thumbnail_url)
        end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
landable-1.13.1 app/controllers/landable/api/themes_controller.rb
landable-1.12.3 app/controllers/landable/api/themes_controller.rb
landable-1.12.2 app/controllers/landable/api/themes_controller.rb
landable-1.12.1 app/controllers/landable/api/themes_controller.rb
landable-1.11.1 app/controllers/landable/api/themes_controller.rb
landable-1.11.0 app/controllers/landable/api/themes_controller.rb
landable-1.10.0.rc2 app/controllers/landable/api/themes_controller.rb
landable-1.10.0.rc1 app/controllers/landable/api/themes_controller.rb
landable-1.9.2 app/controllers/landable/api/themes_controller.rb
landable-1.9.1 app/controllers/landable/api/themes_controller.rb
landable-1.9.0 app/controllers/landable/api/themes_controller.rb
landable-1.9.0.rc2 app/controllers/landable/api/themes_controller.rb
landable-1.9.0.rc1 app/controllers/landable/api/themes_controller.rb
landable-1.8.0 app/controllers/landable/api/themes_controller.rb