Class: ShinyThemes::Theme

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/shiny_themes/theme.rb

Overview

Theme model class which is meant to be associated with one or more controllers. This theme "contains" assets (css, js, etc) as well as any views the them overrides and/or defines.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Theme

Returns a new instance of Theme.

Parameters:

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

    initialization options

Options Hash (options):

  • :name (String) — default: Rails.application.config.theme.name —

    The 1 name of the theme.

  • :layout (String) — default: Rails.application.config.theme.layout || 'application' —

    The name of the default layout.

  • : (String) —

    :theme_path (Rails.application.config.theme.path) The path to the theme's parent directory.



41
42
43
44
45
# File 'lib/shiny_themes/theme.rb', line 41

def initialize(options = {})
  @name = options[:name] || Rails.application.config.theme.name
  @layout = options[:layout] || Rails.application.config.theme.layout || 'application'
  @theme_path = options[:theme_path] || Rails.application.config.theme.path
end

Instance Attribute Details

#layout ⇒ String

Returns ] the name of the default layout to use. Defaults to config.theme.layout or 'application' if this does not exist.

Returns:

  • (String) —

    ] the name of the default layout to use. Defaults to config.theme.layout or 'application' if this does not exist



12
13
14
# File 'lib/shiny_themes/theme.rb', line 12

def layout
  @layout
end

#name ⇒ String (readonly)

Returns the name of the theme which must match the root directory name where theme files are located. Defaults to config.theme.name value.

Returns:

  • (String) —

    the name of the theme which must match the root directory name where theme files are located. Defaults to config.theme.name value



9
10
11
# File 'lib/shiny_themes/theme.rb', line 9

def name
  @name
end

Instance Method Details

#asset_path ⇒ Pathname

Returns Path to the theme's assets directory.

Returns:

  • (Pathname) —

    Path to the theme's assets directory



58
59
60
# File 'lib/shiny_themes/theme.rb', line 58

def asset_path
  path.join('assets')
end

#path ⇒ Pathname

Returns Path to the theme's root directory.

Returns:

  • (Pathname) —

    Path to the theme's root directory



48
49
50
# File 'lib/shiny_themes/theme.rb', line 48

def path
  Rails.root.join(@theme_path, @name)
end

#views_path ⇒ Pathname

Returns Path to the theme's view directory.

Returns:

  • (Pathname) —

    Path to the theme's view directory



53
54
55
# File 'lib/shiny_themes/theme.rb', line 53

def views_path
  path.join('views')
end