Module: ShinyThemes::RendersTheme

Extended by:
ActiveSupport::Concern
Defined in:
lib/shiny_themes/renders_theme.rb

Overview

RendersTheme concern Included into ActionController::Base providing a theme class variable for controllers. This theme defines a view path for templates and a layout to render with.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#current_theme_layout ⇒ String

Returns the current theme default layout.

Returns:

  • (String) —

    the current theme default layout



24
25
26
# File 'lib/shiny_themes/renders_theme.rb', line 24

def current_theme_layout
  self.class.theme.layout
end

#current_theme_name ⇒ String

Returns the current theme name.

Returns:

  • (String) —

    the current theme name



19
20
21
# File 'lib/shiny_themes/renders_theme.rb', line 19

def current_theme_name
  self.class.theme.name
end

#update_current_theme(name, options = {}) ⇒ Theme

Update the current theme for the controller and optionally save

Parameters:

  • name (String) —

    The name of the new theme

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

    Options hash

Options Hash (options):

  • :layout (String) — default: 'application' —

    Default layout for theme

  • :dont_save (Boolean) — default: false —

    Dont save the update to the theme.yml config

Returns:

  • (Theme) —

    the theme for the controller



34
35
36
37
38
39
40
# File 'lib/shiny_themes/renders_theme.rb', line 34

def update_current_theme(name, options = {})
  self.class.renders_theme(name, options)
  Rails.application.config.theme.name = current_theme_name
  Rails.application.config.theme.layout = current_theme_layout
  ShinyThemes::Engine.theme_config.save unless options[:dont_save]
  self.class.theme # return current theme object
end