Sha256: b711c668da5978c4f25dcdf9079538e53008a421fb4d8d21baa7335f8dedc702

Contents?: true

Size: 1.96 KB

Versions: 12

Compression:

Stored size: 1.96 KB

Contents

module Optimacms
  module Mycontroller
    extend ActiveSupport::Concern


    included do
      helper_method :site_page_path
    end

    def my_set_render
      @is_optimacms = true

    end

    def is_optimacms
      @is_optimacms
    end

    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

    def optimacms_pagedata
      @pagedata
    end

    def optimacms_set_pagedata(_pagedata)
      @pagedata = _pagedata

    end

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

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

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

    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

      return nil if res.nil?

      '/'+res
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
optimacms-0.2.26 lib/optimacms/mycontroller.rb
optimacms-0.2.25 lib/optimacms/mycontroller.rb
optimacms-0.2.24 lib/optimacms/mycontroller.rb
optimacms-0.2.21 lib/optimacms/mycontroller.rb
optimacms-0.2.20 lib/optimacms/mycontroller.rb
optimacms-0.2.16 lib/optimacms/mycontroller.rb
optimacms-0.2.15 lib/optimacms/mycontroller.rb
optimacms-0.2.14 lib/optimacms/mycontroller.rb
optimacms-0.2.13 lib/optimacms/mycontroller.rb
optimacms-0.2.12 lib/optimacms/mycontroller.rb
optimacms-0.2.11 lib/optimacms/mycontroller.rb
optimacms-0.2.9 lib/optimacms/mycontroller.rb