joshbuddy-esi-for-rack 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +30 -0
- data/VERSION +1 -0
- data/lib/esi_for_rack/node.rb +133 -0
- data/lib/esi_for_rack.rb +83 -0
- data/spec/http_integration/accept_language_spec.rb +23 -0
- data/spec/http_integration/cookie_spec.rb +23 -0
- data/spec/http_integration/fixtures/accept_language/1.html +12 -0
- data/spec/http_integration/fixtures/cookie/1.html +3 -0
- data/spec/http_integration/fixtures/query_string/1.html +3 -0
- data/spec/http_integration/fixtures/user_agent/1.html +5 -0
- data/spec/http_integration/query_string_spec.rb +22 -0
- data/spec/http_integration/user_agent_spec.rb +23 -0
- data/spec/spec.opts +7 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/tags/choose_spec.rb +18 -0
- data/spec/tags/comment_spec.rb +9 -0
- data/spec/tags/fixtures/choose/simple1.html +8 -0
- data/spec/tags/fixtures/choose/simple2.html +11 -0
- data/spec/tags/fixtures/choose/simple3.html +8 -0
- data/spec/tags/fixtures/comment/simple.html +1 -0
- data/spec/tags/fixtures/include/alt.html +3 -0
- data/spec/tags/fixtures/include/src.html +3 -0
- data/spec/tags/fixtures/include/src_continue.html +3 -0
- data/spec/tags/fixtures/nested/complex.html +12 -0
- data/spec/tags/fixtures/try/include.html +6 -0
- data/spec/tags/fixtures/try/malformed_attempt.html +5 -0
- data/spec/tags/fixtures/try/malformed_except.html +3 -0
- data/spec/tags/fixtures/vars/simple.html +1 -0
- data/spec/tags/include_spec.rb +25 -0
- data/spec/tags/nested_spec.rb +13 -0
- data/spec/tags/try_spec.rb +28 -0
- data/spec/tags/vars_spec.rb +9 -0
- metadata +103 -0
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'lib/esi_for_rack'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |s|
|
6
|
+
s.name = "esi-for-rack"
|
7
|
+
s.description = s.summary = "ESI for Rack"
|
8
|
+
s.email = "joshbuddy@gmail.com"
|
9
|
+
s.homepage = "http://github.com/joshbuddy/esi_for_rack"
|
10
|
+
s.authors = ["Joshua Hull"]
|
11
|
+
s.files = FileList["[A-Z]*", "{lib,spec}/**/*"]
|
12
|
+
s.add_dependency 'joshbuddy-esi_attribute_language'
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'spec'
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
|
21
|
+
task :spec => 'spec:all'
|
22
|
+
namespace(:spec) do
|
23
|
+
Spec::Rake::SpecTask.new(:all) do |t|
|
24
|
+
t.spec_opts ||= []
|
25
|
+
t.spec_opts << "-rubygems"
|
26
|
+
t.spec_opts << "--options" << "spec/spec.opts"
|
27
|
+
t.spec_files = FileList['spec/**/*.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,133 @@
|
|
1
|
+
class EsiForRack
|
2
|
+
|
3
|
+
class Node
|
4
|
+
|
5
|
+
IncludeFailedError = Class.new(RuntimeError)
|
6
|
+
|
7
|
+
attr_reader :node, :context
|
8
|
+
|
9
|
+
def init(node, context)
|
10
|
+
@node = node
|
11
|
+
@context = context
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute_in_place!
|
16
|
+
value = execute.to_s
|
17
|
+
node.replace(Nokogiri::XML::CDATA.new(node.document, value))
|
18
|
+
end
|
19
|
+
|
20
|
+
class Include < Node
|
21
|
+
|
22
|
+
def execute
|
23
|
+
@resolved_src = EsiAttributeLanguage::SimpleGrammar.parse(@node['src']).execute(context.resolver)
|
24
|
+
@resolved_alt = EsiAttributeLanguage::SimpleGrammar.parse(@node['alt']).execute(context.resolver) if @node['alt']
|
25
|
+
@continue_on_error = node['onerror'] == 'continue'
|
26
|
+
|
27
|
+
context.lookup[@resolved_src] ||
|
28
|
+
(@resolved_alt && context.lookup[@resolved_alt]) ||
|
29
|
+
(!@continue_on_error && raise(IncludeFailedError.new)) || nil
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class Vars < Node
|
35
|
+
def execute
|
36
|
+
#@content = node.inner_html
|
37
|
+
@content = Rack::Utils.unescape(node.inner_html)
|
38
|
+
EsiAttributeLanguage::SimpleGrammar.parse(@content).execute(context.resolver)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Try < Node
|
43
|
+
|
44
|
+
def execute
|
45
|
+
unless @esi_attempt = node.css('esi_attempt')[0]
|
46
|
+
raise "no attempt within try"
|
47
|
+
end
|
48
|
+
|
49
|
+
unless @esi_except = node.css('esi_except')[0]
|
50
|
+
raise "no except within try"
|
51
|
+
end
|
52
|
+
|
53
|
+
val = ''
|
54
|
+
begin
|
55
|
+
context.process(@esi_attempt)
|
56
|
+
@esi_attempt.inner_html
|
57
|
+
rescue IncludeFailedError
|
58
|
+
context.process(@esi_except)
|
59
|
+
@esi_except.inner_html
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Choose < Node
|
65
|
+
def execute
|
66
|
+
whens = node.css('esi_when').to_a
|
67
|
+
raise "no when's within choose" if whens.empty?
|
68
|
+
|
69
|
+
otherwise = node.css('esi_otherwise')[0]
|
70
|
+
|
71
|
+
whens.each do |esi_when|
|
72
|
+
if EsiAttributeLanguage::Grammar.parse(esi_when['test']).execute(context.resolver).equal?(true)
|
73
|
+
context.process(esi_when)
|
74
|
+
return esi_when.inner_html
|
75
|
+
end
|
76
|
+
end
|
77
|
+
if otherwise
|
78
|
+
context.process(otherwise)
|
79
|
+
return otherwise.inner_html
|
80
|
+
end
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class Context
|
86
|
+
|
87
|
+
attr_reader :resolver, :lookup, :doc
|
88
|
+
|
89
|
+
def initialize(resolver, lookup)
|
90
|
+
@resolver = resolver
|
91
|
+
@lookup = lookup
|
92
|
+
|
93
|
+
@include = Include.new
|
94
|
+
@choose = Choose.new
|
95
|
+
@vars = Vars.new
|
96
|
+
@try = Try.new
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
def parse(document)
|
101
|
+
document.gsub!('esi:', 'esi_')
|
102
|
+
|
103
|
+
@doc = Nokogiri::HTML(document)
|
104
|
+
|
105
|
+
@doc.css('esi_comment').each do |esi_comment|
|
106
|
+
esi_comment.replace(Nokogiri::XML::CDATA.new(doc, ''))
|
107
|
+
end
|
108
|
+
|
109
|
+
process(@doc)
|
110
|
+
|
111
|
+
@doc
|
112
|
+
end
|
113
|
+
|
114
|
+
def process(doc_fragment)
|
115
|
+
# have to go one at a time because of limitation of .css, its not a live list.
|
116
|
+
while esi_node = doc_fragment.css('esi_try,esi_choose,esi_vars,esi_include')[0]
|
117
|
+
case esi_node.name.to_sym
|
118
|
+
when :esi_include
|
119
|
+
@include.init(esi_node, self).execute_in_place!
|
120
|
+
when :esi_choose
|
121
|
+
@choose.init(esi_node, self).execute_in_place!
|
122
|
+
when :esi_vars
|
123
|
+
@vars.init(esi_node, self).execute_in_place!
|
124
|
+
when :esi_try
|
125
|
+
@try.init(esi_node, self).execute_in_place!
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
data/lib/esi_for_rack.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
require 'esi_attribute_language'
|
5
|
+
require 'parse_user_agent'
|
6
|
+
|
7
|
+
require File.join(File.dirname(__FILE__), 'esi_for_rack', 'node')
|
8
|
+
require File.join(File.dirname(__FILE__), 'esi_for_rack', 'lookup')
|
9
|
+
|
10
|
+
class EsiForRack
|
11
|
+
|
12
|
+
def initialize(app, lookup = nil)
|
13
|
+
@app = app
|
14
|
+
@lookup = lookup
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@lookup ||= Lookup::PassThrough.new(@app, env)
|
19
|
+
|
20
|
+
request = Rack::Request.new(env)
|
21
|
+
result = @app.call(env)
|
22
|
+
response = Rack::Response.new(result[2], result[0], result[1])
|
23
|
+
|
24
|
+
if response['Content-Type'] =~ /text\/html/
|
25
|
+
body = ""
|
26
|
+
response.body.each do |part|
|
27
|
+
body << part
|
28
|
+
end
|
29
|
+
|
30
|
+
user_agent_hash = {}
|
31
|
+
begin
|
32
|
+
user_agent = ParseUserAgent.new.parse(env['HTTP_USER_AGENT'] || '-')
|
33
|
+
user_agent_hash['browser'] = case user_agent.browser
|
34
|
+
when 'Firefox' then 'MOZILLA'
|
35
|
+
when 'MSIE' then 'MSIE'
|
36
|
+
else; 'OTHER'
|
37
|
+
end
|
38
|
+
|
39
|
+
user_agent_hash['version'] = user_agent.browser_version_major
|
40
|
+
|
41
|
+
user_agent_hash['os'] = case user_agent.ostype
|
42
|
+
when 'Windows' then 'WIN'
|
43
|
+
when 'Macintosh' then 'MAC'
|
44
|
+
else; 'OTHER'
|
45
|
+
end
|
46
|
+
|
47
|
+
rescue
|
48
|
+
# error parsing ua
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
binding = {
|
54
|
+
:HTTP_ACCEPT_LANGUAGE => Set.new((env['HTTP_ACCEPT_LANGUAGE'] || '').split(',').map{|l| l.strip.gsub(/q=[0-9]\.[0-9]{1,3}/, '').gsub(';','')}),
|
55
|
+
:HTTP_COOKIE => request.cookies,
|
56
|
+
:HTTP_HOST => request.host,
|
57
|
+
:HTTP_REFERER => request.referer,
|
58
|
+
:HTTP_USER_AGENT => user_agent_hash,
|
59
|
+
:QUERY_STRING => request.GET
|
60
|
+
}
|
61
|
+
context = Node::Context.new(binding, @lookup)
|
62
|
+
[response.status, response.headers, [context.parse(body).to_s]]
|
63
|
+
else
|
64
|
+
result
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
class IOWrapper
|
70
|
+
def initialize(body)
|
71
|
+
@body = body.each
|
72
|
+
end
|
73
|
+
|
74
|
+
def read
|
75
|
+
@body.end?
|
76
|
+
end
|
77
|
+
|
78
|
+
def close
|
79
|
+
#no-op
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "esi user agent variable lookups" do
|
4
|
+
|
5
|
+
it "should lookup a cookie variable" do
|
6
|
+
|
7
|
+
vars = {'type' => 'user'}
|
8
|
+
builder = Rack::Builder.new do
|
9
|
+
use EsiForRack, {'/file/WIN' => 'os', '/file/1.5' => 'version', '/file/MOZILLA' => 'browser'}
|
10
|
+
|
11
|
+
run proc { |env|
|
12
|
+
data = IO.read('spec/http_integration/fixtures/accept_language/1.html')
|
13
|
+
[200, {'Content-type' => 'text/html', 'Content-length' => data.size.to_s}, [data]]
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
request = Rack::MockRequest.env_for("/?#{Rack::Utils.build_query(vars)}")
|
18
|
+
request['HTTP_ACCEPT_LANGUAGE'] = 'da, en-gb;q=0.8, en;q=0.7'
|
19
|
+
builder.call(request).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body>\nENDAEN-GB\n</body></html>\n"]
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "esi cookie variable lookups" do
|
4
|
+
|
5
|
+
it "should lookup a cookie variable" do
|
6
|
+
|
7
|
+
vars = {'type' => 'user'}
|
8
|
+
builder = Rack::Builder.new do
|
9
|
+
use EsiForRack, {'/file/1' => 'resource'}
|
10
|
+
|
11
|
+
run proc { |env|
|
12
|
+
data = IO.read('spec/http_integration/fixtures/cookie/1.html')
|
13
|
+
[200, {'Content-type' => 'text/html', 'Content-length' => data.size.to_s}, [data]]
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
request = Rack::MockRequest.env_for("/?#{Rack::Utils.build_query(vars)}")
|
18
|
+
request['HTTP_COOKIE'] = 'id=1'
|
19
|
+
builder.call(request).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body>resource</body></html>\n"]
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<html><body>
|
2
|
+
<esi:choose>
|
3
|
+
<esi:when test="$(HTTP_ACCEPT_LANGUAGE{en})">EN</esi:when>
|
4
|
+
</esi:choose>
|
5
|
+
<esi:choose>
|
6
|
+
<esi:when test="$(HTTP_ACCEPT_LANGUAGE{da})">DA</esi:when>
|
7
|
+
</esi:choose>
|
8
|
+
<esi:choose>
|
9
|
+
<esi:when test="$(HTTP_ACCEPT_LANGUAGE{en-gb})">EN-GB</esi:when>
|
10
|
+
</esi:choose>
|
11
|
+
|
12
|
+
</body></html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "esi query string variable lookups" do
|
4
|
+
|
5
|
+
it "should lookup a query string variable" do
|
6
|
+
|
7
|
+
vars = {'id' => '1'}
|
8
|
+
builder = Rack::Builder.new do
|
9
|
+
use EsiForRack, {'/file/1' => 'resource'}
|
10
|
+
|
11
|
+
run proc { |env|
|
12
|
+
data = IO.read('spec/http_integration/fixtures/query_string/1.html')
|
13
|
+
[200, {'Content-type' => 'text/html', 'Content-length' => data.size.to_s}, [data]]
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
request = Rack::MockRequest.env_for("/?#{Rack::Utils.build_query(vars)}")
|
18
|
+
builder.call(request).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body>resource</body></html>\n"]
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "esi user agent variable lookups" do
|
4
|
+
|
5
|
+
it "should lookup a cookie variable" do
|
6
|
+
|
7
|
+
vars = {'type' => 'user'}
|
8
|
+
builder = Rack::Builder.new do
|
9
|
+
use EsiForRack, {'/file/WIN' => 'os', '/file/1.5' => 'version', '/file/MOZILLA' => 'browser'}
|
10
|
+
|
11
|
+
run proc { |env|
|
12
|
+
data = IO.read('spec/http_integration/fixtures/user_agent/1.html')
|
13
|
+
[200, {'Content-type' => 'text/html', 'Content-length' => data.size.to_s}, [data]]
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
request = Rack::MockRequest.env_for("/?#{Rack::Utils.build_query(vars)}")
|
18
|
+
request['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2'
|
19
|
+
builder.call(request).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body>\nbrowserosversion\n</body></html>\n"]
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 = true
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'lib/esi_for_rack'
|
5
|
+
|
6
|
+
def build_app(file, lookup)
|
7
|
+
builder = Rack::Builder.new do
|
8
|
+
use EsiForRack
|
9
|
+
|
10
|
+
run proc { |env|
|
11
|
+
data = if env['PATH_INFO'] == '/'
|
12
|
+
IO.read(file)
|
13
|
+
else
|
14
|
+
lookup[env['PATH_INFO']]
|
15
|
+
end
|
16
|
+
|
17
|
+
if data
|
18
|
+
[200, {'Content-type' => 'text/html', 'Content-length' => data.size.to_s}, [data]]
|
19
|
+
else
|
20
|
+
[404, {}, []]
|
21
|
+
end
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
request = Rack::MockRequest.env_for("/?a=b")
|
26
|
+
builder.call(request)
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "esi choose" do
|
4
|
+
|
5
|
+
it "should pick the first available choice" do
|
6
|
+
build_app('spec/tags/fixtures/choose/simple1.html', {}).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body>\n Hey you\n </body></html>\n"]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should pick next available choice" do
|
10
|
+
build_app('spec/tags/fixtures/choose/simple2.html', {}).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body>\n And you\n </body></html>\n"]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should take the otherwise block if there is no valid choice" do
|
14
|
+
build_app('spec/tags/fixtures/choose/simple3.html', {}).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body> \n No good\n </body></html>\n"]
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "esi comment" do
|
4
|
+
|
5
|
+
it "should not render a comment" do
|
6
|
+
build_app('spec/tags/fixtures/comment/simple.html', {}).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>This will show up.</p></body></html>\n"]
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
This will <esi:comment>This will never show up</esi:comment>show up.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<esi:try>
|
2
|
+
<esi:attempt>
|
3
|
+
This is my include: <esi:include src="/include" />
|
4
|
+
Choice/<esi:choose>
|
5
|
+
<esi:when test="1==2">false</esi:when>
|
6
|
+
<esi:when test="1==1">true</esi:when>
|
7
|
+
</esi:choose>/Choice
|
8
|
+
</esi:attempt>
|
9
|
+
<esi:except>
|
10
|
+
BLAH!
|
11
|
+
</esi:except>
|
12
|
+
</esi:try>
|
@@ -0,0 +1 @@
|
|
1
|
+
<esi:vars><img src="http://www.example.com/$(QUERY_STRING{a})/hello.gif"/ ></esi:vars>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "esi include" do
|
4
|
+
|
5
|
+
it "should include a src" do
|
6
|
+
build_app('spec/tags/fixtures/include/src.html', {'/great' => "<p>This is great</p>"}).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>This is great</p></body></html>\n"]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should include an alt if src is unavilable" do
|
10
|
+
build_app('spec/tags/fixtures/include/alt.html', {'/alternate' => "<p>This is great</p>"}).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>This is great</p></body></html>\n"]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should raise an error if src is unavilable" do
|
14
|
+
proc { build_app('spec/tags/fixtures/include/src.html', {}) }.should raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise an error if src and alt is unavilable" do
|
18
|
+
proc { build_app('spec/tags/fixtures/include/alt.html', {}) }.should raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should continue though, if onerror=continue" do
|
22
|
+
build_app('spec/tags/fixtures/include/src_continue.html', {}).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body></body></html>\n"]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "esi nested" do
|
4
|
+
|
5
|
+
it "nested1" do
|
6
|
+
build_app('spec/tags/fixtures/nested/complex.html', {}).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body>\n BLAH!\n </body></html>\n"]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "nested2" do
|
10
|
+
build_app('spec/tags/fixtures/nested/complex.html', {'/include' => "<p>This is great</p>"}).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body>\n This is my include: <p>This is great</p>\n Choice/true/Choice\n </body></html>\n"]
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "esi try" do
|
4
|
+
|
5
|
+
it "should raise on try block without except" do
|
6
|
+
proc {
|
7
|
+
build_app('spec/tags/fixtures/try/malformed_attempt.html', {'/great' => "<p>This is great</p>"})
|
8
|
+
}.should raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise on try block without attempt" do
|
12
|
+
proc {
|
13
|
+
build_app('spec/tags/fixtures/try/malformed_attempt.html', {'/great' => "<p>This is great</p>"})
|
14
|
+
}.should raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should include normally within an attempt block" do
|
18
|
+
build_app('spec/tags/fixtures/try/include.html', {'/great' => "<p>This is great</p>"}).last.should ==
|
19
|
+
["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>This is great</p></body></html>\n"]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should render the except block when the include fails within an attempt block" do
|
23
|
+
build_app('spec/tags/fixtures/try/include.html', {}).last.should ==
|
24
|
+
["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body>This is bad</body></html>\n"]
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "esi vars" do
|
4
|
+
|
5
|
+
it "should render the content within vars" do
|
6
|
+
build_app('spec/tags/fixtures/vars/simple.html', {}).last.should == ["<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><img src=\"http://www.example.com/b/hello.gif\"></body></html>\n"]
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: joshbuddy-esi-for-rack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joshua Hull
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-18 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: joshbuddy-esi_attribute_language
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: ESI for Rack
|
26
|
+
email: joshbuddy@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- Rakefile
|
35
|
+
- VERSION
|
36
|
+
- lib/esi_for_rack.rb
|
37
|
+
- lib/esi_for_rack/node.rb
|
38
|
+
- spec/http_integration/accept_language_spec.rb
|
39
|
+
- spec/http_integration/cookie_spec.rb
|
40
|
+
- spec/http_integration/fixtures/accept_language/1.html
|
41
|
+
- spec/http_integration/fixtures/cookie/1.html
|
42
|
+
- spec/http_integration/fixtures/query_string/1.html
|
43
|
+
- spec/http_integration/fixtures/user_agent/1.html
|
44
|
+
- spec/http_integration/query_string_spec.rb
|
45
|
+
- spec/http_integration/user_agent_spec.rb
|
46
|
+
- spec/spec.opts
|
47
|
+
- spec/spec_helper.rb
|
48
|
+
- spec/tags/choose_spec.rb
|
49
|
+
- spec/tags/comment_spec.rb
|
50
|
+
- spec/tags/fixtures/choose/simple1.html
|
51
|
+
- spec/tags/fixtures/choose/simple2.html
|
52
|
+
- spec/tags/fixtures/choose/simple3.html
|
53
|
+
- spec/tags/fixtures/comment/simple.html
|
54
|
+
- spec/tags/fixtures/include/alt.html
|
55
|
+
- spec/tags/fixtures/include/src.html
|
56
|
+
- spec/tags/fixtures/include/src_continue.html
|
57
|
+
- spec/tags/fixtures/nested/complex.html
|
58
|
+
- spec/tags/fixtures/try/include.html
|
59
|
+
- spec/tags/fixtures/try/malformed_attempt.html
|
60
|
+
- spec/tags/fixtures/try/malformed_except.html
|
61
|
+
- spec/tags/fixtures/vars/simple.html
|
62
|
+
- spec/tags/include_spec.rb
|
63
|
+
- spec/tags/nested_spec.rb
|
64
|
+
- spec/tags/try_spec.rb
|
65
|
+
- spec/tags/vars_spec.rb
|
66
|
+
has_rdoc: false
|
67
|
+
homepage: http://github.com/joshbuddy/esi_for_rack
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.2.0
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: ESI for Rack
|
92
|
+
test_files:
|
93
|
+
- spec/http_integration/accept_language_spec.rb
|
94
|
+
- spec/http_integration/cookie_spec.rb
|
95
|
+
- spec/http_integration/query_string_spec.rb
|
96
|
+
- spec/http_integration/user_agent_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/tags/choose_spec.rb
|
99
|
+
- spec/tags/comment_spec.rb
|
100
|
+
- spec/tags/include_spec.rb
|
101
|
+
- spec/tags/nested_spec.rb
|
102
|
+
- spec/tags/try_spec.rb
|
103
|
+
- spec/tags/vars_spec.rb
|