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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/bijou/console/adapter.rb', line 20
def self.handle
opts = GetoptLong.new(
[ "--config" , "-c", GetoptLong::OPTIONAL_ARGUMENT ],
[ "--query", "-q", GetoptLong::REQUIRED_ARGUMENT ],
[ "--help", "-h", "-?", GetoptLong::NO_ARGUMENT ]
)
debug = false
t0 = Time.now
document_root = ENV['DOCUMENT_ROOT']
path_info = ENV['PATH_INFO']
bijou_cache = ENV['BIJOU_CACHE']
bijou_config = ENV['BIJOU_CONFIG']
query_string = ''
opts.each do |opt, arg|
case opt
when '--config'
bijou_config = arg
when '--query'
query_string = arg
when '--help'
return usage()
end
end
if ARGV.length == 1
path_info = ARGV[0]
elsif !document_root
puts "Missing document argument (try --help)"
return 0
end
if bijou_config
begin
config = Bijou::Config.load_file(bijou_config)
rescue SyntaxError
error = $!.to_s
error << "\nStack: " + $@.join("\n")
return self::diagnostic("Error loading configuration.", error)
end
if (!config)
return self::error("The configuration file path is invalid.")
end
else
config = Bijou::Config.new
end
if !config.document_root || config.document_root.empty?
if document_root
config.document_root = document_root
else
config.document_root = Dir.getwd
end
end
if !config.cache_root && bijou_cache
config.cache_root = bijou_cache
end
if !config.cache_root && bijou_cache
config.cache_root = bijou_cache
end
config.trace_buffer = false
config.includes.each do |inc|
$:.push inc
end
processor = Bijou::Processor.new
begin
context = processor.load(path_info, config)
rescue Exception
msg = Bijou::ErrorFormatter.format_error :text, 4, context
return self::diagnostic("Error loading page", msg)
end
context.request = Bijou::Console::Request.new(query_string)
context.response = Bijou::HttpResponse.new
args = {}
args.replace(context.request.params);
begin
context.render(args)
rescue Exception
msg = Bijou::ErrorFormatter.format_error :text, 4, context
return self::diagnostic("Syntax error loading page", msg)
end
puts context.output;
t3 = Time.now
if debug
puts context.get_log
if config.trace_level > 0
puts context.get_trace
end
end
end
|