rack-app 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5ede34a09c9d0097e937f1e1eed2b2a407b58a8
4
- data.tar.gz: 0e34dd9cbdf1727858035651595f19ef3e202447
3
+ metadata.gz: cb6371a96d8afd319aaf8ebddb3d941a652866d2
4
+ data.tar.gz: d97fba9c4e53ebe73eb3d1aeb10a274bd77a91cc
5
5
  SHA512:
6
- metadata.gz: 5d3a9d617fa9b6517f47341cd7c37b77ae24f5fd057c17bbd3203f59200b1b519582824146bdb953698d6525b4c310ec0d9eb20496fe92efb38f91d2e478ae94
7
- data.tar.gz: d2b13fe4887da9e1f041cc9cf4de3c1a5a9acaf9f0c383ef07afd7a86fe41913a0c2a1db72b0e3d32735d0c69691b59a721128a49cf6449ac08d023c8541e699
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.7.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.8.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.9.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.6.0
1
+ 0.7.0
data/lib/rack/app.rb CHANGED
@@ -6,6 +6,8 @@ class Rack::App
6
6
  require 'rack/app/version'
7
7
  require 'rack/app/constants'
8
8
 
9
+ require 'rack/app/file'
10
+
9
11
  require 'rack/app/params'
10
12
  require 'rack/app/utils'
11
13
  require 'rack/app/router'
@@ -0,0 +1,8 @@
1
+ require 'rack/app'
2
+ require 'rack/app/file/version'
3
+
4
+ module Rack::App::File
5
+ require 'rack/app/file/streamer'
6
+ require 'rack/app/file/parser'
7
+ require 'rack/app/file/server'
8
+ end
@@ -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
@@ -0,0 +1,15 @@
1
+ class Rack::App::File::Streamer
2
+
3
+ def each(&blk)
4
+ @file.each(&blk)
5
+ ensure
6
+ @file.close
7
+ end
8
+
9
+ protected
10
+
11
+ def initialize(path)
12
+ @file = File.open(path)
13
+ end
14
+
15
+ end
@@ -0,0 +1,7 @@
1
+ module Rack
2
+ end unless defined?(Rack)
3
+ class Rack::App
4
+ end unless defined?(Rack::App)
5
+ module Rack::App::File
6
+ VERSION = File.read(File.join(File.dirname(__FILE__),'..','..', '..', '..', 'VERSION')).strip
7
+ end
@@ -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.6.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