Class: Massimo::Page

Inherits:
Resource show all
Defined in:
lib/massimo/page.rb

Constant Summary collapse

FRONT_MATTER_PARSER =
/
  (
    \A\s*       # Beginning of file
    ^---\s*$\n* # Start YAML Block
    (.*?)\n*    # YAML data
    ^---\s*$\n* # End YAML Block
  )
  (.*)          # Rest of File
/mx

Instance Attribute Summary

Attributes inherited from Resource

#content, #source_path

Instance Method Summary collapse

Methods inherited from Resource

all, #extensions, #filename, find, #initialize, path, #process, processable?, resource_name, url

Constructor Details

This class inherits a constructor from Massimo::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (protected)



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/massimo/page.rb', line 92

def method_missing(method, *args, &block)
  if args.length == 0
    method_name = method.to_s
    if method_name.chomp! '?'
      !!@meta_data[method_name.to_sym]
    else
      @meta_data[method_name.to_sym]
    end
  else
    super
  end
end

Instance Method Details

#extensionObject



33
34
35
36
37
38
39
40
41
# File 'lib/massimo/page.rb', line 33

def extension
  if @meta_data[:extension]
    @meta_data[:extension]
  elsif Tilt.registered?(super[1..-1])
    '.html'
  else
    super
  end
end

#layoutObject



47
48
49
50
# File 'lib/massimo/page.rb', line 47

def layout
  @meta_data[:layout] = 'main' if @meta_data[:layout].nil?
  @meta_data[:layout]
end

#output_pathObject



52
53
54
55
56
57
58
# File 'lib/massimo/page.rb', line 52

def output_path
  @output_path ||= begin
    output_path = super.to_s
    output_path << 'index.html' if output_path.ends_with? '/'
    Pathname.new output_path
  end
end

#renderObject



19
20
21
22
23
24
25
26
27
# File 'lib/massimo/page.rb', line 19

def render
  output = super
    
  if found_layout = Massimo::View.find("layouts/#{layout}")
    output = found_layout.render(:page => self) { output }
  end
  
  output
end

#titleObject



29
30
31
# File 'lib/massimo/page.rb', line 29

def title
  @meta_data[:title] ||= filename.gsub(/\.[^.]+/, '').titleize
end

#urlObject



43
44
45
# File 'lib/massimo/page.rb', line 43

def url
  @meta_data[:url] ||= super.chomp('index.html').sub(/\.html$/, '/')
end