Class: Dimples::Site

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Site

Returns a new instance of Site.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dimples/site.rb', line 15

def initialize(config)
  @source_paths = {}
  @output_paths = {}
  @templates = {}
  @categories = {}
  @archives = { year: {}, month: {}, day: {} }

  @pages = []
  @posts = []

  @latest_post = false

  @config = config

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

  @source_paths[:root] = File.expand_path(@config['source_path'])
  @output_paths[:site] = File.expand_path(@config['destination_path'])

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

  %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

Instance Attribute Details

#archivesObject

Returns the value of attribute archives.



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

def archives
  @archives
end

#categoriesObject

Returns the value of attribute categories.



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

def categories
  @categories
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#latest_postObject

Returns the value of attribute latest_post.



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

def latest_post
  @latest_post
end

#output_pathsObject

Returns the value of attribute output_paths.



4
5
6
# File 'lib/dimples/site.rb', line 4

def output_paths
  @output_paths
end

#page_classObject

Returns the value of attribute page_class.



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

def page_class
  @page_class
end

#pagesObject

Returns the value of attribute pages.



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

def pages
  @pages
end

#post_classObject

Returns the value of attribute post_class.



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

def post_class
  @post_class
end

#postsObject

Returns the value of attribute posts.



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

def posts
  @posts
end

#source_pathsObject

Returns the value of attribute source_paths.



3
4
5
# File 'lib/dimples/site.rb', line 3

def source_paths
  @source_paths
end

#templatesObject

Returns the value of attribute templates.



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

def templates
  @templates
end

Instance Method Details

#generateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dimples/site.rb', line 45

def generate
  Dimples.logger.info("Building site at #{@output_paths[:site]}...")

  result = Benchmark.measure do
    prepare_output_directory
    scan_files
    generate_files
    copy_assets
  end

  generation_time = result.real.round(2)

  message = "Done! Site built in #{generation_time} second"
  message += 's' if generation_time != 1
  message += '.'

  Dimples.logger.info(message)
rescue Errors::RenderingError => e
  Dimples.logger.error("Failed to render #{e.file}: #{e.message}")
rescue Errors::PublishingError => e
  Dimples.logger.error("Failed to publish #{e.file}: #{e.message}")
end