Class: Dimples::Site

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

Overview

A collection of pages, posts and templates that can generate a website.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Site

Returns a new instance of Site.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dimples/site.rb', line 16

def initialize(config = {})
  @config = Configuration.prepare(config)

  @paths = {}.tap do |paths|
    paths[:source] = File.expand_path(@config.source)
    paths[:destination] = File.expand_path(@config.destination)

    %w[pages posts static templates].each do |type|
      paths[type.to_sym] = File.join(paths[:source], type)
    end
  end

  prepare
end

Instance Attribute Details

#archiveObject (readonly)

Returns the value of attribute archive.



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

def archive
  @archive
end

#categoriesObject (readonly)

Returns the value of attribute categories.



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

def categories
  @categories
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#latest_postObject (readonly)

Returns the value of attribute latest_post.



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

def latest_post
  @latest_post
end

#pagesObject (readonly)

Returns the value of attribute pages.



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

def pages
  @pages
end

#pathsObject (readonly)

Returns the value of attribute paths.



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

def paths
  @paths
end

#postsObject (readonly)

Returns the value of attribute posts.



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

def posts
  @posts
end

#templatesObject (readonly)

Returns the value of attribute templates.



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

def templates
  @templates
end

Instance Method Details

#dataObject



49
50
51
# File 'lib/dimples/site.rb', line 49

def data
  @config.data || {}
end

#generateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dimples/site.rb', line 31

def generate
  prepare

  read_templates
  read_posts
  read_pages

  create_output_directory
  copy_static_assets

  publish_posts
  publish_pages
  publish_archives if @config.generation.year_archives
  publish_categories if @config.generation.categories
rescue PublishingError, RenderingError, GenerationError => e
  @errors << e
end

#inspectObject



53
54
55
# File 'lib/dimples/site.rb', line 53

def inspect
  "#<#{self.class} @paths=#{paths}>"
end