rhr 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +33 -0
- data/Rakefile +25 -0
- data/Readme.md +24 -0
- data/bin/rhr +47 -0
- data/lib/rhr.rb +6 -0
- data/lib/rhr/server.rb +42 -0
- data/lib/rhr/version.rb +3 -0
- data/rhr.gemspec +13 -0
- data/spec/rhr_spec.rb +97 -0
- data/spec/site/.hidden.html +1 -0
- data/spec/site/Gemfile +1 -0
- data/spec/site/_hidden.html +1 -0
- data/spec/site/_hidden/xxx.html +1 -0
- data/spec/site/index.erb +1 -0
- data/spec/site/people.jpg +0 -0
- data/spec/site/plain.html +1 -0
- data/spec/site/xxx/.hidden.html +1 -0
- data/spec/site/xxx/aaa.html +1 -0
- data/spec/site/xxx/index.erb +1 -0
- data/spec/site/yyy/index.html +1 -0
- data/spec/spec_helper.rb +5 -0
- metadata +116 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rhr (0.1.0)
|
5
|
+
rack
|
6
|
+
tilt
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.1.3)
|
12
|
+
rack (1.3.2)
|
13
|
+
rack-test (0.6.1)
|
14
|
+
rack (>= 1.0)
|
15
|
+
rake (0.9.2)
|
16
|
+
rspec (2.6.0)
|
17
|
+
rspec-core (~> 2.6.0)
|
18
|
+
rspec-expectations (~> 2.6.0)
|
19
|
+
rspec-mocks (~> 2.6.0)
|
20
|
+
rspec-core (2.6.4)
|
21
|
+
rspec-expectations (2.6.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.6.0)
|
24
|
+
tilt (1.3.3)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
rack-test
|
31
|
+
rake
|
32
|
+
rhr!
|
33
|
+
rspec (~> 2)
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
task :default do
|
5
|
+
sh "rspec spec/"
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "start the test-server"
|
9
|
+
task :server do
|
10
|
+
sh "cd spec/site && ../../bin/rhr server"
|
11
|
+
end
|
12
|
+
|
13
|
+
rule /^version:bump:.*/ do |t|
|
14
|
+
sh "git status | grep 'nothing to commit'" # ensure we are not dirty
|
15
|
+
index = ['major', 'minor','patch'].index(t.name.split(':').last)
|
16
|
+
file = 'lib/rhr/version.rb'
|
17
|
+
|
18
|
+
version_file = File.read(file)
|
19
|
+
old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
|
20
|
+
version_parts[index] = version_parts[index].to_i + 1
|
21
|
+
new_version = version_parts * '.'
|
22
|
+
File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
|
23
|
+
|
24
|
+
sh "git add #{file} && git commit -m 'bump version to #{new_version}'"
|
25
|
+
end
|
data/Readme.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Ruby Hypertext Refinement -- the ease of PHP with the elegance of Ruby
|
2
|
+
|
3
|
+
Install
|
4
|
+
=======
|
5
|
+
sudo gem install rhr
|
6
|
+
|
7
|
+
Usage
|
8
|
+
=====
|
9
|
+
echo 'Hello <%= "RHR" %>' > index.erb
|
10
|
+
rhr server
|
11
|
+
--> http://localhost:3000
|
12
|
+
--> http://localhost:3000/index.erb
|
13
|
+
|
14
|
+
- Supports [Erb, Haml, Liquid, ... everything](https://github.com/rtomayko/tilt)
|
15
|
+
- Does not serve Rakefile / Gemfile / Gemfile.lock + everything starting with `_` or `.`
|
16
|
+
|
17
|
+
Author
|
18
|
+
======
|
19
|
+
Initial (crazy) idea by [Steffen Schröder](https://github.com/ChaosSteffen)
|
20
|
+
|
21
|
+
[Michael Grosser](http://grosser.it)<br/>
|
22
|
+
michael@grosser.it<br/>
|
23
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...<br/>
|
24
|
+
[![Build Status](https://secure.travis-ci.org/grosser/rhr.png)](http://travis-ci.org/grosser/rhr)
|
data/bin/rhr
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
require 'rubygems'
|
4
|
+
require 'optparse'
|
5
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
6
|
+
|
7
|
+
def parse_options
|
8
|
+
options = {}
|
9
|
+
parser = OptionParser.new do |opts|
|
10
|
+
opts.banner = <<BANNER
|
11
|
+
Ruby Hypertext Refinement
|
12
|
+
|
13
|
+
Usage:
|
14
|
+
echo 'Hello <%= "RHR" %>' > index.erb
|
15
|
+
rhr server
|
16
|
+
--> http://localhost:3000
|
17
|
+
|
18
|
+
Options:
|
19
|
+
BANNER
|
20
|
+
opts.on("-p", "--port PORT","Port for server") {|i| options[:port] = i }
|
21
|
+
opts.on("-v", "--version","Show Version"){
|
22
|
+
require 'rhr/version'
|
23
|
+
puts RHR::VERSION
|
24
|
+
exit
|
25
|
+
}
|
26
|
+
opts.on("-h", "--help","Show this.") { puts opts; exit }
|
27
|
+
end
|
28
|
+
parser.parse!
|
29
|
+
|
30
|
+
if ARGV.empty?
|
31
|
+
puts parser
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
|
35
|
+
options
|
36
|
+
end
|
37
|
+
|
38
|
+
options = parse_options
|
39
|
+
ARGV.shift == 'server' or raise('did you forget "server" ?')
|
40
|
+
|
41
|
+
require 'rhr'
|
42
|
+
|
43
|
+
Rack::Server.new(
|
44
|
+
:app => RHR::Server.new,
|
45
|
+
:Port => options[:port] || 3000,
|
46
|
+
:server => 'webrick'
|
47
|
+
).start
|
data/lib/rhr.rb
ADDED
data/lib/rhr/server.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module RHR
|
2
|
+
class Server
|
3
|
+
def initialize
|
4
|
+
@files = Dir["**/*"] - ['Gemfile','Gemfile.lock','Rakefile']
|
5
|
+
@files -= @files.grep(/(^|\/)_/)
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
path = env['PATH_INFO']
|
10
|
+
if template = find_template(path)
|
11
|
+
if renderer = Tilt[template]
|
12
|
+
body = renderer.new(template).render
|
13
|
+
[200, {}, [body]]
|
14
|
+
else
|
15
|
+
Rack::File.new('.').call(env.merge('PATH_INFO' => template))
|
16
|
+
end
|
17
|
+
else
|
18
|
+
[404, {}, ['404 File not found']]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def find_template(path)
|
25
|
+
file = path.dup
|
26
|
+
file.sub!('/','')
|
27
|
+
file.sub!(/\/$/,'')
|
28
|
+
is_root = (file == '')
|
29
|
+
|
30
|
+
return if not is_root and not @files.index(file)
|
31
|
+
|
32
|
+
if is_root or File.directory?(file)
|
33
|
+
# folder -> find an index file
|
34
|
+
file << '/' unless is_root
|
35
|
+
@files.grep(/^#{Regexp.escape file}index\.[^\/]+$/).first
|
36
|
+
else
|
37
|
+
# just another normal template
|
38
|
+
file
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/rhr/version.rb
ADDED
data/rhr.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
require 'rhr/version'
|
3
|
+
|
4
|
+
Gem::Specification.new "rhr", RHR::VERSION do |s|
|
5
|
+
s.summary = "Ruby Hypertext Refinement -- the ease of PHP with the elegance of Ruby"
|
6
|
+
s.authors = ["Michael Grosser"]
|
7
|
+
s.email = "michael@grosser.it"
|
8
|
+
s.homepage = "http://github.com/grosser/rhr"
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
|
11
|
+
s.add_dependency 'rack'
|
12
|
+
s.add_dependency 'tilt'
|
13
|
+
end
|
data/spec/rhr_spec.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RHR do
|
4
|
+
def rhr(command)
|
5
|
+
`cd spec/site && ../../bin/rhr #{command}`
|
6
|
+
end
|
7
|
+
|
8
|
+
it "has a VERSION" do
|
9
|
+
RHR::VERSION.should =~ /^[\.\da-z]+$/
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a commandline version" do
|
13
|
+
rhr("-v").should =~ /^[\.\da-z]+$/m
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a commandline help" do
|
17
|
+
rhr("-h").should =~ /Ruby Hypertext Refinement/
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'server' do
|
21
|
+
include Rack::Test::Methods
|
22
|
+
|
23
|
+
before :all do
|
24
|
+
Dir.chdir 'spec/site'
|
25
|
+
end
|
26
|
+
|
27
|
+
def app
|
28
|
+
RHR::Server.new
|
29
|
+
end
|
30
|
+
|
31
|
+
it "can get /" do
|
32
|
+
get '/'
|
33
|
+
last_response.body.should == 'TEST'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "evaluates erb files" do
|
37
|
+
get '/index.erb'
|
38
|
+
last_response.body.should == 'TEST'
|
39
|
+
last_response.content_type.should == 'text/html'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "can get static files" do
|
43
|
+
get '/plain.html'
|
44
|
+
last_response.body.should == "<%= 'TEST' %>\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not server monkey paths" do
|
48
|
+
get '/xxx/../plain.html'
|
49
|
+
last_response.status.should == 404
|
50
|
+
end
|
51
|
+
|
52
|
+
it "can get nested index.erb" do
|
53
|
+
get '/xxx'
|
54
|
+
last_response.body.should == "NESTED"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "can get nested index.erb with trailing slash" do
|
58
|
+
get '/xxx/'
|
59
|
+
last_response.body.should == "NESTED"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "can get nested index without template language" do
|
63
|
+
get '/yyy'
|
64
|
+
last_response.body.should == "Foo\n"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "can get static files with correct content-type" do
|
68
|
+
get "/people.jpg"
|
69
|
+
last_response.content_type.should == 'image/jpeg'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "ignores common ruby files" do
|
73
|
+
get "/Gemfile"
|
74
|
+
last_response.status.should == 404
|
75
|
+
end
|
76
|
+
|
77
|
+
it "ignores _files" do
|
78
|
+
get "/_hidden.html"
|
79
|
+
last_response.status.should == 404
|
80
|
+
end
|
81
|
+
|
82
|
+
it "ignores .files" do
|
83
|
+
get "/.hidden.html"
|
84
|
+
last_response.status.should == 404
|
85
|
+
end
|
86
|
+
|
87
|
+
it "ignores hidden folders" do
|
88
|
+
get "/_hidden/xxx.html"
|
89
|
+
last_response.status.should == 404
|
90
|
+
end
|
91
|
+
|
92
|
+
it "ignores nested hidden" do
|
93
|
+
get "/xxx/.hidden.html"
|
94
|
+
last_response.status.should == 404
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
HIDDEN
|
data/spec/site/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
xxx
|
@@ -0,0 +1 @@
|
|
1
|
+
HIDDEN
|
@@ -0,0 +1 @@
|
|
1
|
+
HIDDEN
|
data/spec/site/index.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<%= 'TEST' %>
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= 'TEST' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
HIDDEN
|
@@ -0,0 +1 @@
|
|
1
|
+
PLOP
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= 'NESTED' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Foo
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rhr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Grosser
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-04 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
name: rack
|
33
|
+
version_requirements: *id001
|
34
|
+
prerelease: false
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
name: tilt
|
47
|
+
version_requirements: *id002
|
48
|
+
prerelease: false
|
49
|
+
description:
|
50
|
+
email: michael@grosser.it
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .travis.yml
|
59
|
+
- Gemfile
|
60
|
+
- Gemfile.lock
|
61
|
+
- Rakefile
|
62
|
+
- Readme.md
|
63
|
+
- bin/rhr
|
64
|
+
- lib/rhr.rb
|
65
|
+
- lib/rhr/server.rb
|
66
|
+
- lib/rhr/version.rb
|
67
|
+
- rhr.gemspec
|
68
|
+
- spec/rhr_spec.rb
|
69
|
+
- spec/site/.hidden.html
|
70
|
+
- spec/site/Gemfile
|
71
|
+
- spec/site/_hidden.html
|
72
|
+
- spec/site/_hidden/xxx.html
|
73
|
+
- spec/site/index.erb
|
74
|
+
- spec/site/people.jpg
|
75
|
+
- spec/site/plain.html
|
76
|
+
- spec/site/xxx/.hidden.html
|
77
|
+
- spec/site/xxx/aaa.html
|
78
|
+
- spec/site/xxx/index.erb
|
79
|
+
- spec/site/yyy/index.html
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: http://github.com/grosser/rhr
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 1.6.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: Ruby Hypertext Refinement -- the ease of PHP with the elegance of Ruby
|
115
|
+
test_files: []
|
116
|
+
|