Sha256: 52ef347eaa69d375ca82d1473c34a3c6ecafcf27cfd44a8b939486687709352a

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

class AbstractController::Base
  attr_accessor :current_theme
  attr_accessor :force_liquid_template

  # Use this in your controller just like the <tt>layout</tt> macro.
  # Example:
  #
  #  theme 'theme_name'
  #
  # -or-
  #
  #  theme :get_theme
  #
  #  def get_theme
  #    'theme_name'
  #  end

  def self.theme(theme_name, conditions = {})
    # TODO: Allow conditions... (?)
    write_inheritable_attribute "theme", theme_name
  end

  # Retrieves the current set theme
  def current_theme(passed_theme=nil)
    theme = passed_theme || self.class.read_inheritable_attribute("theme")

    @active_theme = case theme
      when Symbol then send(theme)
      when Proc   then theme.call(self)
      when String then theme
    end
  end
end

module AbstractController
  module Rendering
    alias_method :theme_support_render, :render

    def render(*args, &block)
      theme = current_theme
      if theme
        theme = ActionView::Base.process_view_paths(File.join("themes", theme, "views"))
        prepend_view_path(theme)
      end

      theme_support_render(*args, &block)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
theme_support-3.0.6 lib/theme_support/patches/abstractcontroller_ex.rb
theme_support-3.0.5 lib/theme_support/patches/abstractcontroller_ex.rb
theme_support-3.0.4 lib/theme_support/patches/abstractcontroller_ex.rb