Class: Aviary::Site

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Site

Returns a new instance of Site.



5
6
7
8
9
10
# File 'lib/aviary/site.rb', line 5

def initialize(config)
  @source    = config[:source]
  @dest      = config[:dest]
  @paginator = Paginator.new(config[:per_page] || 25)
  @template  = ERB.new(File.read(File.join(self.source, 'template.erb')))
end

Instance Attribute Details

#destObject (readonly)

Returns the value of attribute dest.



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

def dest
  @dest
end

#paginatorObject (readonly)

Returns the value of attribute paginator.



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

def paginator
  @paginator
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

#templateObject (readonly)

Returns the value of attribute template.



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

def template
  @template
end

Instance Method Details

#copy_assetsObject

Recursively copy the contents of the _assets directory into the root of the dest directory. Useful for sharing CSS, JavaScript or images between pages.

Returns nothing.



44
45
46
# File 'lib/aviary/site.rb', line 44

def copy_assets
  FileUtils.cp_r File.join(self.source, '_assets', '.'), self.dest
end

#copy_indexObject

Copies the first page and makes it the index at the root of the dest directory.

Returns nothing.



34
35
36
37
# File 'lib/aviary/site.rb', line 34

def copy_index
  FileUtils.cp File.join(self.dest, "page1", "index.htm"), 
               File.join(self.dest, "index.htm")
end

#current_page_pathObject



48
49
50
# File 'lib/aviary/site.rb', line 48

def current_page_path
  File.join(self.dest, "page#{self.paginator.current_page}")
end

#processObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/aviary/site.rb', line 12

def process
  render
  if self.paginator.next_page?
    self.paginator.next_page!
    process
  else
    copy_index
    copy_assets
  end
end

#renderObject



23
24
25
26
27
28
# File 'lib/aviary/site.rb', line 23

def render
  FileUtils.mkdir_p(current_page_path) unless File.exists?(current_page_path)
  File.open(File.join(current_page_path, "index.htm"), "w") do |file|
    file.write self.template.result(Page.new(self.paginator).binding)
  end
end