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.



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

def initialize(config = {})
  @config = Hashie::Mash.new(Configuration.defaults).deep_merge(config)

  @paths = {}.tap do |paths|
    paths[:base] = Dir.pwd
    paths[:output] = File.expand_path(@config.paths.output)

    paths[:sources] = {}.tap do |sources|
      %w[pages posts static templates].each do |type|
        sources[type.to_sym] = File.join(paths[:base], type)
      end
    end
  end

  prepare
end

Instance Attribute Details

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



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

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.



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

def templates
  @templates
end

Instance Method Details

#generateObject



32
33
34
35
36
37
38
39
40
# File 'lib/dimples/site.rb', line 32

def generate
  prepare
  scan_sources
  create_output_directory
  copy_static_assets
  publish_files
rescue PublishingError, RenderingError, GenerationError => error
  @errors << error
end

#inspectObject



63
64
65
# File 'lib/dimples/site.rb', line 63

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

#publish_filesObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/dimples/site.rb', line 52

def publish_files
  trigger_event(:before_publishing)

  publish_posts
  publish_pages
  publish_archives
  publish_categories if @config.generation.categories

  trigger_event(:after_publishing)
end

#scan_sourcesObject



42
43
44
45
46
47
48
49
50
# File 'lib/dimples/site.rb', line 42

def scan_sources
  trigger_event(:before_file_scanning)

  read_templates
  read_posts
  read_pages

  trigger_event(:after_file_scanning)
end