vanilla 1.2 → 1.9.9

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.
Files changed (106) hide show
  1. data/Rakefile +61 -60
  2. data/bin/vanilla +6 -35
  3. data/config.example.yml +6 -0
  4. data/config.ru +10 -0
  5. data/lib/defensio.rb +59 -0
  6. data/lib/tasks/vanilla.rake +173 -0
  7. data/lib/vanilla.rb +3 -10
  8. data/lib/vanilla/app.rb +48 -104
  9. data/lib/vanilla/console.rb +5 -19
  10. data/lib/vanilla/dynasnips/comments.rb +108 -0
  11. data/lib/vanilla/dynasnips/current_snip.rb +32 -0
  12. data/{pristine_app/soups → lib/vanilla}/dynasnips/debug.rb +3 -5
  13. data/lib/vanilla/dynasnips/edit.rb +60 -0
  14. data/lib/vanilla/dynasnips/edit_link.rb +20 -0
  15. data/{pristine_app/soups → lib/vanilla}/dynasnips/index.rb +2 -4
  16. data/{pristine_app/soups/extras → lib/vanilla/dynasnips}/kind.rb +12 -14
  17. data/{pristine_app/soups → lib/vanilla}/dynasnips/link_to.rb +0 -2
  18. data/lib/vanilla/dynasnips/link_to_current_snip.rb +16 -0
  19. data/lib/vanilla/dynasnips/login.rb +56 -0
  20. data/lib/vanilla/dynasnips/new.rb +14 -0
  21. data/lib/vanilla/dynasnips/notes.rb +42 -0
  22. data/{pristine_app/soups → lib/vanilla}/dynasnips/pre.rb +4 -6
  23. data/{pristine_app/soups/extras → lib/vanilla/dynasnips}/rand.rb +0 -2
  24. data/{pristine_app/soups → lib/vanilla}/dynasnips/raw.rb +5 -8
  25. data/{pristine_app/soups/extras → lib/vanilla/dynasnips}/url_to.rb +0 -0
  26. data/lib/vanilla/renderers/base.rb +22 -32
  27. data/lib/vanilla/renderers/bold.rb +2 -0
  28. data/lib/vanilla/renderers/erb.rb +2 -0
  29. data/lib/vanilla/renderers/markdown.rb +2 -0
  30. data/lib/vanilla/renderers/raw.rb +2 -0
  31. data/lib/vanilla/renderers/ruby.rb +5 -9
  32. data/lib/vanilla/renderers/textile.rb +2 -0
  33. data/lib/vanilla/request.rb +15 -16
  34. data/lib/vanilla/routes.rb +18 -5
  35. data/lib/vanilla/snip_reference.rb +534 -0
  36. data/lib/vanilla/snip_reference.treetop +48 -0
  37. data/lib/vanilla/snip_reference_parser.rb +99 -82
  38. data/lib/vanilla/snips/start.rb +28 -0
  39. data/lib/vanilla/snips/system.rb +77 -0
  40. data/lib/vanilla/snips/tutorial.rb +244 -0
  41. data/lib/vanilla/soup_with_timestamps.rb +21 -0
  42. data/public/hatch.png +0 -0
  43. data/public/javascripts/jquery.autogrow-textarea.js +54 -0
  44. data/public/javascripts/jquery.js +4376 -0
  45. data/public/javascripts/vanilla.js +22 -0
  46. data/spec/dynasnip_spec.rb +28 -0
  47. data/spec/renderers/base_renderer_spec.rb +40 -0
  48. data/spec/renderers/erb_renderer_spec.rb +27 -0
  49. data/spec/renderers/markdown_renderer_spec.rb +29 -0
  50. data/spec/renderers/raw_renderer_spec.rb +21 -0
  51. data/spec/renderers/ruby_renderer_spec.rb +59 -0
  52. data/spec/renderers/vanilla_app_detecting_renderer_spec.rb +35 -0
  53. data/spec/spec_helper.rb +70 -0
  54. data/spec/tmp/config.yml +2 -0
  55. data/spec/tmp/soup/current_snip.yml +15 -0
  56. data/spec/tmp/soup/system.yml +5 -0
  57. data/spec/vanilla_app_spec.rb +38 -0
  58. data/spec/vanilla_presenting_spec.rb +84 -0
  59. data/spec/vanilla_request_spec.rb +73 -0
  60. metadata +79 -170
  61. data/lib/vanilla/renderers.rb +0 -12
  62. data/lib/vanilla/renderers/haml.rb +0 -13
  63. data/lib/vanilla/static.rb +0 -28
  64. data/pristine_app/Gemfile +0 -3
  65. data/pristine_app/Gemfile.lock +0 -32
  66. data/pristine_app/README +0 -47
  67. data/pristine_app/config.ru +0 -26
  68. data/pristine_app/public/vanilla.css +0 -15
  69. data/pristine_app/soups/base/layout.snip +0 -18
  70. data/pristine_app/soups/base/start.snip +0 -19
  71. data/pristine_app/soups/dynasnips/current_snip.rb +0 -29
  72. data/pristine_app/soups/dynasnips/link_to_current_snip.rb +0 -14
  73. data/pristine_app/soups/dynasnips/page_title.rb +0 -9
  74. data/pristine_app/soups/extras/comments.rb +0 -78
  75. data/pristine_app/soups/tutorial/bad_dynasnip.snip +0 -8
  76. data/pristine_app/soups/tutorial/hello_world.snip +0 -20
  77. data/pristine_app/soups/tutorial/markdown_example.snip +0 -13
  78. data/pristine_app/soups/tutorial/snip.snip +0 -9
  79. data/pristine_app/soups/tutorial/soup.snip +0 -3
  80. data/pristine_app/soups/tutorial/test.snip +0 -30
  81. data/pristine_app/soups/tutorial/textile_example.snip +0 -11
  82. data/pristine_app/soups/tutorial/tutorial-another-snip.snip +0 -1
  83. data/pristine_app/soups/tutorial/tutorial-basic-snip-inclusion.snip +0 -1
  84. data/pristine_app/soups/tutorial/tutorial-dynasnips.snip.markdown +0 -56
  85. data/pristine_app/soups/tutorial/tutorial-layout.snip +0 -56
  86. data/pristine_app/soups/tutorial/tutorial-links.snip +0 -4
  87. data/pristine_app/soups/tutorial/tutorial-renderers.snip.markdown +0 -77
  88. data/pristine_app/soups/tutorial/tutorial.snip.markdown +0 -69
  89. data/pristine_app/soups/tutorial/vanilla-rb.snip +0 -16
  90. data/pristine_app/soups/tutorial/vanilla.snip +0 -8
  91. data/test/dynasnip_test.rb +0 -42
  92. data/test/dynasnips/link_to_current_snip_test.rb +0 -19
  93. data/test/dynasnips/link_to_test.rb +0 -27
  94. data/test/dynasnips/page_title_test.rb +0 -19
  95. data/test/renderers/base_renderer_test.rb +0 -43
  96. data/test/renderers/erb_renderer_test.rb +0 -29
  97. data/test/renderers/haml_renderer_test.rb +0 -35
  98. data/test/renderers/markdown_renderer_test.rb +0 -31
  99. data/test/renderers/raw_renderer_test.rb +0 -23
  100. data/test/renderers/ruby_renderer_test.rb +0 -59
  101. data/test/snip_inclusion_test.rb +0 -56
  102. data/test/snip_reference_parser_test.rb +0 -123
  103. data/test/test_helper.rb +0 -75
  104. data/test/vanilla_app_test.rb +0 -83
  105. data/test/vanilla_presenting_test.rb +0 -125
  106. data/test/vanilla_request_test.rb +0 -87
