Sha256: df4e5ba8a8380325881e09887b3d801b488c040a8b67275306c91dce7bac8015

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

module Schnitzelpress
  module Actions
    module Admin
      extend ActiveSupport::Concern

      included do
        before '/admin/?*' do
          admin_only!
        end

        get '/admin/?' do
          @posts  = Post.published.posts.desc(:published_at)
          @pages  = Post.published.pages
          @drafts = Post.drafts
          haml :'admin/admin'
        end

        get '/admin/config/?' do
          haml :'admin/config'
        end

        post '/admin/config' do
          config.attributes = params[:config]
          if config.save
            CacheControl.bust!
            redirect '/admin'
          else
            haml :'admin/config'
          end
        end

        get '/admin/new/?' do
          @post = Post.new
          haml :'admin/new'
        end

        post '/admin/new/?' do
          @post = Post.new(params[:post])
          if @post.save
            redirect url_for(@post)
          else
            haml :'admin/new'
          end
        end

        get '/admin/edit/:id/?' do
          @post = Post.find(params[:id])
          haml :'admin/edit'
        end

        put '/admin/edit/:id/?' do
          @post = Post.find(params[:id])
          @post.attributes = params[:post]
          if @post.save
            redirect url_for(@post)
          else
            haml :'admin/edit'
          end
        end

        delete '/admin/edit/:id/?' do
          @post = Post.find(params[:id])
          @post.destroy
          redirect '/admin'
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
schnitzelpress-0.2.1 lib/schnitzelpress/actions/admin.rb
schnitzelpress-0.2.0 lib/schnitzelpress/actions/admin.rb