Module: Simplec::ActionController::Extensions

Defined in:
lib/simplec/action_controller/extensions.rb

Instance Method Summary collapse

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, options={})
  @_page ||= Hash.new
  return @_page[path] if @_page[path]

  _subdomain = subdomain
  _subdomain = Subdomain.find_by!(
    name: options[:subdomain]
  ) if options[: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, options={})
  # TODO cache page_paths
  _page = page_or_path.is_a?(Page) ?
    page_or_path : page(page_or_path, options)

  unless _page
    raise ActiveRecord::RecordNotFound if options[: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, options={})
  # TODO cache page_urls
  _page = page_or_path.is_a?(Page) ?
    page_or_path : page(page_or_path, options)

  unless _page
    raise ActiveRecord::RecordNotFound if options[: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