hibana 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hibana.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -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
@@ -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.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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
@@ -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
@@ -0,0 +1,5 @@
1
+ module Hibana
2
+ module Errors
3
+ autoload :RouterNotSetError, 'hibana/errors/router_not_set_error'
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module Hibana
2
+ module Errors
3
+ class RouterNotSetError < ::RuntimeError
4
+ # @return [String]
5
+ def to_s
6
+ "Can't handle requests because router is not set."
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Hibana
2
+ VERSION = "0.1.0"
3
+ end
@@ -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: []