Class: Smithy::PagesController

Inherits:
BaseController show all
Includes:
Liquid::Rendering
Defined in:
app/controllers/smithy/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



29
30
31
32
33
34
35
# File 'app/controllers/smithy/pages_controller.rb', line 29

def create
  @page.save
  flash.notice = "Your page was created #{@page.published? ? 'and published' : 'as a draft'}" if @page.persisted?
  respond_with @page do |format|
    format.html { @page.persisted? ? redirect_to(edit_page_path(@page.id)) : render(:action => 'new') }
  end
end

#destroyObject



48
49
50
51
# File 'app/controllers/smithy/pages_controller.rb', line 48

def destroy
  @page.destroy
  respond_with @page.parent ? @page.parent : @page
end

#editObject



37
38
39
# File 'app/controllers/smithy/pages_controller.rb', line 37

def edit
  respond_with @page
end

#indexObject



14
15
16
# File 'app/controllers/smithy/pages_controller.rb', line 14

def index
  respond_with @root
end

#newObject



25
26
27
# File 'app/controllers/smithy/pages_controller.rb', line 25

def new
  respond_with @page
end

#orderObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/smithy/pages_controller.rb', line 53

def order
  first = Smithy::Page.find(params[:order].shift)
  @parent = first.parent
  if @parent && @parent.children.count > 1 # Only need to order if there are multiple children.
    left = first.id
    params[:order].each do |page_id|
      page = Smithy::Page.find(page_id)
      page.move_to_right_of(left)
      left = page.id
    end
  end
  render :nothing => true, :status => 200 and return if request.xhr?
  redirect_to pages_path
end

#selector_modalObject



68
69
70
71
72
# File 'app/controllers/smithy/pages_controller.rb', line 68

def selector_modal
  respond_to do |format|
    format.html { render :layout => 'smithy/modal' }
  end
end

#showObject



18
19
20
21
22
23
# File 'app/controllers/smithy/pages_controller.rb', line 18

def show
  render_page and return if smithy_current_user # no caching if you're editing
  # adding :public param allow Rack::Cache to cache the result
  @page.cache_length == 0 ? expires_now : expires_in(@page.cache_length.to_i.seconds, :public => true)
  render_page if stale?(:etag => @page, :last_modified => @page.updated_at.utc, :public => true)
end

#updateObject



41
42
43
44
45
46
# File 'app/controllers/smithy/pages_controller.rb', line 41

def update
  flash.notice = "Your page was saved #{@page.published? ? 'and published' : 'as a draft'}" if @page.update_attributes(filtered_params)
  respond_with @page do |format|
    format.html { redirect_to edit_page_path(@page.id) }
  end
end