@@ -0,0 +1,73 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe Vanilla::Request, "when requesting urls" do
4
+ before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip"), @app) }
5
+
6
+ it "should use the first segement as the snip name" do
7
+ @request.snip_name.should == "snip"
8
+ end
9
+
10
+ it "should try to load the snip based on the snip name" do
11
+ @app.soup.should_receive(:[]).with('snip').and_return(:snip)
12
+ @request.snip.should == :snip
13
+ end
14
+
15
+ it "should have no part if the url contains only a single segment" do
16
+ @request.part.should == nil
17
+ end
18
+
19
+ it "should have a default format of html" do
20
+ @request.format.should == 'html'
21
+ end
22
+
23
+ it "should determine the request method" do
24
+ @request.method.should == 'get'
25
+ end
26
+ end
27
+
28
+ describe Vanilla::Request, "when requesting a snip part" do
29
+ before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip/part"), @app) }
30
+
31
+ it "should use the first segment as the snip, and the second segment as the part" do
32
+ @request.snip_name.should == "snip"
33
+ @request.part.should == "part"
34
+ end
35
+
36
+ it "should have a default format of html" do
37
+ @request.format.should == "html"
38
+ end
39
+ end
40
+
41
+ describe Vanilla::Request, "when requesting a snip with a format" do
42
+ before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip.raw"), @app) }
43
+
44
+ it "should use the extension as the format" do
45
+ @request.format.should == "raw"
46
+ end
47
+
48
+ it "should retain the filename part of the path as the snip" do
49
+ @request.snip_name.should == "snip"
50
+ end
51
+ end
52
+
53
+ describe Vanilla::Request, "when requesting a snip part with a format" do
54
+ before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip/part.raw"), @app) }
55
+
56
+ it "should use the extension as the format" do
57
+ @request.format.should == "raw"
58
+ end
59
+
60
+ it "should retain the first segment of the path as the snip" do
61
+ @request.snip_name.should == "snip"
62
+ end
63
+
64
+ it "should use the filename part of the second segment as the snip part" do
65
+ @request.part.should == "part"
66
+ end
67
+ end
68
+
69
+ describe Vanilla::Request, "when requested with a _method paramter" do
70
+ it "should return the method using the parameter" do
71
+ Vanilla::Request.new(mock_env_for_url("/snip?_method=put"), @app).method.should == 'put'
72
+ end
73
+ end
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanilla
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 2
9
- version: "1.2"
4
+ version: 1.9.9
10
5
  platform: ruby
