Module: PagesHelper

Defined in:
app/helpers/pages_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_pageObject



3
4
5
# File 'app/helpers/pages_helper.rb', line 3

def current_page
  @current_page
end

#current_page_resourceObject



44
45
46
47
48
# File 'app/helpers/pages_helper.rb', line 44

def current_page_resource()
  if current_page && current_page.resourceful?
    controller.instance_variable_get("@#{current_page.resource_type}")        
  end
end

#home?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/helpers/pages_helper.rb', line 50

def home?
  request.path == "/"
end

#page_path_for(resource_or_page) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/pages_helper.rb', line 26

def page_path_for(resource_or_page)
  page = resource_or_page.is_a?(Page) ? resource_or_page : page_by_resource(resource_or_page)
  path = page.try(:path)
  if path.blank?      
    "#not-found"
  else
    path.gsub(/:[A-z_]+/) do |seg|
      meth = seg.gsub(/^:/, "")
      resource_or_page.send(meth)
    end
  end

end

#page_url_for(resource_or_page) ⇒ Object



40
41
42
# File 'app/helpers/pages_helper.rb', line 40

def page_url_for(resource_or_page)
  "#{request.protocol}#{request.host_with_port}#{page_path_for(resource_or_page)}"
end

#part(name, opts = {}, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/pages_helper.rb', line 7

def part(name, opts = {}, &block)
  if @current_page
    schema = opts.delete(:schema) || PagePart
    
    klass = schema.is_a?(Class)  ? schema : "#{schema.to_s.camelize}PagePart".constantize  
    p = klass.where(:name => "#{name}", :page_id => @current_page.id).first
    p ||= klass.create!(:name => "#{name}", :page_id =>  @current_page.id)
          
    if block_given?
      capture do
        block.call(p)
      end
    else
      p
    end
    
  end
end