Class: Metc::Page

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePage

Returns a new instance of Page.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/metc/page.rb', line 7

def initialize()

  @catalog = Metc::Catalog.new

  @layout = Tilt.new("layout.haml")
  @navbar = Tilt.new("navbar.haml")
  @col3   = Tilt.new("col3.haml")
  @col4   = Tilt.new("col4.haml")
  @col6   = Tilt.new("col6.haml")
  @col8a  = Tilt.new("col8a.haml")
  @col8b  = Tilt.new("col8b.haml")
  @col12  = Tilt.new("col12.haml")

end

Instance Attribute Details

#catalogObject (readonly)

Returns the value of attribute catalog.



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

def catalog
  @catalog
end

#layoutObject (readonly)

Returns the value of attribute layout.



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

def layout
  @layout
end

Returns the value of attribute navbar.



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

def navbar
  @navbar
end

Instance Method Details

#generate(content) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/metc/page.rb', line 73

def generate(content)

  return if File.zero?(content)

  html = @layout.render { Tilt.new(content).render }

  Metc::Filelib.create_file( html, content )

  @catalog.check_content(content)

end

#generate_mainObject



38
39
40
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
71
# File 'lib/metc/page.rb', line 38

def generate_main()

  c = @catalog.get_recent(-1)

  length = c.length
  remain = length
  index  = 0

  doc = ""

  rng = Random.new(SEED)

  while remain != 0 do

    if remain > 4
      n = rng.rand(1..4)
    else
      n = remain
    end

    r = generate_row(c[index..index+n-1])

    remain = remain - n
    index  = index + n

    doc = doc + r
    
  end

  html = @layout.render { doc }

  Metc::Filelib.create_file( html, "index.html" )

end

#generate_row(contents) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/metc/page.rb', line 22

def generate_row(contents)

  length = contents.length

  if length == 1
    return @col12.render( self, :contents => contents )
  elsif length == 2
    return @col8a.render( self, :contents => contents )
  elsif length == 3
    return @col4.render( self, :contents => contents )
  elsif length == 4
    return @col3.render( self, :contents => contents )
  end

end