cgi-spa 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/cgi-spa.gemspec +14 -17
- data/lib/cgi-spa/cgi-methods.rb +56 -4
- data/lib/cgi-spa/environment.rb +15 -3
- data/lib/cgi-spa/version.rb +1 -1
- metadata +5 -5
data/cgi-spa.gemspec
CHANGED
@@ -1,25 +1,22 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.
|
4
|
+
s.name = "cgi-spa"
|
5
|
+
s.version = "0.6.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
s.
|
17
|
-
s.
|
18
|
-
s.
|
19
|
-
s.
|
20
|
-
s.rubyforge_project = %q{cgi-spa}
|
21
|
-
s.rubygems_version = %q{1.8.5}
|
22
|
-
s.summary = %q{CGI Single Page Applications}
|
8
|
+
s.authors = ["Sam Ruby"]
|
9
|
+
s.date = "2012-01-07"
|
10
|
+
s.description = " Provides a number of globals, helper methods, and monkey patches which\n simplify the development of single page applications in the form of\n CGI scripts.\n"
|
11
|
+
s.email = "rubys@intertwingly.net"
|
12
|
+
s.extra_rdoc_files = ["COPYING", "README", "lib/cgi-spa.rb", "lib/cgi-spa/builder.rb", "lib/cgi-spa/cgi-methods.rb", "lib/cgi-spa/environment.rb", "lib/cgi-spa/html-methods.rb", "lib/cgi-spa/installation.rb", "lib/cgi-spa/job-control.rb", "lib/cgi-spa/version.rb"]
|
13
|
+
s.files = ["COPYING", "Manifest", "README", "Rakefile", "cgi-spa.gemspec", "lib/cgi-spa.rb", "lib/cgi-spa/builder.rb", "lib/cgi-spa/cgi-methods.rb", "lib/cgi-spa/environment.rb", "lib/cgi-spa/html-methods.rb", "lib/cgi-spa/installation.rb", "lib/cgi-spa/job-control.rb", "lib/cgi-spa/version.rb"]
|
14
|
+
s.homepage = "http://github.com/rubys/cgi-spa"
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cgi-spa", "--main", "README"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = "cgi-spa"
|
18
|
+
s.rubygems_version = "1.8.11"
|
19
|
+
s.summary = "CGI Single Page Applications"
|
23
20
|
|
24
21
|
if s.respond_to? :specification_version then
|
25
22
|
s.specification_version = 3
|
data/lib/cgi-spa/cgi-methods.rb
CHANGED
@@ -1,8 +1,23 @@
|
|
1
1
|
# produce json
|
2
2
|
def $cgi.json
|
3
3
|
return unless $XHR_JSON
|
4
|
-
|
5
|
-
|
4
|
+
output = yield
|
5
|
+
rescue Exception => exception
|
6
|
+
Kernel.print "Status: 500 Internal Error\r\n"
|
7
|
+
output = {
|
8
|
+
:exception => exception.inspect,
|
9
|
+
:backtrace => exception.backtrace
|
10
|
+
}
|
11
|
+
ensure
|
12
|
+
if $XHR_JSON
|
13
|
+
Kernel.print "Status: 404 Not Found\r\n" unless output
|
14
|
+
$cgi.out 'type' => 'application/json', 'Cache-Control' => 'no-cache' do
|
15
|
+
begin
|
16
|
+
JSON.pretty_generate(output)+ "\n"
|
17
|
+
rescue
|
18
|
+
output.to_json + "\n"
|
19
|
+
end
|
20
|
+
end
|
6
21
|
end
|
7
22
|
end
|
8
23
|
|
@@ -13,9 +28,46 @@ def $cgi.json! &block
|
|
13
28
|
Process.exit
|
14
29
|
end
|
15
30
|
|
31
|
+
# produce text
|
32
|
+
def $cgi.text &block
|
33
|
+
return unless $TEXT
|
34
|
+
@output = []
|
35
|
+
def $cgi.puts(line='')
|
36
|
+
@output << line + "\n"
|
37
|
+
end
|
38
|
+
def $cgi.print(line=nil)
|
39
|
+
@output << line
|
40
|
+
end
|
41
|
+
self.instance_eval &block
|
42
|
+
rescue Exception => exception
|
43
|
+
Kernel.print "Status: 500 Internal Error\r\n"
|
44
|
+
@output << "\n" unless @output.empty?
|
45
|
+
@output << exception.inspect + "\n"
|
46
|
+
exception.backtrace.each {|frame| @output << " #{frame}\n"}
|
47
|
+
ensure
|
48
|
+
class << $cgi
|
49
|
+
undef puts
|
50
|
+
undef print
|
51
|
+
end
|
52
|
+
if $TEXT
|
53
|
+
Kernel.print "Status: 404 Not Found\r\n" if @output.empty?
|
54
|
+
$cgi.out 'type' => 'text/plain', 'Cache-Control' => 'no-cache' do
|
55
|
+
@output.join
|
56
|
+
end
|
57
|
+
@output = nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# produce text and quit
|
62
|
+
def $cgi.text! &block
|
63
|
+
return unless $TEXT
|
64
|
+
json(&block)
|
65
|
+
Process.exit
|
66
|
+
end
|
67
|
+
|
16
68
|
# produce html/xhtml
|
17
69
|
def $cgi.html
|
18
|
-
return if $XHR_JSON
|
70
|
+
return if $XHR_JSON or $TEXT
|
19
71
|
if $XHTML
|
20
72
|
$cgi.out 'type' => 'application/xhtml+xml', 'charset' => 'UTF-8' do
|
21
73
|
$x.declare! :DOCTYPE, :html
|
@@ -35,7 +87,7 @@ end
|
|
35
87
|
|
36
88
|
# produce html and quit
|
37
89
|
def $cgi.html! &block
|
38
|
-
return if $XHR_JSON
|
90
|
+
return if $XHR_JSON or $TEXT
|
39
91
|
html(&block)
|
40
92
|
Process.exit
|
41
93
|
end
|
data/lib/cgi-spa/environment.rb
CHANGED
@@ -3,6 +3,7 @@ $HTTP_GET = ARGV.delete('--html')
|
|
3
3
|
$HTTP_POST = ARGV.delete('--post')
|
4
4
|
$XHR_JSON = ARGV.delete('--json')
|
5
5
|
$XHTML = ARGV.delete('--xhtml')
|
6
|
+
$TEXT = ARGV.delete('--text')
|
6
7
|
|
7
8
|
# Only prompt if explicitly asked for
|
8
9
|
ARGV.push '' if ARGV.empty?
|
@@ -18,6 +19,7 @@ $HTTP_GET ||= ($cgi.request_method == 'GET')
|
|
18
19
|
$HTTP_POST ||= ($cgi.request_method == 'POST')
|
19
20
|
$XHR_JSON ||= ($cgi.accept.to_s =~ /json/)
|
20
21
|
$XHTML ||= ($cgi.accept.to_s =~ /xhtml/)
|
22
|
+
$TEXT ||= ($cgi.accept.to_s =~ /plain/ and $cgi.accept.to_s !~ /html/)
|
21
23
|
|
22
24
|
# get arguments if CGI couldn't find any...
|
23
25
|
$param.merge!(CGI.parse(ARGV.join('&'))) if $param.empty?
|
@@ -44,7 +46,7 @@ end
|
|
44
46
|
$env = {}
|
45
47
|
def $env.method_missing(name)
|
46
48
|
delete name.to_s if ENV[name.to_s] != self[name.to_s]
|
47
|
-
|
49
|
+
if ENV[name.to_s] and not has_key?(name.to_s)
|
48
50
|
self[name.to_s]=ENV[name.to_s].dup.extend(CgiSpa::Untaint)
|
49
51
|
end
|
50
52
|
self[name.to_s]
|
@@ -53,16 +55,26 @@ end
|
|
53
55
|
# quick access to request_uri
|
54
56
|
SELF = ENV['REQUEST_URI'].to_s
|
55
57
|
def SELF?
|
56
|
-
SELF
|
58
|
+
if SELF.include? '?'
|
59
|
+
SELF
|
60
|
+
else
|
61
|
+
SELF + "?" # avoids spoiling the cache
|
62
|
+
end
|
57
63
|
end
|
58
64
|
|
59
65
|
# environment objects
|
60
|
-
$USER = ENV['USER'] ||
|
66
|
+
$USER = ENV['REMOTE_USER'] || ENV['USER'] ||
|
61
67
|
if RUBY_PLATFORM =~ /darwin/
|
62
68
|
`dscl . -search /Users UniqueID #{Process.uid}`.split.first
|
63
69
|
else
|
64
70
|
`getent passwd #{Process.uid}`.split(':').first
|
65
71
|
end
|
66
72
|
|
73
|
+
ENV['REMOTE_USER'] ||= $USER
|
74
|
+
|
67
75
|
$HOME = ENV['HOME'] || File.expand_path('~' + $USER)
|
68
76
|
$SERVER = ENV['HTTP_HOST'] || `hostname`.chomp
|
77
|
+
|
78
|
+
# more implied request types
|
79
|
+
$XHR_JSON ||= ($env.REQUEST_URI.to_s =~ /\?json$/)
|
80
|
+
$TEXT ||= ($env.REQUEST_URI.to_s =~ /\?text$/)
|
data/lib/cgi-spa/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cgi-spa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 6
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sam Ruby
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: builder
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
requirements: []
|
112
112
|
|
113
113
|
rubyforge_project: cgi-spa
|
114
|
-
rubygems_version: 1.8.
|
114
|
+
rubygems_version: 1.8.11
|
115
115
|
signing_key:
|
116
116
|
specification_version: 3
|
117
117
|
summary: CGI Single Page Applications
|