benofsky-bolt 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
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
- @server.reply(page.call)
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
@@ -4,7 +4,6 @@ DRb.start_service()
4
4
  @serve_instance = DRbObject.new(nil, $drb_uri)
5
5
 
6
6
  def page(path, &block)
7
- @current_page = path
8
- path = "" if path == "index"
7
+ @serve_instance.pages[""] = block if path == "index"
9
8
  @serve_instance.pages[path] = block
10
9
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 2
9
- version: 0.4.2
8
+ - 3
9
+ version: 0.4.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ben McRedmond