11
6
  authors:
12
7
  - James Adam
@@ -14,149 +9,79 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2011-05-03 00:00:00 +01:00
12
+ date: 2009-10-12 00:00:00 +01:00
18
13
  default_executable:
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
- prerelease: false
22
- type: :runtime
23
16
  name: rack
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
25
- none: false
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
26
20
  requirements:
27
21
  - - ">="
28
22
  - !ruby/object:Gem::Version
29
- hash: 57
30
- segments:
31
- - 0
32
- - 9
33
- - 1
34
23
  version: 0.9.1
35
- requirement: *id001
24
+ version:
36
25
  - !ruby/object:Gem::Dependency
37
- prerelease: false
38
- type: :runtime
39
26
  name: soup
40
- version_requirements: &id002 !ruby/object:Gem::Requirement
41
- none: false
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
42
30
  requirements:
43
31
  - - ">="
44
32
  - !ruby/object:Gem::Version
45
- hash: 27
46
- segments:
47
- - 1
48
- - 0
49
- - 6
50
- version: 1.0.6
51
- requirement: *id002
33
+ version: 0.9.9
34
+ version:
52
35
  - !ruby/object:Gem::Dependency
53
- prerelease: false
54
- type: :runtime
55
36
  name: ratom
56
- version_requirements: &id003 !ruby/object:Gem::Requirement
57
- none: false
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
58
40
  requirements:
59
41
  - - ">="
60
42
  - !ruby/object:Gem::Version
61
- hash: 25
62
- segments:
63
- - 0
64
- - 3
65
- - 5
66
43
  version: 0.3.5
67
- requirement: *id003
44
+ version:
68
45
  - !ruby/object:Gem::Dependency
69
- prerelease: false
70
- type: :runtime
71
46
  name: RedCloth
72
- version_requirements: &id004 !ruby/object:Gem::Requirement
73
- none: false
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
74
50
  requirements:
