Sha256: 82070419671bcb6151c238c1ce2b78c2ffcdfbffb9ecbc2eda5f87c3d67832a5

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

module Freeberry
  module Controllers
    module HeadOptions
      # Inclusion hook to make #current_user and #logged_in?
      # available as ActionView helper methods.
      def self.included(base)
        base.send :helper_method, :head_options if base.respond_to? :helper_method
      end
      
      def head_options(record, options = {})
        return if record.nil?
        
        options = { :spliter => " | " }.merge(options)
        
        header = record.respond_to?(:header) ? record.header : nil
        
        @view_title = record.title if record.respond_to?(:title)
        @view_title ||= I18n.t('page.title')
        
        # title
        page_title = []
		    page_title << options[:title] if options.key?(:title)
		    page_title << ((header.nil? || header.title.blank?) ? record.title : header.title)
		    page_title << I18n.t('page.title') if options[:append_title]
		    page_title.flatten!
		    page_title.compact!
		    page_title.uniq!
		
		    @page_title = page_title.join(options[:spliter])
		
		    # keywords
		    keywords = record.keywords.join(', ') if record.respond_to?(:keywords)
		    keywords ||= (header.nil? || header.keywords.blank?) ? page_title.join(' ').split.join(', ') : header.keywords
		    @page_keywords = keywords
		
		    # description
		    description = (header.nil? || header.description.blank?) ? page_title.join(" - ") : header.description
		    @page_description = description
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
freeberry-0.3.0 lib/freeberry/controllers/head_options.rb
freeberry-0.2.9 lib/freeberry/controllers/head_options.rb
freeberry-0.2.7 lib/freeberry/controllers/head_options.rb