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.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dimples/config.rb', line 26

def initialize(options = {})
  options = Config.defaults.to_h do |key, value|
    unless options[key].nil?
      value = case options[key]
              when Hash
                value.merge!(options[key])
              else
                options[key]
              end
    end

    [key, value]
  end

  @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.



13
14
15
# File 'lib/dimples/config.rb', line 13

def build_paths
  @build_paths
end

#generationObject

Returns the value of attribute generation.



13
14
15
# File 'lib/dimples/config.rb', line 13

def generation
  @generation
end

#paginationObject

Returns the value of attribute pagination.



13
14
15
# File 'lib/dimples/config.rb', line 13

def pagination
  @pagination
end

#siteObject

Returns the value of attribute site.



13
14
15
# File 'lib/dimples/config.rb', line 13

def site
  @site
end

#source_pathsObject

Returns the value of attribute source_paths.



13
14
15
# File 'lib/dimples/config.rb', line 13

def source_paths
  @source_paths
end

Class Method Details

.defaultsObject



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

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: { main_feed: true, category_feeds: false }
  }
end

Instance Method Details

#expand_paths(root, paths) ⇒ Object



48
49
50
51
52
53
# File 'lib/dimples/config.rb', line 48

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