75
51
  - - ">="
76
52
  - !ruby/object:Gem::Version
77
- hash: 57
78
- segments:
79
- - 4
80
- - 1
81
- - 1
82
53
  version: 4.1.1
83
- requirement: *id004
54
+ version:
84
55
  - !ruby/object:Gem::Dependency
85
- prerelease: false
86
- type: :runtime
87
56
  name: BlueCloth
88
- version_requirements: &id005 !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- hash: 23
94
- segments:
95
- - 1
96
- - 0
97
- - 0
98
- version: 1.0.0
99
- requirement: *id005
100
- - !ruby/object:Gem::Dependency
101
- prerelease: false
102
57
  type: :runtime
103
- name: haml
104
- version_requirements: &id006 !ruby/object:Gem::Requirement
105
- none: false
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
106
60
  requirements:
107
61
  - - ">="
108
62
  - !ruby/object:Gem::Version
109
- hash: 3
110
- segments:
111
- - 0
112
- version: "0"
113
- requirement: *id006
63
+ version: 1.0.0
64
+ version:
114
65
  - !ruby/object:Gem::Dependency
115
- prerelease: false
66
+ name: treetop
116
67
  type: :runtime
117
- name: parslet
118
- version_requirements: &id007 !ruby/object:Gem::Requirement
119
- none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 31
124
- segments:
125
- - 1
126
- - 2
127
- - 0
128
- version: 1.2.0
129
- requirement: *id007
130
- - !ruby/object:Gem::Dependency
131
- prerelease: false
132
- type: :development
133
- name: kintama
134
- version_requirements: &id008 !ruby/object:Gem::Requirement
135
- none: false
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
136
70
  requirements:
137
71
  - - ">="
138
72
  - !ruby/object:Gem::Version
139
- hash: 23
140
- segments:
141
- - 0
142
- - 1
143
- - 6
144
- version: 0.1.6
145
- requirement: *id008
73
+ version: 1.4.1
74
+ version:
146
75
  - !ruby/object:Gem::Dependency
147
- prerelease: false
76
+ name: rspec
148
77
  type: :development
149
- name: mocha
150
- version_requirements: &id009 !ruby/object:Gem::Requirement
151
- none: false
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
152
80
  requirements:
153
81
  - - ">="
154
82
  - !ruby/object:Gem::Version
155
- hash: 3
156
- segments:
157
- - 0
158
83
  version: "0"
159
- requirement: *id009
84
+ version:
160
85
  description:
161
86
  email: james@lazyatom.com.com
162
87
  executables:
@@ -166,77 +91,67 @@ extensions: []
166
91
  extra_rdoc_files:
167
92
  - README
168
93
  files:
94
+ - config.example.yml
95
+ - config.ru
169
96
  - Rakefile
170
97
  - README
171
- - test/dynasnip_test.rb
172
- - test/dynasnips/link_to_current_snip_test.rb
173
- - test/dynasnips/link_to_test.rb
174
- - test/dynasnips/page_title_test.rb
175
- - test/renderers/base_renderer_test.rb
176
- - test/renderers/erb_renderer_test.rb
177
- - test/renderers/haml_renderer_test.rb
178
- - test/renderers/markdown_renderer_test.rb
179
- - test/renderers/raw_renderer_test.rb
180
- - test/renderers/ruby_renderer_test.rb
181
- - test/snip_inclusion_test.rb
182
- - test/snip_reference_parser_test.rb
183
- - test/test_helper.rb
184
- - test/vanilla_app_test.rb
185
- - test/vanilla_presenting_test.rb
186
- - test/vanilla_request_test.rb
98
+ - spec/dynasnip_spec.rb
99
+ - spec/renderers/base_renderer_spec.rb
100
+ - spec/renderers/erb_renderer_spec.rb
101
+ - spec/renderers/markdown_renderer_spec.rb
102
+ - spec/renderers/raw_renderer_spec.rb
103
+ - spec/renderers/ruby_renderer_spec.rb
104
+ - spec/renderers/vanilla_app_detecting_renderer_spec.rb
105
+ - spec/spec_helper.rb
106
+ - spec/tmp/config.yml
107
+ - spec/tmp/soup/current_snip.yml
108
+ - spec/tmp/soup/system.yml
109
+ - spec/vanilla_app_spec.rb
110
+ - spec/vanilla_presenting_spec.rb
111
+ - spec/vanilla_request_spec.rb
112
+ - lib/defensio.rb
113
+ - lib/tasks/vanilla.rake
187
114
  - lib/vanilla/app.rb
