Class: Noumenon::Theme

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

Overview

Provides access to a theme and it’s contents.

Defined Under Namespace

Classes: AssetsMiddleware, Drop, NotFoundError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, description = {}) ⇒ Theme

Create a new theme instance.

Parameters:

  • path (String, #to_s)

    The path the theme was loaded from.

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

    Any metadata to attach to theme.

Options Hash (description):

  • :name (String)

    The human readable name of the theme.

  • :author (String)

    The author of the theme.

  • :email (String)

    The email address to content regarding this theme.

  • :copyright (String)

    The copyright line to attribute this theme to.

  • :license (String)

    The license this theme is distributed under.



78
79
80
81
82
83
84
85
86
# File 'lib/noumenon/theme.rb', line 78

def initialize(path, description = {})
  @path = path
  
  description.each do |name, value|
    if respond_to? "#{name}="
      send "#{name}=", value
    end
  end
end

Instance Attribute Details

#authorObject

The author of this theme. Loaded from theme.yml.



54
55
56
# File 'lib/noumenon/theme.rb', line 54

def author
  @author
end

The copyright line to attribute this theme to. Loaded from theme.yml.



62
63
64
# File 'lib/noumenon/theme.rb', line 62

def copyright
  @copyright
end

#emailObject

The email address to contact regarding this theme. Loaded from theme.yml.



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

def email
  @email
end

#licenseObject

The license this theme is distributed under. Loaded from theme.yml.



66
67
68
# File 'lib/noumenon/theme.rb', line 66

def license
  @license
end

#nameObject

The name to refer to this theme by. Loaded from theme.yml.



50
51
52
# File 'lib/noumenon/theme.rb', line 50

def name
  @name
end

#pathObject (readonly)

The path the theme was loaded from.



46
47
48
# File 'lib/noumenon/theme.rb', line 46

def path
  @path
end

Class Method Details

.load(path) ⇒ Noumenon::Theme

Load a theme from the specified path. Metadata about the theme will be laoded from “theme.yml”, which should have the format shown in the example.

If the theme is loaded succesfully it will also be registered in the theme list.

Parameters:

  • path (String, #to_s)

    The path to load from.

Returns:

Raises:

See Also:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/noumenon/theme.rb', line 26

def self.load(path)
  unless File.exist?("#{path}/theme.yml")
    raise NotFoundError.new("No theme was found at #{path}. Did you create a theme.yml file?")
  end
  
  description = YAML.load(File.read("#{path}/theme.yml"))
  theme = Noumenon::Theme.new(path, description)

  themes[theme.name] = theme
  theme
end

.themesHash

Returns A hash containing any loaded themes, keyed by their name.

Returns:

  • (Hash)

    A hash containing any loaded themes, keyed by their name.



40
41
42
# File 'lib/noumenon/theme.rb', line 40

def self.themes
  @themes ||= {}
end

Instance Method Details

#layout(name) ⇒ Noumenon::Template

Load a template from the theme’s layouts directory.

Parameters:

  • name (String, #to_s)

    The path to load the template from. This path will be prefixed with “layouts/”

Returns:

Raises:



104
105
106
# File 'lib/noumenon/theme.rb', line 104

def layout(name)
  Noumenon::Template.from_file File.join(path, "layouts", name)
end

#template(name) ⇒ Noumenon::Template

Load a template from the theme’s templates directory.

Parameters:

  • name (String, #to_s)

    The path to load the template from. This path will be prefixed with “templates/”

Returns:

Raises:



94
95
96
# File 'lib/noumenon/theme.rb', line 94

def template(name)
  Noumenon::Template.from_file File.join(path, "templates", name)
end

#to_liquidObject



115
116
117
# File 'lib/noumenon/theme.rb', line 115

def to_liquid
  { name: name, author: author, email: email, copyright: copyright, license: license }
end