Module: Cms::PathHelper

Included in:
ApplicationController
Defined in:
app/helpers/cms/path_helper.rb

Overview

TODO:

All methods really need to be renamed to match conventions for Engines.

In CMS::Engine, shouldn't have cms_ in method name. From app, should be cms.xyz_path

Instance Method Summary collapse

Instance Method Details

#attachment_path_for(attachment) ⇒ Object

Returns the relative path to the given attachment. Content editors will see exact specific version path, while other users will see the 'public' url for the path.



10
11
12
13
14
15
16
17
# File 'app/helpers/cms/path_helper.rb', line 10

def attachment_path_for(attachment)
  return "" unless attachment
  if current_user.able_to?(:edit_content)
    attachment.attachment_version_path
  else
    attachment.url
  end
end

#cms_connectable_path(connectable, options = {}) ⇒ String

Returns path suitable to give to link_to

Parameters:

  • connectable (Class, String)

    The model class (i.e. HtmlBlock) or plural collection name (html_blocks) to link to

  • options (Hash) (defaults to: {})

    Passed to polymorphic_path

Returns:

  • (String)

    path suitable to give to link_to



54
55
56
57
58
59
60
# File 'app/helpers/cms/path_helper.rb', line 54

def cms_connectable_path(connectable, options={})
  if Portlet === connectable
    cms.portlet_path(connectable)
  else
    polymorphic_path(build_path_for(connectable), options)
  end
end

#cms_index_path_for(resource, options = {}) ⇒ Object

Deprecated.

Use cms_connectable_path instead.



32
33
34
# File 'app/helpers/cms/path_helper.rb', line 32

def cms_index_path_for(resource, options={})
  polymorphic_path(build_path_for(resource), options)
end

#cms_index_url_for(resource, options = {}) ⇒ Object

Deprecated.

Remove all usages of this in favor of cms_index_path_for ()



37
38
39
# File 'app/helpers/cms/path_helper.rb', line 37

def cms_index_url_for(resource, options={})
  send("#{resource_collection_name(resource).underscore.pluralize.gsub('/', '_')}_url", options)
end

#cms_new_path_for(resource, options = {}) ⇒ Object



41
42
43
# File 'app/helpers/cms/path_helper.rb', line 41

def cms_new_path_for(resource, options={})
  new_polymorphic_path(build_path_for(resource), options)
end

#cms_new_url_for(resource, options = {}) ⇒ Object

Deprecated.

Remove all usages of this in favor of cms_new_path_for ()



46
47
48
# File 'app/helpers/cms/path_helper.rb', line 46

def cms_new_url_for(resource, options={})
  send("new_#{resource_collection_name(resource).underscore.gsub('/', '_')}_url", options)
end

#cms_sortable_column_path(content_type, column_to_sort) ⇒ Object

Returns a path to sort a table of Content Blocks by a given parameter. Retains other relevant parameters (like search criteria).

Parameters:

  • content_type (Cms::ContentType)
  • column_to_sort (String)

    The name of the column to sort on.



23
24
25
26
27
28
29
# File 'app/helpers/cms/path_helper.rb', line 23

def cms_sortable_column_path(content_type, column_to_sort)
  filtered_params = params.clone
  filtered_params.delete(:action)
  filtered_params.delete(:controller)
  filtered_params.merge!(:order => determine_order(filtered_params[:order], column_to_sort))
  cms_connectable_path(content_type.model_class, filtered_params)
end

#edit_cms_connectable_path(connectable, options = {}) ⇒ Object

TODO:

Really needs to be renamed to match conventions for Engines.

In CMS::Engine, should be edit_connectable_path From app, should be cms.edit_connectable_path



65
66
67
68
69
70
71
# File 'app/helpers/cms/path_helper.rb', line 65

def edit_cms_connectable_path(connectable, options={})
  if Portlet === connectable
    edit_portlet_path(connectable, options)
  else
    edit_polymorphic_path(build_path_for(connectable), options)
  end
end

#engine_for(resource) ⇒ Object

Returns the Engine Proxy that this resource is from.



93
94
95
96
# File 'app/helpers/cms/path_helper.rb', line 93

def engine_for(resource)
  EngineHelper.decorate(resource)
  send(resource.engine_name)
end


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/helpers/cms/path_helper.rb', line 73

def link_to_usages(block)
  count = block.connected_pages.count
  if count > 0
    # Would love a cleaner solution to this problem, see http://stackoverflow.com/questions/702728
    path = if Portlet === block
             usages_portlet_path(block)
           else
             p = []
             p << engine_for(block)
             p << :usages
             p.concat path_elements_for(block)
             p
           end
    link_to count, path, :id => block.id, :block_type => block.content_block_type
  else
    count
  end
end

#path_elements_for(resource) ⇒ Object



98
99
100
101
# File 'app/helpers/cms/path_helper.rb', line 98

def path_elements_for(resource)
  EngineHelper.decorate(resource)
  resource.path_elements
end