Class: Semistatic::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/semistatic/configuration.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



7
8
9
10
11
# File 'lib/semistatic/configuration.rb', line 7

def initialize
  @templates_path = Rails.root. + 'app/views/layout'
  @config_files = [(Rails.root. + 'config/semistatic.yml')]
  @config = HashWithIndifferentAccess.new({pages: {}})
end

Instance Method Details

#config_filesObject

get the config files

Returns:

  • Array # the filepaths in a array



33
34
35
# File 'lib/semistatic/configuration.rb', line 33

def config_files
  @config_files
end

#config_files=(files) ⇒ Object

set the config files

Parameters:

  • Array (Pathname)

    files # the filepaths in a array



27
28
29
# File 'lib/semistatic/configuration.rb', line 27

def config_files=(files)
  @config_files = files
end

#loadObject

load config from files



38
39
40
41
42
43
# File 'lib/semistatic/configuration.rb', line 38

def load
  config_files.each do |file|
    config = YAML::load(File.open(file))
    @config.merge! config
  end
end

#page(key) ⇒ Object

Returns hash.

Parameters:

  • Symbol

    key

Returns:

  • hash

Raises:



52
53
54
55
56
# File 'lib/semistatic/configuration.rb', line 52

def page(key)
  page = pages[key]
  raise Error.new("There is no page named '#{key}'") unless page
  page
end

#pagesObject

Returns Hash.

Returns:

  • Hash



46
47
48
# File 'lib/semistatic/configuration.rb', line 46

def pages
  @config[:pages]
end

#templates_pathObject

get the template path

Returns:

  • Pathname



21
22
23
# File 'lib/semistatic/configuration.rb', line 21

def templates_path
  @templates_path
end

#templates_path=(path) ⇒ Object

set the template path

Parameters:

  • Pathname

    path



15
16
17
# File 'lib/semistatic/configuration.rb', line 15

def templates_path=(path)
  @templates_path = path
end