188
115
  - lib/vanilla/console.rb
189
116
  - lib/vanilla/dynasnip.rb
117
+ - lib/vanilla/dynasnips/comments.rb
118
+ - lib/vanilla/dynasnips/current_snip.rb
119
+ - lib/vanilla/dynasnips/debug.rb
120
+ - lib/vanilla/dynasnips/edit.rb
121
+ - lib/vanilla/dynasnips/edit_link.rb
122
+ - lib/vanilla/dynasnips/index.rb
123
+ - lib/vanilla/dynasnips/kind.rb
124
+ - lib/vanilla/dynasnips/link_to.rb
125
+ - lib/vanilla/dynasnips/link_to_current_snip.rb
126
+ - lib/vanilla/dynasnips/login.rb
127
+ - lib/vanilla/dynasnips/new.rb
128
+ - lib/vanilla/dynasnips/notes.rb
129
+ - lib/vanilla/dynasnips/pre.rb
130
+ - lib/vanilla/dynasnips/rand.rb
131
+ - lib/vanilla/dynasnips/raw.rb
132
+ - lib/vanilla/dynasnips/url_to.rb
190
133
  - lib/vanilla/renderers/base.rb
191
134
  - lib/vanilla/renderers/bold.rb
192
135
  - lib/vanilla/renderers/erb.rb
193
- - lib/vanilla/renderers/haml.rb
194
136
  - lib/vanilla/renderers/markdown.rb
195
137
  - lib/vanilla/renderers/raw.rb
196
138
  - lib/vanilla/renderers/ruby.rb
197
139
  - lib/vanilla/renderers/textile.rb
198
- - lib/vanilla/renderers.rb
199
140
  - lib/vanilla/request.rb
200
141
  - lib/vanilla/routes.rb
142
+ - lib/vanilla/snip_reference.rb
143
+ - lib/vanilla/snip_reference.treetop
201
144
  - lib/vanilla/snip_reference_parser.rb
202
- - lib/vanilla/static.rb
145
+ - lib/vanilla/snips/start.rb
146
+ - lib/vanilla/snips/system.rb
147
+ - lib/vanilla/snips/tutorial.rb
148
+ - lib/vanilla/soup_with_timestamps.rb
203
149
  - lib/vanilla.rb
204
150
  - bin/vanilla
205
- - pristine_app/config.ru
206
- - pristine_app/Gemfile
207
- - pristine_app/Gemfile.lock
208
- - pristine_app/public/vanilla.css
209
- - pristine_app/README
210
- - pristine_app/soups/base/layout.snip
211
- - pristine_app/soups/base/start.snip
212
- - pristine_app/soups/dynasnips/current_snip.rb
213
- - pristine_app/soups/dynasnips/debug.rb
214
- - pristine_app/soups/dynasnips/index.rb
215
- - pristine_app/soups/dynasnips/link_to.rb
216
- - pristine_app/soups/dynasnips/link_to_current_snip.rb
217
- - pristine_app/soups/dynasnips/page_title.rb
218
- - pristine_app/soups/dynasnips/pre.rb
219
- - pristine_app/soups/dynasnips/raw.rb
220
- - pristine_app/soups/extras/comments.rb
221
- - pristine_app/soups/extras/kind.rb
222
- - pristine_app/soups/extras/rand.rb
223
- - pristine_app/soups/extras/url_to.rb
224
- - pristine_app/soups/tutorial/bad_dynasnip.snip
225
- - pristine_app/soups/tutorial/hello_world.snip
226
- - pristine_app/soups/tutorial/markdown_example.snip
227
- - pristine_app/soups/tutorial/snip.snip
228
- - pristine_app/soups/tutorial/soup.snip
229
- - pristine_app/soups/tutorial/test.snip
230
- - pristine_app/soups/tutorial/textile_example.snip
231
- - pristine_app/soups/tutorial/tutorial-another-snip.snip
232
- - pristine_app/soups/tutorial/tutorial-basic-snip-inclusion.snip
233
- - pristine_app/soups/tutorial/tutorial-dynasnips.snip.markdown
234
- - pristine_app/soups/tutorial/tutorial-layout.snip
235
- - pristine_app/soups/tutorial/tutorial-links.snip
236
- - pristine_app/soups/tutorial/tutorial-renderers.snip.markdown
237
- - pristine_app/soups/tutorial/tutorial.snip.markdown
238
- - pristine_app/soups/tutorial/vanilla-rb.snip
239
- - pristine_app/soups/tutorial/vanilla.snip
151
+ - public/hatch.png
152
+ - public/javascripts/jquery.autogrow-textarea.js
153
+ - public/javascripts/jquery.js
154
+ - public/javascripts/vanilla.js
240
155
  has_rdoc: true
