rack_ssi 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -37,3 +37,15 @@ end
37
37
  ```ruby
38
38
  config.middleware.use Rack::SSI, { ... }
39
39
  ```
40
+
41
+ #### Haml
42
+
43
+ To use includes in your HAML, the following should work ok:
44
+
45
+ ```ruby
46
+ !!!
47
+ %html{:xmlns => "http://www.w3.org/1999/xhtml"}
48
+ %head
49
+ %title My site
50
+ / #include file="tools/includes/header.html"
51
+ ```
data/lib/ssi_processor.rb CHANGED
@@ -16,7 +16,7 @@ module Rack
16
16
  end
17
17
 
18
18
  def process_block(part)
19
- part.gsub(/<!--#\s+block\s+name="(\w+)"\s+-->(.*?)<!--#\s+endblock\s+-->/) do
19
+ part.gsub(/<!--\s?#\s?block\s+name="(\w+)"\s+-->(.*?)<!--\s?#\s+endblock\s+-->/) do
20
20
  name, content = $1, $2
21
21
  _info "processing block directive with name=#{name}"
22
22
  yield [name, content]
@@ -25,7 +25,7 @@ module Rack
25
25
  end
26
26
 
27
27
  def process_include(part, blocks)
28
- part.gsub(/<!--#\s+include\s+(?:virtual|file)="([^"]+)"(?:\s+stub="(\w+)")?\s+-->/) do
28
+ part.gsub(/<!--\s?#\s?include\s+(?:virtual|file)="([^"]+)"(?:\s+stub="(\w+)")?\s+-->/) do
29
29
  location, stub = $1, $2
30
30
  _info "processing include directive with location=#{location}"
31
31
  status, _, body = fetch location
@@ -66,4 +66,4 @@ module Rack
66
66
  end
67
67
 
68
68
  end
69
- end
69
+ end
data/rack-ssi.gemspec CHANGED
@@ -15,6 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
16
  gem.name = "rack_ssi"
17
17
  gem.require_paths = ["lib"]
18
- gem.version = "0.0.3"
18
+ gem.version = "0.0.4"
19
19
  gem.add_dependency "rest-client"
20
20
  end
@@ -29,6 +29,33 @@ describe Rack::SSIProcessor do
29
29
 
30
30
  processed = ssi.process_block(html) {|block| blocks << block}
31
31
 
32
+ processed.gsub(/\s+/, "").should == expected
33
+ blocks.should == [["shush", ""], ["shouty", "<h1>ERROR!</h1>"]]
34
+ end
35
+ it "should yield block directives and strip them out of the html from HAML responses" do
36
+ html = <<-eos
37
+ <html>
38
+ <body>
39
+ <!-- # block name="shush" --><!-- # endblock -->
40
+ <p>some content</p>
41
+ <!-- #block name="shouty" --><h1>ERROR!</h1><!-- # endblock -->
42
+ </body>
43
+ </html>
44
+ eos
45
+
46
+ expected = <<-eos.gsub /\s+/, ""
47
+ <html>
48
+ <body>
49
+ <p>some content</p>
50
+ </body>
51
+ </html>
52
+ eos
53
+
54
+ ssi = Rack::SSIProcessor.new
55
+ blocks = []
56
+
57
+ processed = ssi.process_block(html) {|block| blocks << block}
58
+
32
59
  processed.gsub(/\s+/, "").should == expected
33
60
  blocks.should == [["shush", ""], ["shouty", "<h1>ERROR!</h1>"]]
34
61
  end
@@ -61,6 +88,32 @@ describe Rack::SSIProcessor do
61
88
 
62
89
  processed = ssi.process_include(html, {})
63
90
 
91
+ processed.gsub(/\s+/, "").should == expected
92
+ end
93
+ it "should replace include directives from HAML response with appropriate content" do
94
+ html = <<-eos
95
+ <html>
96
+ <body>
97
+ <!-- # include virtual="/some/other/location_from_haml" -->
98
+ <!-- #include virtual="/some/other/location_from_haml" -->
99
+ </body>
100
+ </html>
101
+ eos
102
+
103
+ expected = <<-eos.gsub /\s+/, ""
104
+ <html>
105
+ <body>
106
+ <p>some content from haml</p>
107
+ <p>some content from haml</p>
108
+ </body>
109
+ </html>
110
+ eos
111
+
112
+ ssi = Rack::SSIProcessor.new
113
+ ssi.stub(:fetch).with("/some/other/location_from_haml").and_return([200, {}, "<p>some content from haml</p>"])
114
+
115
+ processed = ssi.process_include(html, {})
116
+
64
117
  processed.gsub(/\s+/, "").should == expected
65
118
  end
66
119
  end
@@ -221,4 +274,4 @@ describe Rack::SSIProcessor do
221
274
  end
222
275
  end
223
276
 
224
- end
277
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_ssi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client