Class: Meta::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/meta/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dest = BASEDIR) ⇒ Page

Returns a new instance of Page.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/meta/page.rb', line 7

def initialize(dest=BASEDIR)

  @dest       = dest

  @catalog    = Meta::Catalog.new

  @templates  = Meta::Filelib.get_templates

  @layout = Tilt.new("layout.haml") if @templates.include?("layout.haml")
  @navbar = Tilt.new("navbar.haml") if @templates.include?("navbar.haml")
  @index  = Tilt.new("index.haml")  if @templates.include?("index.haml")
  @page   = Tilt.new("page.haml")   if @templates.include?("page.haml")

  if @layout.nil?
    abort("layout.haml template missing, this file must be included".red)
  end
  #TODO: must include index and page as well

end

Instance Attribute Details

#catalogObject (readonly)

Returns the value of attribute catalog.



5
6
7
# File 'lib/meta/page.rb', line 5

def catalog
  @catalog
end

Instance Method Details

#generate(overwrite = false) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/meta/page.rb', line 41

def generate(overwrite=false)

  all = Meta::Filelib.get_contents

  stats   = @catalog.get_statistics

  all.each do |c|

    if File.zero?(c)

      puts "skipped file #{c} - empty file".yellow
      next

    end

    content = @catalog.check_content(c)

    content[:summary]     = Tilt.new(c).render
    content[:link]        = File.basename( content[:path],
      File.extname(content[:path]) ) + HTMLEXT

    p = @page.render( self, :content => content )

    html = @layout.render( self, :stats => stats ) { p }
    
    Meta::Filelib.create_file( html, c, HTMLEXT, @dest, overwrite )

  end

end

#generate_index(overwrite = false) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/meta/page.rb', line 27

def generate_index(overwrite=false)

  contents = @catalog.get_recent(-1)

  stats    = @catalog.get_statistics

  doc   = @index.render( self, :contents => contents )

  html  = @layout.render( self, :stats => stats ) { doc }

  Meta::Filelib.create_file( html, INDEX, HTMLEXT, @dest, overwrite )

end