lithium 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -1
- data/README.md +27 -14
- data/lib/lithium.rb +6 -3
- data/lib/lithium/base.rb +150 -0
- data/lib/lithium/modules/templates/erb.rb +11 -0
- data/lib/lithium/modules/templates/slim.rb +19 -0
- data/lib/lithium/version.rb +1 -1
- metadata +26 -55
- data/.gitignore +0 -22
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -2
- data/lithium.gemspec +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d20b742247809e17b6784aeae96cac85981cedc
|
4
|
+
data.tar.gz: b6009b546724ffde5b29820e23d6ecfa57862f69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 909d65c818d90627ca6279187225b2d31f48187bcc82a0c7dcd1fcb22355382a77a4cd7aa5c5df22ab6bbad6c3a45c06724a56eea3217cb6a9b06c41666f0e9c
|
7
|
+
data.tar.gz: 0ca0144f25c8f229de6898fa0fad1bbd815c3b7e698b5d997be48a9f461225b20e611e66edb70814aa04a91e181889a09ab702aa138b1adbafb1988ab690ce8a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,42 @@
|
|
1
|
-
# Lithium
|
1
|
+
# Lithium.
|
2
|
+
Small web framework.
|
2
3
|
|
3
|
-
|
4
|
+
```ruby
|
5
|
+
# lithium_test.rb
|
4
6
|
|
5
|
-
|
7
|
+
require 'lithium'
|
8
|
+
class App < Lithium::Base
|
9
|
+
get '/' do
|
10
|
+
'Hello world!'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
```
|
6
14
|
|
7
|
-
|
15
|
+
```ruby
|
16
|
+
# config.ru
|
8
17
|
|
9
|
-
|
18
|
+
require './app'
|
10
19
|
|
11
|
-
|
20
|
+
run FirstApp
|
12
21
|
|
13
|
-
|
22
|
+
```
|
14
23
|
|
15
|
-
Or install it yourself as:
|
16
24
|
|
17
|
-
|
25
|
+
Run the file:
|
18
26
|
|
19
|
-
|
27
|
+
```bash
|
28
|
+
rackup
|
29
|
+
```
|
30
|
+
Install the gem:
|
20
31
|
|
21
|
-
|
32
|
+
```bash
|
33
|
+
gem install lithium
|
34
|
+
```
|
22
35
|
|
23
|
-
|
36
|
+
# Contributing
|
24
37
|
|
25
|
-
1. Fork it
|
38
|
+
1. Fork it
|
26
39
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
40
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
41
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create
|
42
|
+
5. Create new Pull Request
|
data/lib/lithium.rb
CHANGED
data/lib/lithium/base.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Lithium
|
4
|
+
|
5
|
+
class Request < Rack::Request
|
6
|
+
def initialize(env)
|
7
|
+
env['PATH_INFO'] = '/' if env['PATH_INFO'].empty?
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
class Response
|
14
|
+
attr_accessor :status
|
15
|
+
attr_reader :headers, :body
|
16
|
+
extend Forwardable
|
17
|
+
def_delegators :headers, :[], :[]=
|
18
|
+
|
19
|
+
def initialize(body = [], status = 200, headers = { 'Content-Type' => 'text/html; charset=utf-8' })
|
20
|
+
@body, @headers, @status = [], headers, status
|
21
|
+
@length = 0
|
22
|
+
|
23
|
+
if body.respond_to? :to_str
|
24
|
+
write body.to_str
|
25
|
+
elsif body.respond_to? :each
|
26
|
+
body.each { |i| write i.to_s }
|
27
|
+
else
|
28
|
+
raise TypeError, 'body must #respond_to? #to_str or #each'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def finish
|
33
|
+
unless (100..199).include?(status) || status == 204
|
34
|
+
headers['Content-Length'] = @length.to_s
|
35
|
+
end
|
36
|
+
[status, headers, body]
|
37
|
+
end
|
38
|
+
|
39
|
+
def redirect(target, status = 302)
|
40
|
+
self.status = status
|
41
|
+
headers['Location'] = target
|
42
|
+
end
|
43
|
+
|
44
|
+
def write(string)
|
45
|
+
s = string.to_s
|
46
|
+
@length += s.bytesize
|
47
|
+
|
48
|
+
body << s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
class Base
|
54
|
+
class << self
|
55
|
+
extend Forwardable
|
56
|
+
|
57
|
+
def_delegators :stack, :map, :use
|
58
|
+
|
59
|
+
%w(DELETE GET HEAD OPTIONS PATCH POST PUT).each do |verb|
|
60
|
+
define_method(verb.downcase) { |path, &block| routes[verb] << compile_route(path, &block) }
|
61
|
+
end
|
62
|
+
|
63
|
+
%w(before after).each do |filter|
|
64
|
+
define_method(filter) do |&block|
|
65
|
+
filters[filter.to_sym] = block
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
alias :_new :new
|
70
|
+
def new(*args, &block)
|
71
|
+
stack.run _new(*args, &block)
|
72
|
+
stack
|
73
|
+
end
|
74
|
+
|
75
|
+
def call(env)
|
76
|
+
new.call env
|
77
|
+
end
|
78
|
+
|
79
|
+
def routes
|
80
|
+
@routes ||= Hash.new { |hash, key| hash[key] = [] }
|
81
|
+
end
|
82
|
+
|
83
|
+
def filters
|
84
|
+
@filters ||= Hash.new
|
85
|
+
end
|
86
|
+
|
87
|
+
def stack
|
88
|
+
@stack ||= Rack::Builder.new
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def compile_route(path, &block)
|
94
|
+
route = { block: block, pattern: nil, extra_params: [], path: path }
|
95
|
+
|
96
|
+
pattern = path.gsub(/:\w+/) do |match|
|
97
|
+
route[:extra_params] << match.gsub(':', '').to_sym
|
98
|
+
"([^/?#]+)"
|
99
|
+
end
|
100
|
+
route[:pattern] = /^#{pattern}$/
|
101
|
+
route
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
attr_reader :env, :request, :response
|
106
|
+
|
107
|
+
def call(env)
|
108
|
+
dup.call env
|
109
|
+
end
|
110
|
+
|
111
|
+
def call(env)
|
112
|
+
@env = env
|
113
|
+
@request = Lithium::Request.new @env
|
114
|
+
@response = Lithium::Response.new
|
115
|
+
catch(:halt) { run_route }
|
116
|
+
end
|
117
|
+
|
118
|
+
def halt(response)
|
119
|
+
throw :halt, response
|
120
|
+
end
|
121
|
+
|
122
|
+
def session
|
123
|
+
request.env["rack.session"] || raise("Rack::Session handler is missing")
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
def run_route
|
129
|
+
route = self.class.routes[request.request_method].detect do |r|
|
130
|
+
r[:pattern] =~ request.path_info
|
131
|
+
end
|
132
|
+
if route
|
133
|
+
$~.captures.each_with_index do |value, index|
|
134
|
+
param = route[:extra_params][index]
|
135
|
+
request.params[param] = value
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
if route
|
140
|
+
instance_exec(&self.class.filters[:before]) if self.class.filters[:before]
|
141
|
+
response.write instance_eval(&route[:block])
|
142
|
+
instance_exec(&self.class.filters[:after]) if self.class.filters[:after]
|
143
|
+
else
|
144
|
+
response.status = 404
|
145
|
+
end
|
146
|
+
|
147
|
+
response.finish
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
require 'slim'
|
3
|
+
module Lithium
|
4
|
+
module Modules
|
5
|
+
module Templates
|
6
|
+
module Slim
|
7
|
+
def render template, locals = {}, options = {}, &block
|
8
|
+
template_cache.fetch(template) do
|
9
|
+
::Slim::Template.new(template, options)
|
10
|
+
end.render(self, locals, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def template_cache
|
14
|
+
Thread.current[:templates_cache] ||= Tilt::Cache.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/lithium/version.rb
CHANGED
metadata
CHANGED
@@ -1,101 +1,72 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lithium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Sedat
|
7
|
+
- Sedat CIFTCI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.6'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.6'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
17
|
+
- - ">="
|
39
18
|
- !ruby/object:Gem::Version
|
40
19
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: Dysnomia
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.0.2
|
48
20
|
type: :runtime
|
49
21
|
prerelease: false
|
50
22
|
version_requirements: !ruby/object:Gem::Requirement
|
51
23
|
requirements:
|
52
|
-
- -
|
24
|
+
- - ">="
|
53
25
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
26
|
+
version: '0'
|
55
27
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
28
|
+
name: tilt
|
57
29
|
requirement: !ruby/object:Gem::Requirement
|
58
30
|
requirements:
|
59
|
-
- -
|
31
|
+
- - ">="
|
60
32
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
33
|
+
version: '0'
|
62
34
|
type: :runtime
|
63
35
|
prerelease: false
|
64
36
|
version_requirements: !ruby/object:Gem::Requirement
|
65
37
|
requirements:
|
66
|
-
- -
|
38
|
+
- - ">="
|
67
39
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0
|
40
|
+
version: '0'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
42
|
+
name: slim
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
72
44
|
requirements:
|
73
|
-
- -
|
45
|
+
- - ">="
|
74
46
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
47
|
+
version: '0'
|
76
48
|
type: :runtime
|
77
49
|
prerelease: false
|
78
50
|
version_requirements: !ruby/object:Gem::Requirement
|
79
51
|
requirements:
|
80
|
-
- -
|
52
|
+
- - ">="
|
81
53
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
83
|
-
description:
|
54
|
+
version: '0'
|
55
|
+
description: Ruby minimalistic microframework.
|
84
56
|
email:
|
85
57
|
- me@sedat.us
|
86
58
|
executables: []
|
87
59
|
extensions: []
|
88
60
|
extra_rdoc_files: []
|
89
61
|
files:
|
90
|
-
- .gitignore
|
91
62
|
- Gemfile
|
92
|
-
- LICENSE.txt
|
93
63
|
- README.md
|
94
|
-
- Rakefile
|
95
64
|
- lib/lithium.rb
|
65
|
+
- lib/lithium/base.rb
|
66
|
+
- lib/lithium/modules/templates/erb.rb
|
67
|
+
- lib/lithium/modules/templates/slim.rb
|
96
68
|
- lib/lithium/version.rb
|
97
|
-
|
98
|
-
homepage: ''
|
69
|
+
homepage: https://github.com/amerobin/lithium
|
99
70
|
licenses:
|
100
71
|
- MIT
|
101
72
|
metadata: {}
|
@@ -105,18 +76,18 @@ require_paths:
|
|
105
76
|
- lib
|
106
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
78
|
requirements:
|
108
|
-
- -
|
79
|
+
- - ">="
|
109
80
|
- !ruby/object:Gem::Version
|
110
81
|
version: '0'
|
111
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
83
|
requirements:
|
113
|
-
- -
|
84
|
+
- - ">="
|
114
85
|
- !ruby/object:Gem::Version
|
115
86
|
version: '0'
|
116
87
|
requirements: []
|
117
88
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.
|
89
|
+
rubygems_version: 2.2.2
|
119
90
|
signing_key:
|
120
91
|
specification_version: 4
|
121
|
-
summary:
|
92
|
+
summary: Ruby minimalistic microframework.
|
122
93
|
test_files: []
|
data/.gitignore
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
*.bundle
|
19
|
-
*.so
|
20
|
-
*.o
|
21
|
-
*.a
|
22
|
-
mkmf.log
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 TODO: Write your name
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
data/lithium.gemspec
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'lithium/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "lithium"
|
8
|
-
spec.version = Lithium::VERSION
|
9
|
-
spec.authors = ["Sedat ÇİFTÇİ"]
|
10
|
-
spec.email = ["me@sedat.us"]
|
11
|
-
spec.summary = %q{Server Statistics}
|
12
|
-
spec.description = %q{Server Statistics}
|
13
|
-
spec.homepage = ""
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
|
24
|
-
spec.add_runtime_dependency 'Dysnomia', '~> 0.0.2'
|
25
|
-
spec.add_runtime_dependency 'em-websocket', '~> 0.5.1'
|
26
|
-
spec.add_runtime_dependency 'colorize', '~> 0.7.3'
|
27
|
-
end
|