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.



21
22
23
24
25
26
27
28
29
# File 'lib/dimples/config.rb', line 21

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

  @source_paths = expand_paths(File.expand_path(options[:source]), SOURCE_PATHS.dup)
  @build_paths = expand_paths(File.expand_path(options[:build]), options[:pathnames])
  @site = options[:site]
  @pagination = options[:pagination]
  @generation = options[:generation]
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

#generationObject

Returns the value of attribute generation.



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

def generation
  @generation
end

#paginationObject

Returns the value of attribute pagination.



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

def pagination
  @pagination
end

#siteObject

Returns the value of attribute site.



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

def site
  @site
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
17
18
19
# File 'lib/dimples/config.rb', line 10

def self.defaults
  {
    source: Dir.pwd,
    build: './site',
    pathnames: { posts: 'posts', categories: 'categories' },
    site: { name: nil, domain: nil },
    pagination: { page_prefix: 'page_', per_page: 5 },
    generation: { api: false, main_feed: true, category_feeds: false }
  }
end

Instance Method Details

#expand_paths(root, paths) ⇒ Object



31
32
33
34
35
36
# File 'lib/dimples/config.rb', line 31

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