Module: Cms::PathHelper
- Defined in:
- app/helpers/cms/path_helper.rb
Overview
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
-
#attachment_path_for(attachment) ⇒ Object
Returns the relative path to the given attachment.
-
#edit_engine_aware_path(model_or_class_or_content_type, options = {}) ⇒ Object
Wrappers edit_polymorphic_path to be engine aware.
-
#engine(resource) ⇒ ActionDispatch::Routing::RoutesProxy
(also: #engine_for)
Returns the route proxy (aka engine) for a given resource, which can then have named paths called on it.
-
#engine_aware_path(model_or_class_or_content_type, action = false) ⇒ Array
Return the path for a given resource.
-
#link_to_addressable_content(name, content) ⇒ Object
Link_to_if would call content.path even if it doesn’t respond to ‘.
- #link_to_usages(block) ⇒ Object
-
#new_engine_aware_path(subject, options = {}) ⇒ Object
Wrappers new_polymorphic_path to be engine aware.
-
#sortable_column_path(content_type, column_to_sort) ⇒ Object
Returns a path to sort a table of Content Blocks by a given parameter.
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.
19 20 21 22 23 24 25 26 |
# File 'app/helpers/cms/path_helper.rb', line 19 def () return "" unless if current_user.able_to?(:edit_content) . else .url end end |
#edit_engine_aware_path(model_or_class_or_content_type, options = {}) ⇒ Object
Wrappers edit_polymorphic_path to be engine aware.
97 98 99 |
# File 'app/helpers/cms/path_helper.rb', line 97 def edit_engine_aware_path(model_or_class_or_content_type, ={}) edit_polymorphic_path(build_path_for(model_or_class_or_content_type), ) end |
#engine(resource) ⇒ ActionDispatch::Routing::RoutesProxy Also known as: engine_for
Returns the route proxy (aka engine) for a given resource, which can then have named paths called on it.
I.e. engine(@block).polymorphic_path([@block, :preview])
65 66 67 68 |
# File 'app/helpers/cms/path_helper.rb', line 65 def engine(resource) name = EngineAwarePathBuilder.new(resource).engine_name send(name) end |
#engine_aware_path(model_or_class_or_content_type, action = false) ⇒ Array
Return the path for a given resource. Determines the relevant engine, and the result can be passed to polymporhic_path
or [cms, :html_blocks, @block]
This will work whether the block is:
1. A block in a project (namespaced to the project) (i.e. Dummy::Product)
2. A core CMS block (i.e. Cms::Portlet)
3. A block in a module (i.e. BcmsNews::NewsArticle)
e.g.
engine_aware_path(Dummy::Product.find(1)) => /dummy/products/1
engine_aware_path(Cms::HtmlBlock.find(1)) => /cms/html_blocks/1
engine_aware_path(BcmsNews::NewsArticle.find(1)) => /bcms_news/news_articles/1
90 91 92 93 94 |
# File 'app/helpers/cms/path_helper.rb', line 90 def engine_aware_path(model_or_class_or_content_type, action = false) elements = build_path_for(model_or_class_or_content_type) elements << action if action elements end |
#link_to_addressable_content(name, content) ⇒ Object
Link_to_if would call content.path even if it doesn’t respond to ‘
10 11 12 13 14 15 16 |
# File 'app/helpers/cms/path_helper.rb', line 10 def link_to_addressable_content(name, content) if content.respond_to? :path link_to name, content.path else name end end |
#link_to_usages(block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/cms/path_helper.rb', line 40 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 << block p end link_to count, path, :id => block.id, :block_type => block.content_block_type else count end end |
#new_engine_aware_path(subject, options = {}) ⇒ Object
Wrappers new_polymorphic_path to be engine aware.
102 103 104 |
# File 'app/helpers/cms/path_helper.rb', line 102 def new_engine_aware_path(subject, ={}) new_polymorphic_path(build_path_for(subject), ) end |
#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).
32 33 34 35 36 37 38 |
# File 'app/helpers/cms/path_helper.rb', line 32 def 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)) polymorphic_path(engine_aware_path(content_type.model_class), filtered_params) end |