class Schoolkeep::Server

Attributes

port[R]
quiet[R]
templates_path[R]

Public Class Methods

new(dir: ".", port: 4000, quiet: false, asset_host: ASSET_HOST) click to toggle source
# File lib/schoolkeep/server.rb, line 12
def initialize(dir: ".", port: 4000, quiet: false, asset_host: ASSET_HOST)
  @templates_path = File.join(dir, "templates")
  Template.path = templates_path
  fixture_path = File.join(dir, "config/fixtures.yml")
  unless File.exist?(fixture_path)
    fixture_path = File.join(dir,"fixtures.yml")
  end
  Fixture.default_path =  fixture_path
  Views::Layout.asset_host = asset_host
  @port = port
  @quiet = quiet

  webrick.mount_proc "/color_scheme.css" do |req, res|
    res["content-type"] = "text/css"
    res.body = Views::ColorScheme.new("color_scheme").render
  end

  webrick.mount_proc "/learning_color_scheme.css" do |req, res|
    res["content-type"] = "text/css"
    res.body = Views::ColorScheme.new("learning_color_scheme").render
  end

  webrick.mount_proc "/catalog/" do |req, res|
    id = req.path.split("/")[2]
    if id
      template = Template.new("course_details.html.sktl")

      res["content-type"] = template.type
      res.body = Views::Layout.new(template).render(variables: { "course" => id.to_sym })
    else
      template = Template.new("course_index.html.sktl")

      res["content-type"] = template.type
      res.body = Views::Layout.new(template).render
    end
  end

  webrick.mount_proc "/syllabus/" do |req, res|
    id = req.path.split("/")[2]
    template = Template.new("course_cover.html.sktl")

    res["content-type"] = template.type
    res.body = Views::Layout.new(template).render(variables: { "course" => id.to_sym })
  end

  webrick.mount_proc "/outline/" do |req, res|
    id = req.path.split("/")[2]

    template = Template.new("course_cover.html.sktl")
    res["content-type"] = template.type
    res.body = Views::Layout.new(template).render(variables: {
      "course" => id.to_sym
    })
  end
end

Public Instance Methods

shutdown() click to toggle source
# File lib/schoolkeep/server.rb, line 72
def shutdown
  webrick.shutdown
end
start() click to toggle source
# File lib/schoolkeep/server.rb, line 68
def start
  webrick.start
end

Private Instance Methods

config() click to toggle source
# File lib/schoolkeep/server.rb, line 82
def config
  {
    Port: port,
    DocumentRoot: templates_path,
    DocumentRootOptions: {
      FancyIndexing: true,
      HandlerTable: { "sktl" => SKTLHandler },
      NondisclosureName: ["_*"]
    }
  }.tap do |c|
    if quiet
      c.merge!(
        :AccessLog => [],
        :Logger => WEBrick::Log::new(File::NULL, 7)
      )
    end
  end
end
webrick() click to toggle source
# File lib/schoolkeep/server.rb, line 78
def webrick
  @webrick ||= WEBrick::HTTPServer.new config
end