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 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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rhino.gemspec
4
+ gemspec
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
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
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
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def sum(start = 0)
3
+ inject(start, &:+)
4
+ end
5
+ end
@@ -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,8 @@
1
+ class Object
2
+ # Object will call this method when method const_get can't get constant
3
+ def self.const_missing(c)
4
+ # TODO avoid infiniti call: const_get -> const_missing -> const_get...
5
+ require Rhino.to_underscore(c.to_s)
6
+ Object.const_get(c)
7
+ end
8
+ 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
+
@@ -0,0 +1,11 @@
1
+ module Rhino
2
+ class Application
3
+ def get_controller_and_action(env)
4
+ _, cont, action, after = env['PATH_INFO'].split("/", 4)
5
+ cont = cont.capitalize
6
+ cont += "Controller"
7
+
8
+ [Object.const_get(cont), action]
9
+ end
10
+ end
11
+ end
data/lib/rhino/util.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Rhino
2
+ def self.to_underscore(string)
3
+ string.gsub(/::/, '/').
4
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
5
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
6
+ tr('-','_').
7
+ downcase
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Rhino
2
+ VERSION = "0.0.4"
3
+ end
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,11 @@
1
+ require 'erubis'
2
+
3
+ template = <<TEMPLATE
4
+ This is a template.
5
+ It has <%= some_thing %>.
6
+ TEMPLATE
7
+
8
+ eruby = Erubis::Eruby.new(template)
9
+ puts eruby.src
10
+ puts "========="
11
+ puts eruby.result(some_thing: "Xicaloa")
@@ -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
@@ -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