verb 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/verb.rb +47 -0
- metadata +64 -0
data/lib/verb.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
class Verb
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
base_path = File.join(Dir.pwd, env["PATH_INFO"].sub(/\/$/, ""))
|
10
|
+
exact_path = base_path + ".rhtml"
|
11
|
+
index_path = File.join(base_path, "index.rhtml")
|
12
|
+
|
13
|
+
if File.exists?(exact_path)
|
14
|
+
render(exact_path, env)
|
15
|
+
elsif File.exists?(index_path)
|
16
|
+
render(index_path, env)
|
17
|
+
else
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def render(path, env)
|
23
|
+
@erb_output = ""
|
24
|
+
@render_path = path
|
25
|
+
|
26
|
+
@request = Rack::Request.new(env)
|
27
|
+
@response = Rack::Response.new
|
28
|
+
|
29
|
+
@response["Content-Type"] = "text/html"
|
30
|
+
|
31
|
+
ERB.new(File.open(path) { |f| f.read }, nil, nil, "@erb_output").result(binding)
|
32
|
+
|
33
|
+
@response.write(@erb_output)
|
34
|
+
|
35
|
+
@response.finish
|
36
|
+
end
|
37
|
+
|
38
|
+
def layout(name = "layout")
|
39
|
+
layout_path = File.join(File.dirname(@render_path), name + ".rhtml")
|
40
|
+
|
41
|
+
if File.exists?(layout_path)
|
42
|
+
ERB.new(File.open(layout_path) { |f| f.read }, nil, nil, "@erb_output").result(binding)
|
43
|
+
else
|
44
|
+
yield
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: verb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Nick Chapman
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-05-12 00:00:00 -07:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: Verb is Rack middleware that serves RHTML files.
|
21
|
+
email:
|
22
|
+
- nchapman@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/verb.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/nchapman/verb
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 1
|
53
|
+
- 3
|
54
|
+
- 6
|
55
|
+
version: 1.3.6
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.6
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Serve RHTML in Rack
|
63
|
+
test_files: []
|
64
|
+
|