Class: Aviary::Site
- Inherits:
-
Object
- Object
- Aviary::Site
- Defined in:
- lib/aviary/site.rb
Instance Attribute Summary collapse
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#paginator ⇒ Object
readonly
Returns the value of attribute paginator.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#copy_assets ⇒ Object
Recursively copy the contents of the
_assets
directory into the root of thedest
directory. -
#copy_index ⇒ Object
Copies the first page and makes it the index at the root of the
dest
directory. - #current_page_path ⇒ Object
-
#initialize(config) ⇒ Site
constructor
A new instance of Site.
- #process ⇒ Object
- #render ⇒ Object
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
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
3 4 5 |
# File 'lib/aviary/site.rb', line 3 def dest @dest end |
#paginator ⇒ Object (readonly)
Returns the value of attribute paginator.
3 4 5 |
# File 'lib/aviary/site.rb', line 3 def paginator @paginator end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
3 4 5 |
# File 'lib/aviary/site.rb', line 3 def source @source end |
#template ⇒ Object (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_assets ⇒ Object
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_index ⇒ Object
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_path ⇒ Object
48 49 50 |
# File 'lib/aviary/site.rb', line 48 def current_page_path File.join(self.dest, "page#{self.paginator.current_page}") end |
#process ⇒ Object
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 |
#render ⇒ Object
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 |