Class: Meta::Page
- Inherits:
-
Object
- Object
- Meta::Page
- Defined in:
- lib/meta/page.rb
Instance Attribute Summary collapse
-
#catalog ⇒ Object
readonly
Returns the value of attribute catalog.
Instance Method Summary collapse
- #generate(overwrite = false) ⇒ Object
- #generate_index(overwrite = false) ⇒ Object
-
#initialize(dest = BASEDIR) ⇒ Page
constructor
A new instance of Page.
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/meta/page.rb', line 7 def initialize(dest=BASEDIR) @dest = dest @catalog = Meta::Catalog.new @layouts = Meta::Filelib.get_templates(LAYOUTS) = Meta::Filelib.get_templates(NAVBARS) @pages = Meta::Filelib.get_templates(PAGES) = Meta::Filelib.get_templates(FOOTERS) unless @layouts.include?(LAYOUT) abort("layout.haml not found, #{LAYOUT}, #{INDEX}, and #{PAGE} must exist".red) end unless @pages.include?(INDEX) abort("index.haml not found, #{LAYOUT}, #{INDEX}, and #{PAGE} must exist".red) end unless @pages.include?(PAGE) abort("page.haml not found, #{LAYOUT}, #{INDEX}, #{PAGE} must exist".red) end templates = @layouts | @pages templates |= unless .nil? templates |= unless .nil? @catalog.sync_templates(templates) @index = Tilt.new(INDEX) @page = Tilt.new(PAGE) @layout = Tilt.new(LAYOUT) end |
Instance Attribute Details
#catalog ⇒ Object (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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/meta/page.rb', line 58 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.sync_content(c) content[:summary] = Tilt.new(c).render content[:link] = File.basename( content[:path], File.extname(content[:path]) ) + HTMLEXT layout = @catalog.get_template( "layouts", content[:layout_id] ) page = @catalog.get_template( "pages", content[:page_id] ) @mylayout = Tilt.new(layout) @mypage = Tilt.new(page) p = @mypage.render( self, :content => content ) html = @mylayout.render( self, :stats => stats ) { p } Meta::Filelib.create_file( html, c, HTMLEXT, @dest, overwrite ) end end |
#generate_index(overwrite = false) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/meta/page.rb', line 42 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 } puts "If any content has been modified, index.html should be updated.".yellow Meta::Filelib.create_file( html, INDEX, HTMLEXT, @dest, overwrite ) end |