Class: Dimples::Site

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

Overview

A class that models a single site.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Site



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dimples/site.rb', line 19

def initialize(config)
  @config = config

  @templates = {}
  @categories = {}
  @pages = []
  @posts = []
  @errors = []

  @archives = { year: {}, month: {}, day: {} }
  @latest_post = false

  @page_class = @config.class_override(:page) || Dimples::Page
  @post_class = @config.class_override(:post) || Dimples::Post

  set_source_paths
  set_output_paths
end

Instance Attribute Details

#archivesObject

Returns the value of attribute archives.



11
12
13
# File 'lib/dimples/site.rb', line 11

def archives
  @archives
end

#categoriesObject

Returns the value of attribute categories.



10
11
12
# File 'lib/dimples/site.rb', line 10

def categories
  @categories
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#errorsObject

Returns the value of attribute errors.



17
18
19
# File 'lib/dimples/site.rb', line 17

def errors
  @errors
end

#latest_postObject

Returns the value of attribute latest_post.



14
15
16
# File 'lib/dimples/site.rb', line 14

def latest_post
  @latest_post
end

#output_pathsObject

Returns the value of attribute output_paths.



7
8
9
# File 'lib/dimples/site.rb', line 7

def output_paths
  @output_paths
end

#page_classObject

Returns the value of attribute page_class.



15
16
17
# File 'lib/dimples/site.rb', line 15

def page_class
  @page_class
end

#pagesObject

Returns the value of attribute pages.



12
13
14
# File 'lib/dimples/site.rb', line 12

def pages
  @pages
end

#post_classObject

Returns the value of attribute post_class.



16
17
18
# File 'lib/dimples/site.rb', line 16

def post_class
  @post_class
end

#postsObject

Returns the value of attribute posts.



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

def posts
  @posts
end

#source_pathsObject

Returns the value of attribute source_paths.



6
7
8
# File 'lib/dimples/site.rb', line 6

def source_paths
  @source_paths
end

#templatesObject

Returns the value of attribute templates.



9
10
11
# File 'lib/dimples/site.rb', line 9

def templates
  @templates
end

Instance Method Details

#generateObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/dimples/site.rb', line 59

def generate
  prepare_output_directory
  scan_files
  generate_files
  copy_assets
rescue Errors::RenderingError,
       Errors::PublishingError,
       Errors::GenerationError => e
  @errors << e.message
end

#generated?Boolean



70
71
72
# File 'lib/dimples/site.rb', line 70

def generated?
  @errors.count.zero?
end

#set_output_pathsObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/dimples/site.rb', line 48

def set_output_paths
  @output_paths = {
    site: File.expand_path(@config['destination_path'])
  }

  %w[archives posts categories].each do |path|
    output_path = File.join(@output_paths[:site], @config['paths'][path])
    @output_paths[path.to_sym] = output_path
  end
end

#set_source_pathsObject



38
39
40
41
42
43
44
45
46
# File 'lib/dimples/site.rb', line 38

def set_source_paths
  @source_paths = {
    root: File.expand_path(@config['source_path'])
  }

  %w[pages posts public templates].each do |path|
    @source_paths[path.to_sym] = File.join(@source_paths[:root], path)
  end
end