hibana 0.1.0
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/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +38 -0
- data/README.md +33 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/hibana.gemspec +27 -0
- data/lib/hibana.rb +13 -0
- data/lib/hibana/application.rb +45 -0
- data/lib/hibana/controller.rb +61 -0
- data/lib/hibana/errors.rb +5 -0
- data/lib/hibana/errors/router_not_set_error.rb +10 -0
- data/lib/hibana/version.rb +3 -0
- data/lib/hibana/view.rb +40 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 170f8e41843268c1f41c25165f7ebcd7474e64c69fa335d76c1bae04838d7ec8
|
4
|
+
data.tar.gz: '093ffb5c0fd5090a058b271fe2d10d7c7f6646b4b54fee168bcaa788d9d0d493'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43d58ad70813c4046210918c9f8933dc2130ea493c2f6e355946d1a2fcdcece3ab09a02d1bf783b1b14d5b89f461f6ede8a94488fde0d94fae0b8d5646d8332f
|
7
|
+
data.tar.gz: aae725556ee94049b4bb9c93a564a667deafcbe9bb78a3dcdbf966f2e63357f150bb4a481471a7248d9ee8c12db01e2d713988306a40812e242ae56fe09e8f41
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hibana (0.1.0)
|
5
|
+
hanami-router
|
6
|
+
rack
|
7
|
+
tilt
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
concurrent-ruby (1.1.5)
|
13
|
+
hanami-router (1.3.1)
|
14
|
+
hanami-utils (~> 1.3)
|
15
|
+
http_router (= 0.11.2)
|
16
|
+
rack (~> 2.0)
|
17
|
+
hanami-utils (1.3.5)
|
18
|
+
concurrent-ruby (~> 1.0)
|
19
|
+
transproc (~> 1.0)
|
20
|
+
http_router (0.11.2)
|
21
|
+
rack (>= 1.0.0)
|
22
|
+
url_mount (~> 0.2.1)
|
23
|
+
rack (2.0.8)
|
24
|
+
rake (12.3.3)
|
25
|
+
tilt (2.0.10)
|
26
|
+
transproc (1.1.1)
|
27
|
+
url_mount (0.2.1)
|
28
|
+
rack
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
hibana!
|
35
|
+
rake (~> 12.0)
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
2.1.2
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Hibana
|
2
|
+
|
3
|
+
A small rack-based web framework.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'hibana'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install hibana
|
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 test` 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/r7kamura/hibana.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hibana"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/hibana.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'lib/hibana/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "hibana"
|
5
|
+
spec.version = Hibana::VERSION
|
6
|
+
spec.authors = ["r7kamura"]
|
7
|
+
spec.email = ["r7kamura@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "A small rack-based web framework."
|
10
|
+
spec.homepage = "https://github.com/r7kamura/hibana"
|
11
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
12
|
+
|
13
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
14
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
15
|
+
spec.metadata["changelog_uri"] = "https://github.com/r7kamura/hibana/blob/master/CHANGELOG"
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'hanami-router'
|
25
|
+
spec.add_runtime_dependency 'rack'
|
26
|
+
spec.add_runtime_dependency 'tilt'
|
27
|
+
end
|
data/lib/hibana.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'hibana/version'
|
2
|
+
|
3
|
+
module Hibana
|
4
|
+
autoload :Application, 'hibana/application'
|
5
|
+
autoload :Controller, 'hibana/controller'
|
6
|
+
autoload :Errors, 'hibana/errors'
|
7
|
+
autoload :View, 'hibana/view'
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# @return [Hibana::Application]
|
11
|
+
attr_accessor :application
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'hanami/router'
|
2
|
+
require 'rack/builder'
|
3
|
+
|
4
|
+
module Hibana
|
5
|
+
class Application
|
6
|
+
class << self
|
7
|
+
# @return [Hibana::Router, nil]
|
8
|
+
attr_accessor :router
|
9
|
+
|
10
|
+
# @param [Hash{String => Object}] env
|
11
|
+
# @return [Array]
|
12
|
+
def call(env)
|
13
|
+
rack_application.call(env)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Set routes using hanami-router DSL.
|
17
|
+
def route(&block)
|
18
|
+
self.router = ::Hanami::Router.new(&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def middleware
|
22
|
+
@middleware ||= ::Rack::Builder.new
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def rack_application
|
28
|
+
@rack_application ||= begin
|
29
|
+
middleware.run(new)
|
30
|
+
middleware.to_app
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param [Hash{String => Object}] env
|
36
|
+
# @return [Array]
|
37
|
+
def call(env)
|
38
|
+
unless self.class.router
|
39
|
+
raise ::Hibana::Errors::RouterNotSetError
|
40
|
+
end
|
41
|
+
|
42
|
+
self.class.router.call(env)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rack/request'
|
2
|
+
require 'rack/response'
|
3
|
+
|
4
|
+
module Hibana
|
5
|
+
class Controller
|
6
|
+
DEFAULT_RESPONSE_BODY = ''
|
7
|
+
DEFAULT_RESPONSE_STATUS = 200
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# @param [Hash{String => Object}] env
|
11
|
+
# @return [Array]
|
12
|
+
def call(env)
|
13
|
+
controller = new(env: env)
|
14
|
+
controller.call
|
15
|
+
controller.to_rack_spec_response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Rack::Response]
|
20
|
+
attr_reader :response
|
21
|
+
|
22
|
+
# @param [Hash{String => Object}] env
|
23
|
+
def initialize(env:)
|
24
|
+
@env = env
|
25
|
+
@response = ::Rack::Response.new(
|
26
|
+
DEFAULT_RESPONSE_BODY,
|
27
|
+
DEFAULT_RESPONSE_STATUS
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def call
|
32
|
+
raise ::NotImplementedError
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Hash{Symbol => String}]
|
36
|
+
def path_parameters
|
37
|
+
request.env['router.params']
|
38
|
+
end
|
39
|
+
|
40
|
+
# @todo
|
41
|
+
# @return [Hash{Symbol => String}]
|
42
|
+
def parameters
|
43
|
+
path_parameters
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Rack::Request]
|
47
|
+
def request
|
48
|
+
@request ||= ::Rack::Request.new(@env)
|
49
|
+
end
|
50
|
+
|
51
|
+
# @private
|
52
|
+
# @return [Array]
|
53
|
+
def to_rack_spec_response
|
54
|
+
[
|
55
|
+
@response.status,
|
56
|
+
@response.headers,
|
57
|
+
@response.body,
|
58
|
+
]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/hibana/view.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
|
3
|
+
module Hibana
|
4
|
+
class View
|
5
|
+
# @param [String, nil] layout_template_path
|
6
|
+
# @param [String] partial_template_path
|
7
|
+
# @param [Rack::Request] request
|
8
|
+
def initialize(layout_template_path: nil, partial_template_path:, request:)
|
9
|
+
@layout_template_path = layout_template_path
|
10
|
+
@partial_template_path = partial_template_path
|
11
|
+
@request = request
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [String]
|
15
|
+
def to_s
|
16
|
+
if @layout_template_path
|
17
|
+
render_layout do
|
18
|
+
render_partial
|
19
|
+
end
|
20
|
+
else
|
21
|
+
render_partial
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# @return [Rack::Request]
|
28
|
+
attr_reader :request
|
29
|
+
|
30
|
+
# @return [String]
|
31
|
+
def render_layout(&block)
|
32
|
+
::Tilt.new(@layout_template_path).render(self, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
def render_partial
|
37
|
+
::Tilt.new(@partial_template_path).render(self)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hibana
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- r7kamura
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hanami-router
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tilt
|
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
|
+
description:
|
56
|
+
email:
|
57
|
+
- r7kamura@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- hibana.gemspec
|
70
|
+
- lib/hibana.rb
|
71
|
+
- lib/hibana/application.rb
|
72
|
+
- lib/hibana/controller.rb
|
73
|
+
- lib/hibana/errors.rb
|
74
|
+
- lib/hibana/errors/router_not_set_error.rb
|
75
|
+
- lib/hibana/version.rb
|
76
|
+
- lib/hibana/view.rb
|
77
|
+
homepage: https://github.com/r7kamura/hibana
|
78
|
+
licenses: []
|
79
|
+
metadata:
|
80
|
+
homepage_uri: https://github.com/r7kamura/hibana
|
81
|
+
source_code_uri: https://github.com/r7kamura/hibana
|
82
|
+
changelog_uri: https://github.com/r7kamura/hibana/blob/master/CHANGELOG
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 2.3.0
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubygems_version: 3.0.3
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: A small rack-based web framework.
|
102
|
+
test_files: []
|