Module: Optimacms::Mycontroller

Extended by:
ActiveSupport::Concern
Included in:
PagesController
Defined in:
lib/optimacms/mycontroller.rb

Instance Method Summary collapse

Instance Method Details

#default_render(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/optimacms/mycontroller.rb', line 15

def default_render(*args)
  if self.controller_name!='pages' && !@optimacms_tpl.nil? && @is_optimacms
    render @optimacms_tpl, :layout=>@optimacms_layout and return
    #(render :text => "hello", :layout => @optimacms_layout) and return

    # http://stackoverflow.com/questions/21129587/ruby-on-rails-how-to-render-file-as-plain-text-without-any-html
    #render :plain will set the content type to text/plain
    #render :html will set the content type to text/html
    #render :body will not set the content type header.
    # render text: "some text". :plain does not work.
  end

  super
end

#get_page_path(page_name, p = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/optimacms/mycontroller.rb', line 45

def get_page_path(page_name, p={})
  # get from cache
  @cache_page_urls ||= {}
  url = @cache_page_urls.fetch(page_name.to_s, nil)

  if url.nil?
    page = Page.find_by_name(page_name)
    url = page.url if page
  end

  return nil if url.nil?

  # set to cache
  @cache_page_urls ||= {}
  @cache_page_urls[page_name.to_s] = url

  #
  res = PageServices::PageRouteService.make_url url, p

  '/'+res
end

#my_set_meta(meta) ⇒ Object



35
36
37
38
39
# File 'lib/optimacms/mycontroller.rb', line 35

def my_set_meta(meta)
  @optimacms_meta_title = meta[:title]
  @optimacms_meta_keywords = meta[:keywords]
  @optimacms_meta_description = meta[:description]
end

#my_set_render ⇒ Object



10
11
12
13
# File 'lib/optimacms/mycontroller.rb', line 10

def my_set_render
  @is_optimacms = true

end

#my_set_render_template(tpl_view, tpl_layout) ⇒ Object



30
31
32
33
# File 'lib/optimacms/mycontroller.rb', line 30

def my_set_render_template(tpl_view, tpl_layout)
  @optimacms_tpl = tpl_view
  @optimacms_layout = tpl_layout
end

#site_page_path(name, p = {}) ⇒ Object



41
42
43
# File 'lib/optimacms/mycontroller.rb', line 41

def site_page_path(name, p={})
  get_page_path(name, p)
end