class Pakman::Page
Jekyll-style page
with optional front-matter (yaml block)
Constants
- HEADERS_PATTERN
check if s includes newline too? fix/check ^ - just means start of newline (use /A or something — MUST always be first
note: include --- in headers e.g. --- results in nil empty string (without leading ---) results in false! (we want nil if no headers for empty block)
Attributes
contents[R]
headers[R]
Public Class Methods
from_file( path )
click to toggle source
# File lib/pakman/page.rb, line 11 def self.from_file( path ) puts " Loading page (from file) >#{path}<..." text = File.open( path, 'r:bom|utf-8' ).read ## note: assume utf8 self.new( text, path: path ) ## note: pass along path as an option end
from_string( text )
click to toggle source
# File lib/pakman/page.rb, line 17 def self.from_string( text ) ### use parse as alias - why?? why not?? self.new( text ) end
new( text, opts={} )
click to toggle source
# File lib/pakman/page.rb, line 39 def initialize( text, opts={} ) ## todo/fix: check regex in jekyll (add link to source etc.) if m=HEADERS_PATTERN.match( text ) @contents = m.post_match pp m pp m[:headers] @headers = YAML.load( m[:headers] ) pp @headers @headers = {} if @headers.nil? ## check if headers is nil use/assign empty hash else @contents = text @headers = nil end end
Public Instance Methods
headers?()
click to toggle source
has headers/metadata (front matter block) - yes/no - use hash for check for now
# File lib/pakman/page.rb, line 25 def headers?() @headers.kind_of?( Hash ); end