Class: Page

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

Constant Summary collapse

METADATA =
%w{ title template order }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, title, template, order, markdown) ⇒ Page

Returns a new instance of Page.



22
23
24
25
26
27
28
# File 'lib/mook/page.rb', line 22

def initialize(name, title, template, order, markdown)
  @name = name.gsub(/\.[^\.]+$/, "")
  @title = title
  @template = template
  @order = order
  @markdown = markdown
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



20
21
22
# File 'lib/mook/page.rb', line 20

def content
  @content
end

#markdownObject (readonly)

Returns the value of attribute markdown.



19
20
21
# File 'lib/mook/page.rb', line 19

def markdown
  @markdown
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/mook/page.rb', line 19

def name
  @name
end

#orderObject (readonly)

Returns the value of attribute order.



19
20
21
# File 'lib/mook/page.rb', line 19

def order
  @order
end

#outputObject

Returns the value of attribute output.



20
21
22
# File 'lib/mook/page.rb', line 20

def output
  @output
end

#templateObject (readonly)

Returns the value of attribute template.



19
20
21
# File 'lib/mook/page.rb', line 19

def template
  @template
end

#titleObject (readonly)

Returns the value of attribute title.



19
20
21
# File 'lib/mook/page.rb', line 19

def title
  @title
end

#tocObject

Returns the value of attribute toc.



20
21
22
# File 'lib/mook/page.rb', line 20

def toc
  @toc
end

Class Method Details

.load(filename) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mook/page.rb', line 4

def self.load(filename)
  lines = File.read(filename)
  m, markdown = lines.split("* * *\n", 2)
   = Hash[*m.split("\n").map { |s| s.split(": ", 2) }.map { |k, v| [k.downcase, v] }.flatten]
  
  raise "#{filename} has no title" unless ["title"]
  raise "#{filename} has no template" unless ["template"]
  
  order = (["order"] || 1000).to_i
  
  Page.new(File.basename(filename), ["title"],
           ["template"], order,
           markdown.strip)
end

Instance Method Details

#urlObject



30
31
32
# File 'lib/mook/page.rb', line 30

def url
  "#{@name}.html"
end