Class: Dimples::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/dimples/config.rb

Overview

Configuration settings for a site.

Constant Summary collapse

SOURCE_PATHS =
{ pages: 'pages', posts: 'posts', layouts: 'layouts', static: 'static' }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



18
19
20
21
22
23
24
# File 'lib/dimples/config.rb', line 18

def initialize(options = {})
  options = Config.defaults.merge(options)

  @source_paths = expand_paths(File.expand_path(Dir.pwd), SOURCE_PATHS.dup)
  @build_paths = expand_paths(File.expand_path(options[:build]), options[:pathnames])
  @pagination = options[:pagination]
end

Instance Attribute Details

#build_pathsObject

Returns the value of attribute build_paths.



8
9
10
# File 'lib/dimples/config.rb', line 8

def build_paths
  @build_paths
end

#paginationObject

Returns the value of attribute pagination.



8
9
10
# File 'lib/dimples/config.rb', line 8

def pagination
  @pagination
end

#source_pathsObject

Returns the value of attribute source_paths.



8
9
10
# File 'lib/dimples/config.rb', line 8

def source_paths
  @source_paths
end

Class Method Details

.defaultsObject



10
11
12
13
14
15
16
# File 'lib/dimples/config.rb', line 10

def self.defaults
  {
    build: './site',
    pathnames: { posts: 'posts', categories: 'categories' },
    pagination: { page_prefix: 'page_', per_page: 5 }
  }
end

Instance Method Details

#expand_paths(root, paths) ⇒ Object



26
27
28
29
30
31
# File 'lib/dimples/config.rb', line 26

def expand_paths(root, paths)
  root = File.expand_path(root)

  paths.transform_values! { |value| File.expand_path(File.join(root, value)) }
  paths.tap { |expanded_paths| expanded_paths[:root] = root }
end