class Impression::Pages

Public Class Methods

new(base_path, opts = {}) click to toggle source
# File lib/impression/pages.rb, line 18
def initialize(base_path, opts = {})
  @base_path = base_path
  @opts = opts

  load
end

Public Instance Methods

load() click to toggle source
# File lib/impression/pages.rb, line 25
def load
  @map = {}
  Dir['**/*', base: @base_path].each do |path|
    next if path =~ /\/_.+/

    full_path = File.join(@base_path, path)
    next unless File.file?(full_path)

    page = Page.new(path, full_path, @opts)
    @map[page.relative_permalink] = page
  end
  @map['/'] = @map['/index']
end
Also aliased as: reload
load_file(path) click to toggle source
# File lib/impression/pages.rb, line 40
def load_file(path)
  content = IO.read(path)
end
reload()
Alias for: load
serve(req) click to toggle source
# File lib/impression/pages.rb, line 44
def serve(req)
  page = @map[req.routing_path]
  raise NotFoundError unless page

  # return req.respond('Hello world')

  
  req.respond(page.to_html, 'Content-Type' => 'text/html')
end