cgi-spa 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/cgi-spa.gemspec +2 -2
- data/lib/cgi-spa/cgi-methods.rb +19 -4
- data/lib/cgi-spa/version.rb +1 -1
- metadata +4 -4
data/cgi-spa.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "cgi-spa"
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.7.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Sam Ruby"]
|
9
|
-
s.date = "2012-01-
|
9
|
+
s.date = "2012-01-10"
|
10
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
11
|
s.email = "rubys@intertwingly.net"
|
12
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"]
|
data/lib/cgi-spa/cgi-methods.rb
CHANGED
@@ -11,7 +11,7 @@ rescue Exception => exception
|
|
11
11
|
ensure
|
12
12
|
if $XHR_JSON
|
13
13
|
Kernel.print "Status: 404 Not Found\r\n" unless output
|
14
|
-
$cgi.out 'type' => 'application/json', 'Cache-Control' => 'no-cache' do
|
14
|
+
$cgi.out? 'type' => 'application/json', 'Cache-Control' => 'no-cache' do
|
15
15
|
begin
|
16
16
|
JSON.pretty_generate(output)+ "\n"
|
17
17
|
rescue
|
@@ -51,7 +51,7 @@ ensure
|
|
51
51
|
end
|
52
52
|
if $TEXT
|
53
53
|
Kernel.print "Status: 404 Not Found\r\n" if @output.empty?
|
54
|
-
$cgi.out 'type' => 'text/plain', 'Cache-Control' => 'no-cache' do
|
54
|
+
$cgi.out? 'type' => 'text/plain', 'Cache-Control' => 'no-cache' do
|
55
55
|
@output.join
|
56
56
|
end
|
57
57
|
@output = nil
|
@@ -65,18 +65,33 @@ def $cgi.text! &block
|
|
65
65
|
Process.exit
|
66
66
|
end
|
67
67
|
|
68
|
+
# Conditionally provide output, based on ETAG
|
69
|
+
def $cgi.out?(headers, &block)
|
70
|
+
content = block.call
|
71
|
+
require 'digest/md5'
|
72
|
+
etag = Digest::MD5.hexdigest(content)
|
73
|
+
|
74
|
+
if ENV['HTTP_IF_NONE_MATCH'] == etag.inspect
|
75
|
+
print "Status: 304 Not Modified\r\n\r\n"
|
76
|
+
else
|
77
|
+
$cgi.out headers.merge('Etag' => etag.inspect) do
|
78
|
+
content
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
68
83
|
# produce html/xhtml
|
69
84
|
def $cgi.html
|
70
85
|
return if $XHR_JSON or $TEXT
|
71
86
|
if $XHTML
|
72
|
-
$cgi.out 'type' => 'application/xhtml+xml', 'charset' => 'UTF-8' do
|
87
|
+
$cgi.out? 'type' => 'application/xhtml+xml', 'charset' => 'UTF-8' do
|
73
88
|
$x.declare! :DOCTYPE, :html
|
74
89
|
$x.html :xmlns => 'http://www.w3.org/1999/xhtml' do
|
75
90
|
yield $x
|
76
91
|
end
|
77
92
|
end
|
78
93
|
else
|
79
|
-
$cgi.out 'type' => 'text/html', 'charset' => 'UTF-8' do
|
94
|
+
$cgi.out? 'type' => 'text/html', 'charset' => 'UTF-8' do
|
80
95
|
$x.declare! :DOCTYPE, :html
|
81
96
|
$x.html do
|
82
97
|
yield $x
|
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: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 7
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.7.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: 2012-01-
|
18
|
+
date: 2012-01-10 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: builder
|