rubai 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gem "rack"
data/Gemfile.lock ADDED
@@ -0,0 +1,10 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ rack (1.4.1)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ rack
data/Readme.md ADDED
@@ -0,0 +1,12 @@
1
+ How To
2
+ ======
3
+
4
+ `gem install rubai`
5
+
6
+ In any directory with static content do a `rubai`.
7
+
8
+ Done.
9
+
10
+ Collaborations
11
+ ==============
12
+ @seixasfelipe
data/bin/rubai ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubai/cli'
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,3 @@
1
+ require "rack"
2
+ require "rubai"
3
+ Rack::Server.start app: Rubai::RackApp.new
@@ -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.1
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-07-20 00:00:00.000000000 Z
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.22
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