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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/optimacms/mycontroller.rb', line 21

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/optimacms/mycontroller.rb', line 60

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.w_page.where(name: page_name).first
    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

  return nil if res.nil?

  '/'+res
end

#is_optimacmsObject



17
18
19
# File 'lib/optimacms/mycontroller.rb', line 17

def is_optimacms
  @is_optimacms
end

#my_set_meta(meta) ⇒ Object



50
51
52
53
54
# File 'lib/optimacms/mycontroller.rb', line 50

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

#my_set_renderObject



12
13
14
15
# File 'lib/optimacms/mycontroller.rb', line 12

def my_set_render
  @is_optimacms = true

end

#my_set_render_template(tpl_view, tpl_layout) ⇒ Object



45
46
47
48
# File 'lib/optimacms/mycontroller.rb', line 45

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

#optimacms_pagedataObject



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

def optimacms_pagedata
  @pagedata
end

#optimacms_set_pagedata(_pagedata) ⇒ Object



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

def optimacms_set_pagedata(_pagedata)
  @pagedata = _pagedata

end

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



56
57
58
# File 'lib/optimacms/mycontroller.rb', line 56

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