Sha256: ac1826f7237f6d0c016c391c179c3dfab473197ccf239adfefb890724384eeea

Contents?: true

Size: 879 Bytes

Versions: 7

Compression:

Stored size: 879 Bytes

Contents

module Viewable
  class ViewPresenter < ViewablePresenter
    def initialize(model, context)
      super
      set_cms_view
      set_meta_tags
    end

    def add_link
      return unless h.cms_edit_mode?

      h.link_to add_path, class: "cms-add cms-add-page", 'data-no-turbolink' => true do
        h.t('cms.add_page')
      end
    end

    private

    def set_cms_view
      h.instance_variable_set :@cms_view, self
    end

    def set_meta_tags
      tags = %w[
        title
        meta_keywords
        meta_description
      ]
      tags.each do |tag|
        h.instance_variable_set("@cms_page_#{tag}", m.send(tag).presence)
      end
    end

    def add_path
      h.main_app.new_viewable_url(list_key: h.cms_list_key(short_type, m.unique_key_name), max: Float::INFINITY)
    end

    def short_type
      m.viewable_type.demodulize.underscore
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_admin_cms-0.1.1 app/presenters/viewable/view_presenter.rb
rails_admin_cms-0.0.9 app/presenters/viewable/view_presenter.rb
rails_admin_cms-0.0.7 app/presenters/viewable/view_presenter.rb
rails_admin_cms-0.0.6 app/presenters/viewable/view_presenter.rb
rails_admin_cms-0.0.5 app/presenters/viewable/view_presenter.rb
rails_admin_cms-0.0.4 app/presenters/viewable/view_presenter.rb
rails_admin_cms-0.0.3 app/presenters/viewable/view_presenter.rb