Sha256: f2c37b5bad32dfe40a59e9326608facfce491c4807206d87d7319bd77ab01934

Contents?: true

Size: 1.93 KB

Versions: 4

Compression:

Stored size: 1.93 KB

Contents

module Cms
  module PathHelper
    def cms_index_path_for(resource, options={})
      send("cms_#{resource_collection_name(resource).pluralize}_path", options)
    end
    
    def cms_index_url_for(resource, options={})
      send("cms_#{resource_collection_name(resource).pluralize}_url", options)
    end
    
    def cms_new_path_for(resource, options={})
      send("new_cms_#{resource_collection_name(resource)}_path", options)
    end
    
    def cms_new_url_for(resource, options={})
      send("new_cms_#{resource_collection_name(resource)}_url", options)
    end
    
    def cms_versions_path_for(resource, options={})
      options.merge!(:id => resource.id) unless options[:id]
      send("versions_cms_#{resource_collection_name(resource)}_path", options)
    end
    
    def cms_revert_to_path_for(resource, options={})
      options.merge!(:id => resource.id) unless options[:id]
      options.merge!(:version => resource.version) unless options[:version]
      send("revert_to_cms_#{resource_collection_name(resource)}_path", options)
    end
        
    def cms_connectable_path(connectable, options={})
      if Portlet === connectable
        cms_portlet_path(connectable)
      else
        [:cms, connectable]
      end
    end
    
    def edit_cms_connectable_path(connectable, options={})
      if Portlet === connectable
        edit_cms_portlet_path(connectable, options)
      else
        polymorphic_path([:edit, :cms, connectable], options)        
      end
    end
    
    private
      # Returns the name of the collection that this resouce belongs to
      # the resource can be a ContentType, ActiveRecord::Base instance
      # or just a string or symbol
      def resource_collection_name(resource)
        collection_name = case resource
          when ContentType then resource.name.underscore
          when ActiveRecord::Base then resource.class.name.underscore
          else resource.to_s
        end
      end
        
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
webficient-browsercms-3.0.1 app/helpers/cms/path_helper.rb
webficient-browsercms-3.0.2 app/helpers/cms/path_helper.rb
webficient-browsercms-3.0.3 app/helpers/cms/path_helper.rb
webficient-browsercms-3.0.4 app/helpers/cms/path_helper.rb