Sha256: 8e28bf02ea8054e3349858a9040661d60be4e0376aad66f381dad97d9f039040

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Phlexible
  #
  # Helper to assist in defining page titles within Phlex views. Also includes support for nested
  # views, where each desendent view class will have its title prepended to the page title. Simply
  # include the module and assign the title to the `page_title` class variable:
  #
  #   class MyView
  #     include Phlexible::PageTitle
  #     self.page_title = 'My Title'
  #   end
  #
  # Then call the `page_title` method in the <head> of your page.
  #
  module PageTitle
    def self.included(base)
      base.class_eval do
        self.class.attr_accessor :page_title
      end
    end

    private

    def page_title
      title = []

      klass = self.class
      while klass.respond_to?(:page_title)
        title << if klass.page_title.is_a?(Proc)
                   instance_exec(&klass.page_title)
                 else
                   klass.page_title
                 end

        klass = klass.superclass
      end

      title.compact.join(' - ')
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
phlexible-2.0.0 lib/phlexible/page_title.rb
phlexible-1.0.0 lib/phlexible/page_title.rb
phlexible-1.0.0.beta.1 lib/phlexible/page_title.rb
phlexible-0.7.0 lib/phlexible/page_title.rb
phlexible-0.6.2 lib/phlexible/page_title.rb
phlexible-0.6.1 lib/phlexible/page_title.rb
phlexible-0.6.0 lib/phlexible/page_title.rb
phlexible-0.5.0 lib/phlexible/page_title.rb
phlexible-0.4.2 lib/phlexible/page_title.rb
phlexible-0.4.1 lib/phlexible/page_title.rb
phlexible-0.4.0 lib/phlexible/page_title.rb
phlexible-0.3.0 lib/phlexible/page_title.rb