RHP 0.0.2a
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +23 -0
- data/Rakefile +2 -0
- data/bin/rhp +45 -0
- data/lib/rhp.rb +80 -0
- data/lib/rhp/config.ru +1 -0
- data/lib/rhp/version.rb +3 -0
- data/rhp.gemspec +22 -0
- metadata +104 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
= RHP: Hypertext Preprocessor.
|
2
|
+
|
3
|
+
== Usage
|
4
|
+
First install the RHP gem:
|
5
|
+
$: sudo gem i rhp
|
6
|
+
|
7
|
+
Next, pick or create a directory with some files to serve:
|
8
|
+
$: mkdir site
|
9
|
+
$: cd site
|
10
|
+
$: echo '%h1 hello from HAML' > index.html.haml
|
11
|
+
|
12
|
+
Now start the server:
|
13
|
+
$: rhp
|
14
|
+
|
15
|
+
That's it!
|
16
|
+
|
17
|
+
|
18
|
+
== More info
|
19
|
+
|
20
|
+
RHP is probably buggy and definitely a security risk. It should not be used by anyone under any circumstances. Luckily ruby has no shortage of solid, innovative and well-thought-out web frameworks for you to pick from.
|
21
|
+
|
22
|
+
|
23
|
+
Development by Arthur Gunn.
|
data/Rakefile
ADDED
data/bin/rhp
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# require File.expand_path('../../lib/rhp', __FILE__)
|
3
|
+
require 'rhp'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
usage = <<USAGE
|
7
|
+
Usage: rhp <options>
|
8
|
+
|
9
|
+
To use rhp, cd to your sites base public directory, and run.
|
10
|
+
|
11
|
+
Options
|
12
|
+
-p, --port The port to run RHP from. Default: 2718
|
13
|
+
USAGE
|
14
|
+
|
15
|
+
options = {
|
16
|
+
:port => 2718,
|
17
|
+
:config => File.expand_path("../../lib/rhp/config.ru", __FILE__)
|
18
|
+
}
|
19
|
+
|
20
|
+
ARGV.options do |o|
|
21
|
+
o.on("-p", "--port") do |port|
|
22
|
+
options[:port] = port
|
23
|
+
end
|
24
|
+
|
25
|
+
# o.on("-c", "--config") do |config|
|
26
|
+
# options[:config] = File.expand_path(config, Dir.pwd)
|
27
|
+
# end
|
28
|
+
|
29
|
+
o.on_tail("-h", "--help") { puts usage; exit }
|
30
|
+
|
31
|
+
o.parse!
|
32
|
+
end
|
33
|
+
|
34
|
+
project_path = ARGV.first || '.'
|
35
|
+
RHP::Server.project_root = File.expand_path(project_path, Dir.pwd)
|
36
|
+
|
37
|
+
|
38
|
+
server = Rack::Server.new.tap do |s|
|
39
|
+
s.options[:config] = options[:config]
|
40
|
+
s.options[:Port] = options[:port]
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
puts "RHP started at http://0.0.0.0:#{options[:port]}/ from #{project_path}\n"
|
45
|
+
server.start
|
data/lib/rhp.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require "rack"
|
2
|
+
require "tilt"
|
3
|
+
|
4
|
+
module RHP
|
5
|
+
class Server
|
6
|
+
class << self
|
7
|
+
def project_root=(path)
|
8
|
+
@@project_root = path
|
9
|
+
end
|
10
|
+
|
11
|
+
def project_root
|
12
|
+
@@project_root
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
file_request = FileRequest.new(env["PATH_INFO"])
|
17
|
+
|
18
|
+
[200, {"Content-Type" => file_request.mime_type}, [file_request.content]]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class FileRequest
|
24
|
+
attr_accessor :request_path
|
25
|
+
EXTENSIONS_REGEX = "\\.(#{Tilt.mappings.keys.join('|')})$"
|
26
|
+
|
27
|
+
def initialize(path)
|
28
|
+
# /pages/
|
29
|
+
self.request_path = path.gsub(/\/$/, "/index.html").gsub(/^\//, "")
|
30
|
+
self.request_path = "#{self.request_path}/index.html" if File.directory?(raw_file_path)
|
31
|
+
# pages/index.html
|
32
|
+
end
|
33
|
+
|
34
|
+
def content
|
35
|
+
if Tilt.mappings.keys.include?(extension)
|
36
|
+
"Files with the .#{extension} extension may not be accessed directly."
|
37
|
+
elsif File.file?(raw_file_path.to_s)
|
38
|
+
File.read(raw_file_path)
|
39
|
+
elsif File.file?(template_path.to_s)
|
40
|
+
Tilt.new(template_path).render
|
41
|
+
else
|
42
|
+
"ERROR!"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def mime_type
|
47
|
+
Rack::Mime::mime_type(".#{extension}", "text/html")
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
def raw_file_path
|
53
|
+
File.expand_path(request_path, Server.project_root)
|
54
|
+
# /Users/.. ../site/public/pages/index.html
|
55
|
+
end
|
56
|
+
|
57
|
+
def template_path
|
58
|
+
Dir.glob("#{raw_file_path}*").find do |file|
|
59
|
+
/#{raw_file_path}#{EXTENSIONS_REGEX}/ === file
|
60
|
+
end
|
61
|
+
# /Users/.. ../site/public/pages/index.html.haml
|
62
|
+
end
|
63
|
+
|
64
|
+
def request_filename
|
65
|
+
request_path.split("/").last
|
66
|
+
# index.html
|
67
|
+
end
|
68
|
+
|
69
|
+
def template_extension
|
70
|
+
template_path.split(".").last
|
71
|
+
# haml
|
72
|
+
end
|
73
|
+
|
74
|
+
def extension
|
75
|
+
request_filename.split(".").last
|
76
|
+
# html
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/lib/rhp/config.ru
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
run RHP::Server
|
data/lib/rhp/version.rb
ADDED
data/rhp.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rhp/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "RHP"
|
7
|
+
s.version = RHP::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Arthur Gunn"]
|
10
|
+
s.email = ["arthur@gunn.co.nz"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{The RHP (or ruby) Hypertext Preprocessor. (VaporWare)}
|
13
|
+
s.description = %q{Pages are written in any templating language supported by the tilt gem. Routes are based only on directory structure and file names. Simple!}
|
14
|
+
|
15
|
+
s.add_dependency "rack", "~>1.2.0"
|
16
|
+
s.add_dependency "tilt", "~>1.2.0"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: RHP
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: true
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2a
|
9
|
+
version: 0.0.2a
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Arthur Gunn
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-17 00:00:00 +13:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rack
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 2
|
31
|
+
- 0
|
32
|
+
version: 1.2.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: tilt
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 2
|
46
|
+
- 0
|
47
|
+
version: 1.2.0
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: Pages are written in any templating language supported by the tilt gem. Routes are based only on directory structure and file names. Simple!
|
51
|
+
email:
|
52
|
+
- arthur@gunn.co.nz
|
53
|
+
executables:
|
54
|
+
- rhp
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- .gitignore
|
61
|
+
- Gemfile
|
62
|
+
- README.rdoc
|
63
|
+
- Rakefile
|
64
|
+
- bin/rhp
|
65
|
+
- lib/rhp.rb
|
66
|
+
- lib/rhp/config.ru
|
67
|
+
- lib/rhp/version.rb
|
68
|
+
- rhp.gemspec
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: ""
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 1
|
93
|
+
- 3
|
94
|
+
- 1
|
95
|
+
version: 1.3.1
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.3.7
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: The RHP (or ruby) Hypertext Preprocessor. (VaporWare)
|
103
|
+
test_files: []
|
104
|
+
|