Class: Schoolkeep::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/schoolkeep/server.rb

Defined Under Namespace

Classes: SKTLHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir: ".", port: 4000, quiet: false, asset_host: ASSET_HOST) ⇒ Server

Returns a new instance of Server.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'lib/schoolkeep/server.rb', line 10

def port
  @port
end

#quietObject (readonly)

Returns the value of attribute quiet.



10
11
12
# File 'lib/schoolkeep/server.rb', line 10

def quiet
  @quiet
end

#templates_pathObject (readonly)

Returns the value of attribute templates_path.



10
11
12
# File 'lib/schoolkeep/server.rb', line 10

def templates_path
  @templates_path
end

Instance Method Details

#shutdownObject



72
73
74
# File 'lib/schoolkeep/server.rb', line 72

def shutdown
  webrick.shutdown
end

#startObject



68
69
70
# File 'lib/schoolkeep/server.rb', line 68

def start
  webrick.start
end