rack-app 0.6.0 → 0.7.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 +4 -4
- data/README.md +3 -3
- data/VERSION +1 -1
- data/lib/rack/app.rb +2 -0
- data/lib/rack/app/file.rb +8 -0
- data/lib/rack/app/file/parser.rb +23 -0
- data/lib/rack/app/file/parser/erb.rb +18 -0
- data/lib/rack/app/file/server.rb +53 -0
- data/lib/rack/app/file/streamer.rb +15 -0
- data/lib/rack/app/file/version.rb +7 -0
- data/lib/rack/app/utils.rb +12 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb6371a96d8afd319aaf8ebddb3d941a652866d2
|
4
|
+
data.tar.gz: d97fba9c4e53ebe73eb3d1aeb10a274bd77a91cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 204a5de067f1bf95e05b67af4d106647362c22f0ac22e2b7bdc9a747d72d145510dd16590bdc8c9301d375c20b05f1d9cd7362941befa6ce0d3660c042f54c06
|
7
|
+
data.tar.gz: 87c97fcf51497608c69e3f22be02e9acafe8696a02cea6f116547fdfec9c84b32701ca9499a2d8380b536ed278e88f2236492b5b269c4709b052acc3977f5a76
|
data/README.md
CHANGED
@@ -116,18 +116,18 @@ i feared do this for Rails that is usually slower than Grape :S
|
|
116
116
|
|
117
117
|
## Roadmap
|
118
118
|
|
119
|
-
### 0.
|
119
|
+
### 0.10.0
|
120
120
|
|
121
121
|
* serializer block/method for class shared serialization logic
|
122
122
|
* Mount method should able to take namespace option
|
123
123
|
* Create erb Parser Gem for View/FileServer to support to .erb files
|
124
124
|
|
125
|
-
### 0.
|
125
|
+
### 0.11.0
|
126
126
|
|
127
127
|
* content_type syntax sugar on class level
|
128
128
|
* response_headers syntax sugar for request processing
|
129
129
|
|
130
|
-
### 0.
|
130
|
+
### 0.12.0
|
131
131
|
|
132
132
|
* custom error_handler block for api, where Exception class types can be defined to process
|
133
133
|
* NULL Object pattern for error_handler_fetcher
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/lib/rack/app.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Rack::App::File::Parser
|
2
|
+
|
3
|
+
require 'rack/app/file/parser/erb'
|
4
|
+
|
5
|
+
def self.format_request_path(request_path)
|
6
|
+
request_path
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse(file_path)
|
10
|
+
Rack::App::File::Streamer.new(file_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def file_type(file_path)
|
14
|
+
File.extname(file_path)
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def initialize(app)
|
20
|
+
@app = app
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'erb'
|
2
|
+
class Rack::App::File::Parser::ERB < Rack::App::File::Parser
|
3
|
+
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
def parse(file_path)
|
7
|
+
[::ERB.new(File.read(file_path)).result(@app.instance_eval { binding })]
|
8
|
+
end
|
9
|
+
|
10
|
+
def file_type(file_path)
|
11
|
+
super(file_path.sub(/\.erb$/, ''))
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.format_request_path(request_path)
|
15
|
+
request_path.sub(/\.erb$/, '')
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class Rack::App::File::Server < Rack::App
|
2
|
+
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def source_folder(relative_folder_path)
|
6
|
+
|
7
|
+
source_folder = Rack::App::Utils.pwd(relative_folder_path)
|
8
|
+
Dir.glob(File.join(source_folder, '**', '*')).each do |file_path|
|
9
|
+
|
10
|
+
file_parser_class = find_file_parser_class_for(File.extname(file_path))
|
11
|
+
|
12
|
+
raw_endpoint_name = file_path.sub(source_folder, '').split(File::Separator).join('/')
|
13
|
+
request_path = file_parser_class.format_request_path(raw_endpoint_name)
|
14
|
+
|
15
|
+
options request_path do
|
16
|
+
response.finish
|
17
|
+
end
|
18
|
+
|
19
|
+
get request_path do
|
20
|
+
file_parser = file_parser_class.new(self)
|
21
|
+
|
22
|
+
response.body = file_parser.parse(file_path)
|
23
|
+
response.headers[Rack::CONTENT_TYPE]= Rack::Mime.mime_type(file_parser.file_type(file_path)).to_s
|
24
|
+
|
25
|
+
response.finish
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def use_file_parser(parser_class, *extensions)
|
33
|
+
extensions.each do |extension|
|
34
|
+
file_parser_classes[extension.to_s]= parser_class
|
35
|
+
end
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_file_parser_class_for(extension)
|
40
|
+
file_parser_classes[extension.to_s] || Rack::App::File::Parser
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def file_parser_classes
|
46
|
+
@file_parser_classes ||= {
|
47
|
+
'.erb' => Rack::App::File::Parser::ERB
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/lib/rack/app/utils.rb
CHANGED
@@ -17,4 +17,16 @@ module Rack::App::Utils
|
|
17
17
|
path
|
18
18
|
end
|
19
19
|
|
20
|
+
def pwd(*path_parts)
|
21
|
+
|
22
|
+
root_folder =if ENV['BUNDLE_GEMFILE']
|
23
|
+
ENV['BUNDLE_GEMFILE'].split(File::Separator)[0..-2].join(File::Separator)
|
24
|
+
else
|
25
|
+
Dir.pwd.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
return File.join(root_folder,*path_parts)
|
29
|
+
|
30
|
+
end
|
31
|
+
|
20
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
@@ -87,6 +87,12 @@ files:
|
|
87
87
|
- lib/rack/app/constants.rb
|
88
88
|
- lib/rack/app/endpoint.rb
|
89
89
|
- lib/rack/app/endpoint/not_found.rb
|
90
|
+
- lib/rack/app/file.rb
|
91
|
+
- lib/rack/app/file/parser.rb
|
92
|
+
- lib/rack/app/file/parser/erb.rb
|
93
|
+
- lib/rack/app/file/server.rb
|
94
|
+
- lib/rack/app/file/streamer.rb
|
95
|
+
- lib/rack/app/file/version.rb
|
90
96
|
- lib/rack/app/params.rb
|
91
97
|
- lib/rack/app/request_configurator.rb
|
92
98
|
- lib/rack/app/router.rb
|