Class: ListPortlet

Inherits:
Cms::Portlet show all
Defined in:
app/portlets/list_portlet.rb

Instance Attribute Summary

Attributes inherited from Cms::Portlet

#connect_to_container, #connect_to_page_id, #controller

Instance Method Summary collapse

Methods inherited from Cms::Portlet

blacklist, blacklisted?, columns_for_index, connectable?, #connected_pages, default_template, default_template_path, description, enable_template_editor, form, get_subclass, handler, has_edit_link?, #inline_options, #instance_name, #page_title, #portlet_type_name, render_inline, set_default_template_path, #store_errors_in_flash, #store_hash_in_flash, #store_params_in_flash, #type_name, types, #url_for_failure, #url_for_success

Instance Method Details

#current_content_typeObject



37
38
39
# File 'app/portlets/list_portlet.rb', line 37

def current_content_type
  Cms::ContentType.named(self.content_type).first
end

#expected_view_pathObject



29
30
31
# File 'app/portlets/list_portlet.rb', line 29

def expected_view_path
  File.join(Rails.root, 'app', 'views', 'portlets', 'list', self.name.parameterize('_'), "_#{self.view_as}.html.erb")
end

#renderObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/portlets/list_portlet.rb', line 6

def render
  query = current_content_type.model_class
  limit = self.limit
  unless limit.blank?
    query = query.limit(limit.to_i)
  end
  direction =  self.reverse_order.blank? || self.reverse_order == "0" ? 'asc' : 'desc'
  unless self.order.blank?
    query = query.order("#{self.order} #{direction}")
  end
  @content_blocks = query.all.to_a
end

#view_as_full_pathObject

This is far less flexible than prepending additional view paths, but it suffices for now.



21
22
23
24
25
26
27
# File 'app/portlets/list_portlet.rb', line 21

def view_as_full_path
  if File.exists?(expected_view_path())
    "portlets/list/#{self.name.parameterize('_')}/_#{self.view_as}"
  else
    "portlets/list/_#{self.view_as}"
  end
end

#view_as_pathObject



33
34
35
# File 'app/portlets/list_portlet.rb', line 33

def view_as_path
  "portlets/list/#{self.name.parameterize('_')}/_#{self.view_as}.html.erb"
end