nimble_framework 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/nimble_framework.rb +68 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 708b35ecd5f97b3ad7d7dd775704b5677a9a9268
|
4
|
+
data.tar.gz: 13335a7dcbecf5372852dcf712b445d0d2c9404e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73777da017ea8fad01da2d37611da0a4c8b01c00e5abd29a619f79aab637ee9be43bff18e37acf9eb2d102f4cb952ac2725697780a4c9d4f20c783646f69a712
|
7
|
+
data.tar.gz: e42b4b4aa172c9c546a805d604b44dbcfc236fef4b18990b6db54bb6a97992200408f678b19a1ae7e6eec63e208f75dbab35325937ccd2690cb8ba5ba13e9aee
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'tilt'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module Nimble
|
6
|
+
|
7
|
+
class Main
|
8
|
+
@@routes = Hash.new { |hash, key| hash[key] = Hash.new }
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :routes
|
12
|
+
|
13
|
+
def get(route, &block)
|
14
|
+
@@routes['GET'][route] = block
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(route, &block)
|
18
|
+
@@routes['POST'][route] = block
|
19
|
+
end
|
20
|
+
|
21
|
+
def put(route, &block)
|
22
|
+
@@routes['PUT'][route] = block
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(route, &block)
|
26
|
+
@@routes['DELETE'][route] = block
|
27
|
+
end
|
28
|
+
|
29
|
+
def erb(view_name, locals = {})
|
30
|
+
path = ::File.join("views", "#{view_name.to_s}.html.erb")
|
31
|
+
template = Tilt.new(path)
|
32
|
+
template.render(nil, locals)
|
33
|
+
end
|
34
|
+
|
35
|
+
def session
|
36
|
+
@request.session
|
37
|
+
end
|
38
|
+
|
39
|
+
def params
|
40
|
+
@params
|
41
|
+
end
|
42
|
+
|
43
|
+
def redirect_to(path)
|
44
|
+
@response['Location'] = path
|
45
|
+
@response.status = 303
|
46
|
+
"Redirect!"
|
47
|
+
end
|
48
|
+
|
49
|
+
def call(env)
|
50
|
+
@request = Rack::Request.new(env)
|
51
|
+
block = @@routes[@request.request_method][@request.path_info]
|
52
|
+
if block
|
53
|
+
@params = @request.params
|
54
|
+
@response = Rack::Response.new
|
55
|
+
@response.body = [block.call]
|
56
|
+
@response.header ||= {}
|
57
|
+
@response.status ||= 200
|
58
|
+
@response.finish
|
59
|
+
else
|
60
|
+
[404, {}, ["Page not found"]]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nimble_framework
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anna Sheaffer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Lightweight Ruby web framework
|
14
|
+
email: annasheaffer@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/nimble_framework.rb
|
20
|
+
homepage: http://rubygems.org/gems/nimble_framework
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.0.preview.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Nimble!
|
44
|
+
test_files: []
|
45
|
+
has_rdoc:
|