glog 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/glog/page.rb +5 -27
- data/lib/glog/server.rb +21 -10
- data/lib/glog.rb +12 -3
- metadata +2 -2
data/lib/glog/page.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
require 'jadof'
|
2
|
+
|
1
3
|
module Glog
|
2
4
|
class Page < JADOF::Page
|
5
|
+
|
3
6
|
def self.root
|
4
7
|
get(Glog.config['root'])
|
5
8
|
end
|
@@ -8,33 +11,8 @@ module Glog
|
|
8
11
|
self.template == false ? super : wrap_with_template(super)
|
9
12
|
end
|
10
13
|
|
11
|
-
def
|
12
|
-
|
13
|
-
"templates/#{self.template}.haml"
|
14
|
-
else self.parent.size > 0
|
15
|
-
detect_template_from_parent
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def detect_template_from_parent
|
20
|
-
first_match = false
|
21
|
-
segments = self.parent.split(File::SEPARATOR)
|
22
|
-
segments.size.times do |i|
|
23
|
-
template_path = (['templates'] + segments[0..-(i-1)] + ['default.haml']).join(File::SEPARATOR)
|
24
|
-
if File.exists?(template_path)
|
25
|
-
first_match = template_path
|
26
|
-
break
|
27
|
-
end
|
28
|
-
segments.pop
|
29
|
-
end
|
30
|
-
first_match || 'templates/default.haml'
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def wrap_with_template(content)
|
36
|
-
locals = { :page => self, :config => Glog.config, :pages => self.class }
|
37
|
-
Haml::Engine.new(File.read(template_path)).to_html(nil, locals)
|
14
|
+
def path_with_parent
|
15
|
+
File.join(parent, name)
|
38
16
|
end
|
39
17
|
|
40
18
|
end
|
data/lib/glog/server.rb
CHANGED
@@ -1,40 +1,51 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
1
3
|
module Glog
|
2
4
|
class Server
|
3
|
-
|
4
|
-
def call(
|
5
|
-
env
|
5
|
+
|
6
|
+
def call(rack_env)
|
7
|
+
Glog.env = Env.new(rack_env)
|
8
|
+
Glog.env.path?('/') ? send_root_page : send_path(Glog.env.path)
|
6
9
|
end
|
7
|
-
|
10
|
+
|
8
11
|
private
|
9
12
|
|
10
13
|
def send_path(path)
|
11
14
|
path = path[1..-1] # /my/page => my/page
|
12
15
|
# First trying to load page
|
13
16
|
if page = Page.get(path)
|
17
|
+
puts page
|
14
18
|
send_page(page)
|
15
19
|
# Then trying to load directory index if any
|
16
20
|
elsif page = try_dir_index(path)
|
21
|
+
puts page
|
17
22
|
send_page(page)
|
18
23
|
else
|
19
24
|
send_not_found
|
20
25
|
end
|
21
26
|
end
|
22
|
-
|
27
|
+
|
23
28
|
def try_dir_index(path)
|
24
29
|
File.directory?(File.join('pages', path))
|
25
30
|
Page.get(File.join(path, 'index'))
|
26
31
|
end
|
27
|
-
|
32
|
+
|
28
33
|
def send_page(page)
|
29
|
-
[200, { 'Content-Type' => 'text/html' }, page
|
34
|
+
[200, { 'Content-Type' => 'text/html' }, render_page(page)]
|
30
35
|
end
|
31
|
-
|
36
|
+
|
32
37
|
def send_not_found
|
33
38
|
[404, { 'Content-Type' => 'text/html'}, '404 Not Found']
|
34
39
|
end
|
35
|
-
|
40
|
+
|
36
41
|
def send_root_page
|
37
42
|
Page.root ? send_page(Page.root) : send_not_found
|
38
43
|
end
|
44
|
+
|
45
|
+
def render_page(page)
|
46
|
+
locals = { :env => Glog.env, :config => Glog.config, :pages => Page }
|
47
|
+
Template.wrap(page, locals).render
|
48
|
+
end
|
49
|
+
|
39
50
|
end # Server
|
40
|
-
end # Glog
|
51
|
+
end # Glog
|
data/lib/glog.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
3
|
-
require '
|
4
|
-
require 'haml'
|
2
|
+
|
3
|
+
require 'glog/env'
|
5
4
|
require 'glog/page'
|
5
|
+
require 'glog/template'
|
6
6
|
require 'glog/server'
|
7
7
|
|
8
8
|
module Glog
|
9
9
|
|
10
10
|
@@config = nil
|
11
|
+
@@env = nil
|
11
12
|
|
12
13
|
def self.config
|
13
14
|
@@config ||= YAML.load_file('glog.yaml')
|
@@ -16,5 +17,13 @@ module Glog
|
|
16
17
|
def self.config=(config)
|
17
18
|
@@config = config
|
18
19
|
end
|
20
|
+
|
21
|
+
def self.env
|
22
|
+
@@env
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.env=(env)
|
26
|
+
@@env = env
|
27
|
+
end
|
19
28
|
|
20
29
|
end
|