rubai 0.0.1 → 0.1.0
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/.gitignore +2 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +10 -0
- data/Readme.md +12 -0
- data/bin/rubai +2 -0
- data/lib/rubai.rb +16 -0
- data/lib/rubai/cli.rb +3 -0
- data/lib/rubai/mime_type.rb +20 -0
- data/lib/rubai/rack_app.rb +38 -0
- data/lib/rubai/response.rb +37 -0
- data/rubai.gemspec +20 -0
- metadata +17 -5
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/Readme.md
ADDED
data/bin/rubai
ADDED
data/lib/rubai.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubai/mime_type'
|
2
|
+
require 'rubai/response'
|
3
|
+
require 'rubai/rack_app'
|
4
|
+
|
5
|
+
module Rubai
|
6
|
+
def self.mimes
|
7
|
+
@types ||= {
|
8
|
+
css: "text/css",
|
9
|
+
html: "text/html",
|
10
|
+
js: "text/javascript",
|
11
|
+
png: "image/png",
|
12
|
+
jpg: "image/jpeg",
|
13
|
+
gif: "image/gif"
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
data/lib/rubai/cli.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rubai
|
2
|
+
class MimeType
|
3
|
+
def initialize(type)
|
4
|
+
@mime_name = type;
|
5
|
+
@content_type = Rubai.mimes.fetch(type.to_sym) { Rubai.mimes[:html] }
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.new_with_extension(extension)
|
9
|
+
new(extension.to_sym)
|
10
|
+
end
|
11
|
+
|
12
|
+
def content_type
|
13
|
+
@content_type
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
content_type
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Rubai
|
2
|
+
class RackApp
|
3
|
+
def path
|
4
|
+
if env["PATH_INFO"] == "/"
|
5
|
+
path = "index.html"
|
6
|
+
else
|
7
|
+
path = "./#{env["PATH_INFO"]}"
|
8
|
+
end
|
9
|
+
path
|
10
|
+
end
|
11
|
+
|
12
|
+
def env
|
13
|
+
@env
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
@env = env
|
18
|
+
|
19
|
+
unless File.file?(path)
|
20
|
+
response = Response.new
|
21
|
+
response.status = 404
|
22
|
+
response.content_type = MimeType.new(:html).content_type
|
23
|
+
# TODO: this response should be configurable
|
24
|
+
response << "<html>"
|
25
|
+
response << " <body>"
|
26
|
+
response << " NO!"
|
27
|
+
response << " </body>"
|
28
|
+
response << "</html>"
|
29
|
+
return response.for_rack
|
30
|
+
end
|
31
|
+
|
32
|
+
extension = File.extname(path)
|
33
|
+
mime_type = MimeType.new(extension)
|
34
|
+
response = Response.new 200, mime_type.content_type, [File.read(path)]
|
35
|
+
response.for_rack
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Rubai
|
2
|
+
class Response
|
3
|
+
def initialize(status = 200, content_type = "text/html", body=[])
|
4
|
+
@status = status
|
5
|
+
self.content_type= content_type
|
6
|
+
@body = body
|
7
|
+
end
|
8
|
+
|
9
|
+
def headers
|
10
|
+
@headers ||= {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def body
|
14
|
+
@body ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def <<(body_text)
|
18
|
+
body << body_text
|
19
|
+
end
|
20
|
+
|
21
|
+
def []=(header, value)
|
22
|
+
headers[header] = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def content_type=(content_type)
|
26
|
+
self["Content-Type"] = content_type
|
27
|
+
end
|
28
|
+
|
29
|
+
def status=(status)
|
30
|
+
@status = status
|
31
|
+
end
|
32
|
+
|
33
|
+
def for_rack
|
34
|
+
[@status, headers, @body]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/rubai.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = "rubai"
|
4
|
+
s.version = "0.1.0"
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.authors = ["Ricardo Valeriano"]
|
7
|
+
s.email = ["ricardo.valeriano@gmail.com"]
|
8
|
+
s.homepage = "http://github.com/ricardovaleriano/rubai"
|
9
|
+
s.summary = "Simple local http server for your local dirs"
|
10
|
+
s.description = <<SUM
|
11
|
+
Simple local http server for your local dirs
|
12
|
+
SUM
|
13
|
+
s.required_rubygems_version = ">= 0"
|
14
|
+
|
15
|
+
s.require_path = 'lib'
|
16
|
+
s.files = `git ls-files | sed 's/examples.*//'`.split("\n").reject{|f| f == ""}
|
17
|
+
|
18
|
+
s.add_dependency 'rack'
|
19
|
+
s.executables = ['rubai']
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
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: 2012-
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -32,10 +32,22 @@ description: ! ' Simple local http server for your local dirs
|
|
32
32
|
'
|
33
33
|
email:
|
34
34
|
- ricardo.valeriano@gmail.com
|
35
|
-
executables:
|
35
|
+
executables:
|
36
|
+
- rubai
|
36
37
|
extensions: []
|
37
38
|
extra_rdoc_files: []
|
38
|
-
files:
|
39
|
+
files:
|
40
|
+
- .gitignore
|
41
|
+
- Gemfile
|
42
|
+
- Gemfile.lock
|
43
|
+
- Readme.md
|
44
|
+
- bin/rubai
|
45
|
+
- lib/rubai.rb
|
46
|
+
- lib/rubai/cli.rb
|
47
|
+
- lib/rubai/mime_type.rb
|
48
|
+
- lib/rubai/rack_app.rb
|
49
|
+
- lib/rubai/response.rb
|
50
|
+
- rubai.gemspec
|
39
51
|
homepage: http://github.com/ricardovaleriano/rubai
|
40
52
|
licenses: []
|
41
53
|
post_install_message:
|
@@ -56,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
68
|
version: '0'
|
57
69
|
requirements: []
|
58
70
|
rubyforge_project:
|
59
|
-
rubygems_version: 1.8.
|
71
|
+
rubygems_version: 1.8.23
|
60
72
|
signing_key:
|
61
73
|
specification_version: 3
|
62
74
|
summary: Simple local http server for your local dirs
|