Class: Cmsimple::PageResponder

Inherits:
Object
  • Object
show all
Defined in:
lib/cmsimple/page_responder.rb

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ PageResponder

Returns a new instance of PageResponder.



3
4
5
6
7
8
# File 'lib/cmsimple/page_responder.rb', line 3

def initialize(controller)
  @controller  = controller
  @request     = @controller.request
  @params      = @request.params
  @page        = @controller.current_page
end

Instance Method Details

#current_page_is_viewable?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/cmsimple/page_responder.rb', line 38

def current_page_is_viewable?
  is_currently_editable? || @page.published?
end

#draft_context?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/cmsimple/page_responder.rb', line 34

def draft_context?
  @page
end

#is_currently_editable?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/cmsimple/page_responder.rb', line 42

def is_currently_editable?
  @controller.in_editor_iframe?
end

#page_for_contextObject

Raises:

  • (ActiveRecord::RecordNotFound)


14
15
16
17
18
19
20
# File 'lib/cmsimple/page_responder.rb', line 14

def page_for_context
  raise ActiveRecord::RecordNotFound unless current_page_is_viewable?

  return published_context? ||
           version_context? ||
           draft_context?
end

#published_context?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/cmsimple/page_responder.rb', line 22

def published_context?
  unless is_currently_editable?
    return @page if @page.as_published!
  end
end

#respondObject



10
11
12
# File 'lib/cmsimple/page_responder.rb', line 10

def respond
  @controller.respond_with page_for_context
end

#version_context?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/cmsimple/page_responder.rb', line 28

def version_context?
  if @params[:version].present?
    return @page if @page.at_version!(@params[:version])
  end
end