zephyre 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/zephyre/controller.rb +60 -0
- data/lib/zephyre/dependencies.rb +7 -0
- data/lib/zephyre/main.rb +22 -0
- data/lib/zephyre/routing.rb +72 -0
- data/lib/zephyre/utils.rb +15 -0
- data/lib/zephyre/version.rb +3 -0
- data/lib/zephyre.rb +1 -0
- data/zephyre.gemspec +28 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d8dfc35260a405c0f08e78e34ada55bd0d694a01
|
4
|
+
data.tar.gz: 187f80ad23027f581018b52d9273dc3af9855f65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26609abd5c21a5e6b6d42550a157e638d1f26e45d4d499e2c8b6c06da24fba3653912743cb3a3ae902f0ef3f92f6b4392b70194643abafb18f1c70ef5104cf2f
|
7
|
+
data.tar.gz: 18360fd4cf776fcda6bfaceed9773ffc55337d7fd530ead27ec895d35a9b4f389d32df350f1b953d4d6204c18960a3482b33dbca80691ef25779f8c8f00f4603
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at dovzhanyn.alex@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Alex Dovzhanyn
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Zephyre
|
2
|
+
|
3
|
+
Zephyre is an opinionated ruby web framework that makes it easy to build small-scale projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'zephyre'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install zephyre
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alexdovzhanyn/zephyre. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "zephyre"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
|
3
|
+
module Zephyre
|
4
|
+
class Controller
|
5
|
+
attr_reader :request
|
6
|
+
|
7
|
+
def initialize(env)
|
8
|
+
@request ||= Rack::Request.new(env)
|
9
|
+
end
|
10
|
+
|
11
|
+
def params
|
12
|
+
request.params
|
13
|
+
end
|
14
|
+
|
15
|
+
def response(body, status=200, header={})
|
16
|
+
@response = Rack::Response.new(body, status, header)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_response
|
20
|
+
@response
|
21
|
+
end
|
22
|
+
|
23
|
+
def render(*args)
|
24
|
+
response(render_template(*args))
|
25
|
+
end
|
26
|
+
|
27
|
+
def render_template(view_name, locals = {})
|
28
|
+
filename = File.join("app", "views", controller_name, "#{view_name}.erb")
|
29
|
+
template = File.read(filename)
|
30
|
+
|
31
|
+
vars = {}
|
32
|
+
instance_variables.each do |var|
|
33
|
+
key = var.to_s.gsub("@", "").to_sym
|
34
|
+
vars[key] = instance_variable_get(var)
|
35
|
+
end
|
36
|
+
|
37
|
+
Erubis::Eruby.new(template).result(locals.merge(vars))
|
38
|
+
end
|
39
|
+
|
40
|
+
def controller_name
|
41
|
+
self.class.to_s.gsub(/Controller$/, "").to_snake_case
|
42
|
+
end
|
43
|
+
|
44
|
+
def dispatch(action)
|
45
|
+
content = self.send(action)
|
46
|
+
|
47
|
+
if get_response
|
48
|
+
get_response
|
49
|
+
else
|
50
|
+
render(action)
|
51
|
+
get_response
|
52
|
+
# [200, {"Content-Type" => "text/html"}, [response]]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.action(action_name)
|
57
|
+
-> (env) { self.new(env).dispatch(action_name) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/zephyre/main.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "zephyre/version"
|
2
|
+
require "zephyre/controller"
|
3
|
+
require "zephyre/utils"
|
4
|
+
require "zephyre/dependencies"
|
5
|
+
require "zephyre/routing"
|
6
|
+
|
7
|
+
module Zephyre
|
8
|
+
class Application
|
9
|
+
def map_routes(&block)
|
10
|
+
@router ||= Zephyre::Router.new
|
11
|
+
@router.instance_eval(&block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_rack_app(env)
|
15
|
+
@router.check_url(env["PATH_INFO"], env["REQUEST_METHOD"])
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
get_rack_app(env).call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Zephyre
|
2
|
+
class Router
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@routes = []
|
6
|
+
|
7
|
+
create_http_methods
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_http_methods
|
11
|
+
[:get, :post, :put, :patch, :delete, :match].each do |http_method|
|
12
|
+
|
13
|
+
self.define_singleton_method(http_method) do |pathmap|
|
14
|
+
target = pathmap.values.first
|
15
|
+
|
16
|
+
url_parts = pathmap.keys.first.split("/")
|
17
|
+
url_parts.select! {|part| !part.empty?}
|
18
|
+
|
19
|
+
placeholders = []
|
20
|
+
regexp_parts = url_parts.map do |part|
|
21
|
+
if part[0] == ":"
|
22
|
+
placeholders << part[1..-1]
|
23
|
+
"([A-Za-z0-9_]+)"
|
24
|
+
else
|
25
|
+
part
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
regexp = regexp_parts.join('/')
|
30
|
+
|
31
|
+
@routes << {
|
32
|
+
regexp: Regexp.new("^/#{regexp}$"),
|
33
|
+
target: target,
|
34
|
+
placeholders: placeholders,
|
35
|
+
method: "#{http_method.to_s.upcase}"
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def check_url(url, method)
|
42
|
+
@routes.each do |route|
|
43
|
+
match = route[:regexp].match(url)
|
44
|
+
|
45
|
+
if (match && (route[:method] == "MATCH" || route[:method].match(method)))
|
46
|
+
placeholders = {}
|
47
|
+
|
48
|
+
route[:placeholders].each_with_index do |placeholder, index|
|
49
|
+
placeholders[placeholder] = match.captures[index]
|
50
|
+
end
|
51
|
+
|
52
|
+
if route[:target]
|
53
|
+
return convert_target(route[:target])
|
54
|
+
else
|
55
|
+
controller = placeholders["controller"]
|
56
|
+
action = placeholders["action"]
|
57
|
+
|
58
|
+
return convert_target("#{controller}.#{action}")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def convert_target(target)
|
65
|
+
if target =~ /^([^.]+).([^.]+)$/
|
66
|
+
controller_name = $1.to_camel_case
|
67
|
+
controller = Object.const_get("#{controller_name}Controller")
|
68
|
+
return controller.action($2)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class String
|
2
|
+
def to_snake_case
|
3
|
+
self.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
|
+
|
10
|
+
def to_camel_case
|
11
|
+
return self if self !~ /_/ && self =~ /[A-Z]+.*/
|
12
|
+
|
13
|
+
split('_').map{ |str| str.capitalize }.join
|
14
|
+
end
|
15
|
+
end
|
data/lib/zephyre.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'zephyre/main'
|
data/zephyre.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zephyre/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zephyre"
|
8
|
+
spec.version = Zephyre::VERSION
|
9
|
+
spec.authors = ["Alex Dovzhanyn"]
|
10
|
+
spec.email = ["dovzhanyn.alex@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A small, open-source ruby web framework.}
|
13
|
+
spec.description = %q{Zephyre is a web development framework built on Rack. Use Zephyre to build quick websites with ruby.}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "rack"
|
27
|
+
spec.add_runtime_dependency "erubis"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zephyre
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Dovzhanyn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-19 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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: :development
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack
|
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: erubis
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Zephyre is a web development framework built on Rack. Use Zephyre to
|
84
|
+
build quick websites with ruby.
|
85
|
+
email:
|
86
|
+
- dovzhanyn.alex@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/zephyre.rb
|
101
|
+
- lib/zephyre/controller.rb
|
102
|
+
- lib/zephyre/dependencies.rb
|
103
|
+
- lib/zephyre/main.rb
|
104
|
+
- lib/zephyre/routing.rb
|
105
|
+
- lib/zephyre/utils.rb
|
106
|
+
- lib/zephyre/version.rb
|
107
|
+
- zephyre.gemspec
|
108
|
+
homepage: ''
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.4.8
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: A small, open-source ruby web framework.
|
132
|
+
test_files: []
|