241
156
  homepage: http://github.com/lazyatom/vanilla-rb
242
157
  licenses: []
@@ -248,27 +163,21 @@ rdoc_options:
248
163
  require_paths:
249
164
  - lib
250
165
  required_ruby_version: !ruby/object:Gem::Requirement
251
- none: false
252
166
  requirements:
253
167
  - - ">="
254
168
  - !ruby/object:Gem::Version
255
- hash: 3
256
- segments:
257
- - 0
258
169
  version: "0"
170
+ version:
259
171
  required_rubygems_version: !ruby/object:Gem::Requirement
260
- none: false
261
172
  requirements:
262
173
  - - ">="
263
174
  - !ruby/object:Gem::Version
264
- hash: 3
265
- segments:
266
- - 0
267
175
  version: "0"
176
+ version:
268
177
  requirements: []
269
178
 
270
179
  rubyforge_project: vanilla
271
- rubygems_version: 1.3.7
180
+ rubygems_version: 1.3.3
272
181
  signing_key:
273
182
  specification_version: 3
274
183
  summary: A bliki-type web content thing.
@@ -1,12 +0,0 @@
1
- module Vanilla
2
- module Renderers
3
- autoload :Base, "vanilla/renderers/base"
4
- autoload :Bold, "vanilla/renderers/bold"
5
- autoload :Erb, "vanilla/renderers/erb"
6
- autoload :Haml, "vanilla/renderers/haml"
7
- autoload :Markdown, "vanilla/renderers/markdown"
8
- autoload :Raw, "vanilla/renderers/raw"
9
- autoload :Ruby, "vanilla/renderers/ruby"
10
- autoload :Textile, "vanilla/renderers/textile"
11
- end
12
- end
@@ -1,13 +0,0 @@
1
- require 'haml'
2
-
3
- module Vanilla::Renderers
4
- class Haml < Base
5
- def prepare(snip, part=:content, args=[], enclosing_snip=snip)
6
- @snip = snip
7
- end
8
-
9
- def process_text(content)
10
- ::Haml::Engine.new(content).render(binding)
11
- end
12
- end
13
- end
@@ -1,28 +0,0 @@
1
- require 'rack/utils'
2
-
3
- # Heavily based on ActionDispatch::Static
4
- module Vanilla
5
- class Static
6
- def initialize(app, root)
7
- @app = app
8
- @file_server = ::Rack::File.new(root)
9
- end
10
-
11
- def call(env)
12
- path = env['PATH_INFO'].chomp('/')
13
- method = env['REQUEST_METHOD']
14
-
15
- if %w(GET HEAD).include?(method) && file_exist?(path)
16
- @file_server.call(env)
17
- else
18
- @app.call(env)
19
- end
20
- end
21
-
22
- private
23
- def file_exist?(path)
24
- full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
25
- File.file?(full_path) && File.readable?(full_path)
26
- end
27
- end
28
- end