rhino-framework 0.0.4
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.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +2 -0
- data/lib/rhino.rb +42 -0
- data/lib/rhino/array.rb +5 -0
- data/lib/rhino/controller.rb +31 -0
- data/lib/rhino/dependencies.rb +8 -0
- data/lib/rhino/file_model.rb +50 -0
- data/lib/rhino/routing.rb +11 -0
- data/lib/rhino/util.rb +9 -0
- data/lib/rhino/version.rb +3 -0
- data/rhino.gemspec +29 -0
- data/test/erb_test.rb +11 -0
- data/test/test_application.rb +27 -0
- data/test/test_helper.rb +11 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 492876e8b44ac07720daaa2f0f21da53899a3c83
|
4
|
+
data.tar.gz: ba4db5600b64551d69bf934537b7fe11e6422436
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24279bbf2b49923991899d273694cc563be92e7fa2455efb432d66e3ee885f0bcbce16204df18002fbb3eee7d738258bcf55aae2aa2d735a393c15d5629bc2be
|
7
|
+
data.tar.gz: d8ad14a65bbeb15242b0c1c1de5c01b67d92e9ef4340686b8bb5851b29e76fb25695ff8eda7002dfb5d0ac20e2599fe0dc765b43f1b7c46cd8357591a820719a
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Rhino
|
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/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Rhino
|
2
|
+
|
3
|
+
This is a small Ruby Web Framework. Rails-like framework.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rhino'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rhino
|
20
|
+
|
21
|
+
## Contributing
|
22
|
+
|
23
|
+
1. Fork it ( https://github.com/[my-github-username]/rhino/fork )
|
24
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
25
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
26
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
27
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/rhino.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "rhino/version"
|
2
|
+
require "rhino/routing"
|
3
|
+
require "rhino/util"
|
4
|
+
require "rhino/dependencies"
|
5
|
+
require "rhino/controller"
|
6
|
+
require "rhino/file_model"
|
7
|
+
|
8
|
+
module Rhino
|
9
|
+
|
10
|
+
class Application
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
klass, act = get_controller_and_action(env)
|
14
|
+
controller = klass.new(env)
|
15
|
+
text = controller.send(act) rescue (return action_not_found)
|
16
|
+
[200, {'Content-Type' => 'text/html'}, [text]]
|
17
|
+
rescue LoadError => e
|
18
|
+
return error_404(e)
|
19
|
+
rescue => e # StandardError
|
20
|
+
return error_500(e)
|
21
|
+
end
|
22
|
+
|
23
|
+
def error_404(error)
|
24
|
+
[404, {'Content-Type' => 'text/html'}, ["The page not found ! <br/> <b>#{error.message}</b>"]]
|
25
|
+
end
|
26
|
+
|
27
|
+
def action_not_found
|
28
|
+
[404, {'Content-Type' => 'text/html'}, ['The action not found !']]
|
29
|
+
end
|
30
|
+
|
31
|
+
def error_500(error)
|
32
|
+
[500, {'Content-Type' => 'text/html'}, ["Some thing went wrong ! <br/> <b>#{error.message}</b>"]]
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.root_path
|
36
|
+
"/home/buikhanh/projects/my_projects/ruby-framework/best_quotes/"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
data/lib/rhino/array.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
require 'rhino/file_model'
|
3
|
+
|
4
|
+
module Rhino
|
5
|
+
|
6
|
+
class Controller
|
7
|
+
include Rhino::Model
|
8
|
+
|
9
|
+
def initialize(env)
|
10
|
+
@env = env
|
11
|
+
end
|
12
|
+
|
13
|
+
def env
|
14
|
+
@env
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(view_name, locals={})
|
18
|
+
file_name = File.join Rhino::Application.root_path, 'app', 'views', controller_name, "#{view_name}.html.erb"
|
19
|
+
template = File.read file_name
|
20
|
+
eruby = Erubis::Eruby.new(template)
|
21
|
+
eruby.result locals.merge(env: env)
|
22
|
+
end
|
23
|
+
|
24
|
+
def controller_name
|
25
|
+
klass = self.class
|
26
|
+
klass = klass.to_s.gsub(/Controller$/, "")
|
27
|
+
Rhino.to_underscore(klass)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
module Rhino
|
3
|
+
module Model
|
4
|
+
class FileModel
|
5
|
+
|
6
|
+
def initialize(file_name)
|
7
|
+
@file_name = file_name
|
8
|
+
|
9
|
+
base_name = File.split(file_name)[-1]
|
10
|
+
@id = File.basename(base_name, ".json").to_i
|
11
|
+
|
12
|
+
obj = File.read(file_name)
|
13
|
+
@hash = MultiJson.load(obj)
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](name)
|
17
|
+
@hash[name.to_s]
|
18
|
+
end
|
19
|
+
|
20
|
+
def []=(name, value)
|
21
|
+
@hash[name.to_s] = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find(id)
|
25
|
+
FileModel.new(Rhino::Application.root_path + "/db/quotes/#{id}.json")
|
26
|
+
rescue
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.all
|
31
|
+
files = Dir[Rhino::Application.root_path + '/db/quotes/*.json']
|
32
|
+
files.map{|f| FileModel.new f}.select{|x| !x.nil? }
|
33
|
+
end
|
34
|
+
|
35
|
+
# TODO
|
36
|
+
def self.find_by_committer(committer)
|
37
|
+
end
|
38
|
+
|
39
|
+
# TODO
|
40
|
+
def self.where(options={})
|
41
|
+
end
|
42
|
+
|
43
|
+
# TODO
|
44
|
+
def update_attribute(options={})
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/lib/rhino/util.rb
ADDED
data/rhino.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rhino/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rhino-framework"
|
8
|
+
spec.version = Rhino::VERSION
|
9
|
+
spec.authors = ["rhino"]
|
10
|
+
spec.email = ["18hino@gmail.com"]
|
11
|
+
spec.summary = %q{Rhino - Ruby Web Framework}
|
12
|
+
spec.description = %q{This is Rails-like, Rack based framework}
|
13
|
+
spec.homepage = "http://1rhino.github.io"
|
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_runtime_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_runtime_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_runtime_dependency "erubis"
|
24
|
+
spec.add_runtime_dependency "multi_json"
|
25
|
+
spec.add_development_dependency "test-unit", "~> 3.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.5"
|
27
|
+
spec.add_development_dependency "rack-test", "~> 0.6"
|
28
|
+
|
29
|
+
end
|
data/test/erb_test.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class RhinoAppTest < Test::Unit::TestCase
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
BestQuotes::Application.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_get
|
11
|
+
get '/'
|
12
|
+
|
13
|
+
assert last_response, "404"
|
14
|
+
body = last_response.body
|
15
|
+
assert body["not found"]
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_request_post
|
20
|
+
get '/quotes/a_quote'
|
21
|
+
|
22
|
+
assert last_response.ok?
|
23
|
+
body = last_response.body
|
24
|
+
assert body["Ruby Version"]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
# Alway use the local code first
|
5
|
+
dir = File.join(File.dirname(__FILE__), "..", 'lib')
|
6
|
+
best_quotes_dir = File.join(File.dirname(__FILE__), "..", "..", 'best_quotes')
|
7
|
+
$LOAD_PATH.unshift File.expand_path(dir)
|
8
|
+
$LOAD_PATH.unshift File.expand_path(best_quotes_dir)
|
9
|
+
|
10
|
+
require 'rhino'
|
11
|
+
require 'config/application.rb'
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rhino-framework
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rhino
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: erubis
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: test-unit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rack-test
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.6'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.6'
|
111
|
+
description: This is Rails-like, Rack based framework
|
112
|
+
email:
|
113
|
+
- 18hino@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/rhino.rb
|
123
|
+
- lib/rhino/array.rb
|
124
|
+
- lib/rhino/controller.rb
|
125
|
+
- lib/rhino/dependencies.rb
|
126
|
+
- lib/rhino/file_model.rb
|
127
|
+
- lib/rhino/routing.rb
|
128
|
+
- lib/rhino/util.rb
|
129
|
+
- lib/rhino/version.rb
|
130
|
+
- rhino.gemspec
|
131
|
+
- test/erb_test.rb
|
132
|
+
- test/test_application.rb
|
133
|
+
- test/test_helper.rb
|
134
|
+
homepage: http://1rhino.github.io
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.4.6
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Rhino - Ruby Web Framework
|
158
|
+
test_files:
|
159
|
+
- test/erb_test.rb
|
160
|
+
- test/test_application.rb
|
161
|
+
- test/test_helper.rb
|