Module: Simplec::ActionController::Extensions
- Included in:
- Simplec::ApplicationController
- Defined in:
- lib/simplec/action_controller/extensions.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#page(path, options = {}) ⇒ Simplec::Page
TODO docs.
-
#simplec_path_for(page_or_path, options = {}) ⇒ String?
Get the path of a page.
-
#simplec_url_for(page_or_path, options = {}) ⇒ String?
Get the url of a page.
-
#subdomain(name = nil) ⇒ Object
Get the subdomain.
Class Method Details
.included(receiver) ⇒ Object
5 6 7 8 |
# File 'lib/simplec/action_controller/extensions.rb', line 5 def self.included(receiver) receiver.helper_method :subdomain, :page, :simplec_path_for, :simplec_url_for end |
Instance Method Details
#page(path, options = {}) ⇒ Simplec::Page
TODO docs
23 24 25 26 27 28 29 30 31 |
# File 'lib/simplec/action_controller/extensions.rb', line 23 def page(path, ={}) @_page ||= Hash.new key = "#{subdomain([:subdomain])};#{path}" return @_page[key] if @_page[key] # TODO add raise option for find_by! @_page[key] = subdomain([:subdomain]).pages. includes(:subdomain).find_by!(path: path) end |
#simplec_path_for(page_or_path, options = {}) ⇒ String?
Get the path of a page.
By default, if the Page cannot be located nil will be the result.
50 51 52 53 54 55 56 57 |
# File 'lib/simplec/action_controller/extensions.rb', line 50 def simplec_path_for(page_or_path, ={}) page = page_for(page_or_path, ) return unless page .delete(:raise) simplec.page_path .merge( path: page.path ) end |
#simplec_url_for(page_or_path, options = {}) ⇒ String?
Get the url of a page.
By default, if the Page cannot be located nil will be the result.
76 77 78 79 80 81 82 83 84 |
# File 'lib/simplec/action_controller/extensions.rb', line 76 def simplec_url_for(page_or_path, ={}) page = page_for(page_or_path, ) return unless page .delete(:raise) simplec.page_url .merge( subdomain: page.subdomain.try(:name), path: page.path ) end |
#subdomain(name = nil) ⇒ Object
Get the subdomain. TODO docs
12 13 14 15 16 17 |
# File 'lib/simplec/action_controller/extensions.rb', line 12 def subdomain(name=nil) name ||= request.subdomain @_subdomains ||= Hash.new return @_subdomains[name] if @_subdomains[name] @_subdomains[name] = Subdomain.find_by!(name: name) end |