Class: Dimples::Site

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

Constant Summary collapse

DEFAULT_CONFIG =
{ overwrite_directory: false }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path, output_path, config) ⇒ Site

Returns a new instance of Site.



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

def initialize(source_path, output_path, config)
  @paths = {
    source: File.expand_path(source_path || Dir.pwd),
    destination: File.expand_path(output_path || File.join(Dir.pwd, "site"))
  }

  @config = DEFAULT_CONFIG
  @config.merge!(config) if config&.is_a?(Hash)

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

  scan_posts
  scan_pages
  scan_templates
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



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

def categories
  @categories
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#pagesObject

Returns the value of attribute pages.



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

def pages
  @pages
end

#postsObject

Returns the value of attribute posts.



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

def posts
  @posts
end

Class Method Details

.generate(source_path, output_path, config) ⇒ Object



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

def self.generate(source_path, output_path, config)
  new(source_path, output_path, config).generate
end

Instance Method Details

#generateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dimples/site.rb', line 37

def generate
  if Dir.exist?(@paths[:destination])
    unless @config[:overwrite_directory]
      raise GenerationError.new("The build directory (#{@paths[:destination]}) already exists.")
    end

    FileUtils.rm_rf(@paths[:destination])
  end

  Dir.mkdir(@paths[:destination])

  generate_posts
  generate_pages
  generate_categories

  copy_assets
end