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



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

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

#home?Boolean

Returns:

  • (Boolean)


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

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

#page_path_for(resource_or_page) ⇒ Object



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

def page_path_for(resource_or_page)
  page = resource_or_page.is_a?(Page) ? resource_or_page : Page.find_by_resource_type(resource_or_page.class.name.underscore)
  path = page.try(:path)
  if path.blank?
    Rails.logger.info "#{resource_or_page} non trovato"
    Rails.logger.info "PAGINA: #{page}"
    Rails.logger.info "Path: #{page.path}"
    
    "#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



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

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
# 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.find_or_create_by_name_and_page_id("#{name}", @current_page)
    
    if block_given?
      block.call(p)
    else
      p
    end
    
  end
end