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.



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
44
45
46
# File 'lib/dimples/site.rb', line 16

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'])

  @errors = []

  %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

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
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



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

def generate
  prepare_output_directory
  scan_files
  generate_files
  copy_assets
rescue Errors::RenderingError, Errors::PublishingError, Errors::GenerationError => e
  @errors << "Failed to generate the site: #{e.message}."
end

#generated?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/dimples/site.rb', line 57

def generated?
  @errors.count == 0
end