Module: Pulitzer::ControllerHelpers

Defined in:
lib/pulitzer/controller_helpers.rb

Instance Method Summary collapse

Instance Method Details

#get_active_post(post_type_name) ⇒ Object



9
10
11
12
13
# File 'lib/pulitzer/controller_helpers.rb', line 9

def get_active_post(post_type_name)
  @post_type_version = Pulitzer::PostType.named(post_type_name).published_type_version
  @post = get_post_for_version(@post_type_version,:active)
  return @post, @post_type_version
end

#get_post_for_version(ptv, status) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pulitzer/controller_helpers.rb', line 21

def get_post_for_version(ptv,status)
  if ptv.present?
    if ptv.plural?
      ptv.posts.find_by!(slug: params[:slug]).send "get_#{status}_version!"
    else
      ptv.singleton_post.send "get_#{status}_version!"
    end
  else
    nil
  end
end

#get_preview_post(post_type_name) ⇒ Object



15
16
17
18
19
# File 'lib/pulitzer/controller_helpers.rb', line 15

def get_preview_post(post_type_name)
  @post_type_version = Pulitzer::PostType.named(post_type_name).post_type_versions.find_by(version_number: params[:version_number])
  @post = get_post_for_version(@post_type_version,:preview)
  return @post, @post_type_version
end

#pulitzer_view_path(version_number) ⇒ Object



3
4
5
6
7
# File 'lib/pulitzer/controller_helpers.rb', line 3

def pulitzer_view_path(version_number)
  File.join Pulitzer.public_controller,
    action_name,
    "v_#{version_number.to_s}.html.erb"
end