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.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#navbar ⇒ Object
readonly
Returns the value of attribute navbar.
Instance Method Summary collapse
- #generate(overwrite = false) ⇒ Object
- #generate_main(overwrite = false) ⇒ Object
- #generate_row(contents) ⇒ 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 |
# File 'lib/meta/page.rb', line 7 def initialize(dest=BASEDIR) @dest = dest @catalog = Meta::Catalog.new @layout = Tilt.new("layout.haml") = Tilt.new("navbar.haml") @col = Tilt.new("col.haml") 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 |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
5 6 7 |
# File 'lib/meta/page.rb', line 5 def layout @layout end |
#navbar ⇒ Object (readonly)
Returns the value of attribute navbar.
5 6 7 |
# File 'lib/meta/page.rb', line 5 def end |
Instance Method Details
#generate(overwrite = false) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/meta/page.rb', line 90 def generate(overwrite=false) all = Meta::Filelib.get_contents all.each do |c| if File.zero?(c) puts "skipped file #{c} - empty file".yellow next end content = @catalog.check_content(c) content[:col_classes] = "col-lg-12 box" content[:summary] = Tilt.new(c).render content[:link] = File.basename( content[:path], File.extname(content[:path]) ) + HTMLEXT contents = [] contents << content rows = [] rows << contents r = @col.render( self, :rows => rows ) html = @layout.render { r } Meta::Filelib.create_file( html, c, @dest, overwrite ) end end |
#generate_main(overwrite = false) ⇒ Object
57 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 |
# File 'lib/meta/page.rb', line 57 def generate_main(overwrite=false) c = @catalog.get_recent(-1) length = c.length remain = length index = 0 rows = [] rng = Random.new(SEED) while remain != 0 do n = rng.rand(1..remain) r = generate_row(c[index..index+n-1]) remain = remain - n index = index + n rows << r end doc = @col.render( self, :rows => rows ) html = @layout.render { doc } Meta::Filelib.create_file( html, INDEX, @dest, overwrite ) end |
#generate_row(contents) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/meta/page.rb', line 19 def generate_row(contents) length = contents.length if length == 1 contents[0][:col_classes] = "col-lg-12 box" elsif length == 2 rng = Random.new(SEED) r = rng.rand(1..3) if r == 3 contents[0][:col_classes] = "col-lg-6 box" contents[1][:col_classes] = "col-lg-6 box" elsif r == 2 contents[0][:col_classes] = "col-lg-8 box" contents[1][:col_classes] = "col-lg-4 box" else contents[0][:col_classes] = "col-lg-4 box" contents[1][:col_classes] = "col-lg-8 box" end elsif length == 3 contents[0][:col_classes] = "col-lg-4 box" contents[1][:col_classes] = "col-lg-4 box" contents[2][:col_classes] = "col-lg-4 box" else contents[0][:col_classes] = "col-lg-3 box" contents[1][:col_classes] = "col-lg-3 box" contents[2][:col_classes] = "col-lg-3 box" contents[3][:col_classes] = "col-lg-3 box" end return contents end |