benofsky-bolt 0.4.2 → 0.4.3
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/bolt/serve.rb +15 -4
- data/lib/bolt/serve_page.rb +1 -2
- metadata +2 -2
data/lib/bolt/serve.rb
CHANGED
|
@@ -39,6 +39,12 @@ module Bolt
|
|
|
39
39
|
include DRbUndumped
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
class PageBinding
|
|
43
|
+
def initialize(current_page)
|
|
44
|
+
@current_page = current_page
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
42
48
|
class Serve < Build
|
|
43
49
|
attr_accessor :pages
|
|
44
50
|
|
|
@@ -65,16 +71,20 @@ module Bolt
|
|
|
65
71
|
# Basically the parent class Build loads each page in the pages directory
|
|
66
72
|
# for whatever project we're in, however the bolt/serve_page require up above
|
|
67
73
|
# overrides the standard page method used in these pages to instead send us
|
|
68
|
-
# the block used to generate the page, so basically @pages is full of
|
|
74
|
+
# the block used to generate the page (via drb), so basically @pages is full of
|
|
69
75
|
# url => block references.
|
|
70
76
|
load_pages
|
|
71
77
|
parse_config
|
|
72
78
|
|
|
73
79
|
page_name = request['GET'].gsub(/\.html/,'')[1..-1]
|
|
74
80
|
page = @pages[page_name]
|
|
75
|
-
|
|
81
|
+
|
|
76
82
|
if(!page.nil?)
|
|
77
|
-
|
|
83
|
+
page_name = "index" if page_name == ""
|
|
84
|
+
|
|
85
|
+
# A tad hacky, otherwise @current_page isn't set properly and all hell breaks loose
|
|
86
|
+
body = PageBinding.new(page_name).instance_eval(&page)
|
|
87
|
+
@server.reply(body)
|
|
78
88
|
elsif(File.exists?(d($config.resources) + request['GET']))
|
|
79
89
|
f = File.new(d($config.resources) + request['GET'])
|
|
80
90
|
@server.reply(f.to_s, 200, 'Content-Type' => f.content_type)
|
|
@@ -83,7 +93,8 @@ module Bolt
|
|
|
83
93
|
end
|
|
84
94
|
end
|
|
85
95
|
rescue Exception => e
|
|
86
|
-
puts e
|
|
96
|
+
puts "Error: #{e}"
|
|
97
|
+
puts e.backtrace
|
|
87
98
|
@server.reply(File.new(@errors_base + '500.html').to_s, 500)
|
|
88
99
|
retry
|
|
89
100
|
end
|
data/lib/bolt/serve_page.rb
CHANGED