Module: Wallaby::View::Themeable::ClassMethods

Defined in:
lib/wallaby/view/themeable.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#themeHash (readonly)

Returns theme metadata.

Examples:

Once theme is set, the metadata will be set as well:

class Admin::ApplicationController < ApplicationController
  self.theme_name = 'secure'

  self.theme

  # =>
  # {
  #   theme_name: 'secure',
  #   theme_path: 'admin/application'
  # }
end

Returns:

  • (Hash)

    theme metadata



71
72
73
74
75
76
# File 'lib/wallaby/view/themeable.rb', line 71

def theme
  defined?(@theme_name) && @theme_name && {
    theme_name: @theme_name,
    theme_path: @theme_path
  } || superclass.try(:theme)
end

#theme_nameString? (readonly)

Returns theme name.

Returns:

  • (String, nil)

    theme name



53
54
55
# File 'lib/wallaby/view/themeable.rb', line 53

def theme_name
  defined?(@theme_name) && @theme_name || superclass.try(:theme_name)
end

#themesArray<Hash> (readonly)

Returns a list of #theme metadata.

Returns:

  • (Array<Hash>)

    a list of #theme metadata



80
81
82
83
84
# File 'lib/wallaby/view/themeable.rb', line 80

def themes
  list = superclass.try(:themes) || []
  list.prepend theme if defined?(@theme_name) && @theme_name
  list.compact
end

Instance Method Details

#theme_name=(theme_name, **options, &block) ⇒ Object (readonly)

The theme name is used to specify the layout and prefixes so that a set of theme implementation for the frontend (html/css/javascript) can be applied

When theme name is set to e.g. ‘custom_theme`, the following changes will be made:

  • layout will be set to the same name ‘custom_theme`

  • theme name will be added to the lookup prefixes right after the controller path of where it’s defined.

Once theme name is set, all its subclass controllers will inherit the same theme name

Examples:

To set an theme name:

class Admin::ApplicationController < ApplicationController
  self.theme_name = 'secure'

  def index
    _prefixes

    # =>
    # [
    #   'admin/application/index',
    #   'admin/application',
    #   'secure/index',
    #   'secure',
    #   'application/index',
    #   'application'
    # ]
  end
end

Parameters:

  • theme_name (String)
  • options (Hash)

    same options as Rails’ layout method



45
46
47
48
49
# File 'lib/wallaby/view/themeable.rb', line 45

def theme_name=(theme_name, **options, &block)
  layout theme_name, options, &block
  @theme_path = theme_name && controller_path || nil
  @theme_name = theme_name || nil
end