Class: Archangel::Theme::ThemableController

Inherits:
Object
  • Object
show all
Defined in:
lib/archangel/theme/themable_controller.rb

Overview

Apply Archangel theme to page

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, theme) ⇒ ThemableController

Theme initializer

Parameters:

  • controller (Object)

    the controller

  • theme (String)

    the theme


66
67
68
69
# File 'lib/archangel/theme/themable_controller.rb', line 66

def initialize(controller, theme)
  @controller = controller
  @theme_name = theme_name_identifier(theme)
end

Instance Attribute Details

#theme_nameObject (readonly)

Theme name


15
16
17
# File 'lib/archangel/theme/themable_controller.rb', line 15

def theme_name
  @theme_name
end

Class Method Details

.apply_theme(controller_class, theme, options = {}) ⇒ Object

Apply theme

Parameters:

  • controller_class (Class)

    the controller

  • theme (String)

    the theme

  • options (Hash) (defaults to: {})

    the theme options


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/archangel/theme/themable_controller.rb', line 25

def apply_theme(controller_class, theme, options = {})
  filter_method = before_filter_method(options)
  options = options.slice(:only, :except)

  controller_class.class_eval do
    define_method :layout_from_theme do
      theme_instance.theme_name
    end
    alias_method :current_theme, :layout_from_theme

    define_method :theme_instance do
      @theme_instance ||=
        Archangel::Theme::ThemableController.new(self, theme)
    end

    private :layout_from_theme,
            :theme_instance

    layout :layout_from_theme, options

    helper_method :current_theme
  end

  controller_class.send(filter_method, options) do |controller|
    controller.prepend_view_path theme_instance.theme_view_path
  end
end

Instance Method Details

#theme_view_pathString

Archangel theme path

Returns:

  • (String)

    the path to the theme


76
77
78
79
80
81
# File 'lib/archangel/theme/themable_controller.rb', line 76

def theme_view_path
  path = Rails.root
  path = Archangel::Engine.root if @theme_name == Archangel::THEME_DEFAULT

  "#{path}/app/themes/#{@theme_name}/views"
end