Module: Simplec::ActionController::Extensions
- Defined in:
- lib/simplec/action_controller/extensions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #page(path, options = {}) ⇒ Object
- #simplec_path(page_or_path, options = {}) ⇒ Object
- #simplec_url(page_or_path, options = {}) ⇒ Object
- #subdomain(name = nil) ⇒ Object
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, :simplec_url end |
Instance Method Details
#page(path, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simplec/action_controller/extensions.rb', line 17 def page(path, ={}) @_page ||= Hash.new return @_page[path] if @_page[path] _subdomain = subdomain _subdomain = Subdomain.find_by!( name: [:subdomain] ) if [:subdomain] @_page[path] = _subdomain.pages.find_by!(path: path) end |
#simplec_path(page_or_path, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/simplec/action_controller/extensions.rb', line 29 def simplec_path(page_or_path, ={}) # TODO cache page_paths _page = page_or_path.is_a?(Page) ? page_or_path : page(page_or_path, ) unless _page raise ActiveRecord::RecordNotFound if [:raise] return nil end _page.path end |
#simplec_url(page_or_path, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/simplec/action_controller/extensions.rb', line 42 def simplec_url(page_or_path, ={}) # TODO cache page_urls _page = page_or_path.is_a?(Page) ? page_or_path : page(page_or_path, ) unless _page raise ActiveRecord::RecordNotFound if [:raise] return nil end URI.join(root_url(subdomain: _page.subdomain.try(:name)), _page.path).to_s end |
#subdomain(name = nil) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/simplec/action_controller/extensions.rb', line 10 def subdomain(name=nil) name ||= request.subdomain @_subdomains ||= Hash.new return @_subdomains[name] if @_subdomains[name] @_subdomains[name] = Subdomain.find_by!(name: name) end |