rack-app 0.7.0 → 0.8.1

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: cb6371a96d8afd319aaf8ebddb3d941a652866d2
4
- data.tar.gz: d97fba9c4e53ebe73eb3d1aeb10a274bd77a91cc
3
+ metadata.gz: e8ad6c7fc6f81f76077dfe132794c6e0d6eb3791
4
+ data.tar.gz: bfcc01f514353f1d8aae0db0b005b4a9d63e6683
5
5
  SHA512:
6
- metadata.gz: 204a5de067f1bf95e05b67af4d106647362c22f0ac22e2b7bdc9a747d72d145510dd16590bdc8c9301d375c20b05f1d9cd7362941befa6ce0d3660c042f54c06
7
- data.tar.gz: 87c97fcf51497608c69e3f22be02e9acafe8696a02cea6f116547fdfec9c84b32701ca9499a2d8380b536ed278e88f2236492b5b269c4709b052acc3977f5a76
6
+ metadata.gz: ef57d6bf059772af7cabc811874ecc787db76c6ebd4bae08578e914f6a078d71f61ed48bf770bc6f6b755b76675177370415f02875a4324292283522b3f18cce
7
+ data.tar.gz: 88b17fb42241c1069c8a8fe2a1a188235ea030ba618c57b4d74493f3b678e6203f13de16bb75fc349dc5e3fbc33907e14c487f2a6873d3eff7b05c6b21bfee5e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.8.1
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rack/app"
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
@@ -6,8 +6,6 @@ class Rack::App
6
6
  require 'rack/app/version'
7
7
  require 'rack/app/constants'
8
8
 
9
- require 'rack/app/file'
10
-
11
9
  require 'rack/app/params'
12
10
  require 'rack/app/utils'
13
11
  require 'rack/app/router'
@@ -15,6 +13,9 @@ class Rack::App
15
13
  require 'rack/app/endpoint/not_found'
16
14
  require 'rack/app/request_configurator'
17
15
 
16
+ require 'rack/app/file'
17
+ require 'rack/app/view'
18
+
18
19
  class << self
19
20
 
20
21
  def call(request_env)
@@ -58,6 +59,10 @@ class Rack::App
58
59
  end
59
60
 
60
61
  def root(endpoint_path)
62
+ options '/' do
63
+ endpoint = self.class.router.fetch_endpoint('OPTIONS', Rack::App::Utils.normalize_path(endpoint_path))
64
+ endpoint.execute(request.env)
65
+ end
61
66
  get '/' do
62
67
  endpoint = self.class.router.fetch_endpoint('GET', Rack::App::Utils.normalize_path(endpoint_path))
63
68
  endpoint.execute(request.env)
@@ -1,5 +1,6 @@
1
1
  class Rack::App::File::Parser
2
2
 
3
+ require 'rack/app/file/parser/factory'
3
4
  require 'rack/app/file/parser/erb'
4
5
 
5
6
  def self.format_request_path(request_path)
@@ -0,0 +1,22 @@
1
+ module Rack::App::File::Parser::Factory
2
+
3
+ def use_file_parser(parser_class, *extensions)
4
+ extensions.each do |extension|
5
+ file_parser_classes[extension.to_s]= parser_class
6
+ end
7
+ nil
8
+ end
9
+
10
+ def find_file_parser_class_for(extension)
11
+ file_parser_classes[extension.to_s] || Rack::App::File::Parser
12
+ end
13
+
14
+ protected
15
+
16
+ def file_parser_classes
17
+ @file_parser_classes ||= {
18
+ '.erb' => Rack::App::File::Parser::ERB
19
+ }
20
+ end
21
+
22
+ end
@@ -1,51 +1,30 @@
1
- class Rack::App::File::Server < Rack::App
1
+ module Rack::App::File::Server
2
2
 
3
- class << self
3
+ include Rack::App::File::Parser::Factory
4
4
 
5
- def source_folder(relative_folder_path)
5
+ def source_folder(relative_folder_path)
6
6
 
7
- source_folder = Rack::App::Utils.pwd(relative_folder_path)
8
- Dir.glob(File.join(source_folder, '**', '*')).each do |file_path|
7
+ source_folder = Rack::App::Utils.pwd(relative_folder_path)
8
+ Dir.glob(File.join(source_folder, '**', '*')).each do |file_path|
9
9
 
10
- file_parser_class = find_file_parser_class_for(File.extname(file_path))
10
+ file_parser_class = find_file_parser_class_for(File.extname(file_path))
11
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
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)
27
14
 
15
+ options request_path do
16
+ response.finish
28
17
  end
29
18
 
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
19
+ get request_path do
20
+ file_parser = file_parser_class.new(self)
38
21
 
39
- def find_file_parser_class_for(extension)
40
- file_parser_classes[extension.to_s] || Rack::App::File::Parser
41
- end
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
42
24
 
43
- protected
25
+ response.finish
26
+ end
44
27
 
45
- def file_parser_classes
46
- @file_parser_classes ||= {
47
- '.erb' => Rack::App::File::Parser::ERB
48
- }
49
28
  end
50
29
 
51
30
  end
@@ -1,11 +1,21 @@
1
1
  class Rack::App::File::Streamer
2
2
 
3
+ include Enumerable
4
+
3
5
  def each(&blk)
4
6
  @file.each(&blk)
5
7
  ensure
6
8
  @file.close
7
9
  end
8
10
 
11
+ def to_a
12
+ @file.to_a.map(&:chomp)
13
+ end
14
+
15
+ def render(object=nil)
16
+ return self
17
+ end
18
+
9
19
  protected
10
20
 
11
21
  def initialize(path)
@@ -0,0 +1,14 @@
1
+ class Rack::App::View
2
+
3
+ extend Rack::App::File::Parser::Factory
4
+
5
+ def render(view_file_basename)
6
+ file_path = File.join(class_current_folder, view_file_basename)
7
+ self.class.find_file_parser_class_for(File.extname(file_path)).new(self).parse(file_path).to_a.join("\n")
8
+ end
9
+
10
+ def class_current_folder
11
+ method(:call).source_location.first.sub(/.rb$/,'')
12
+ end
13
+
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-04 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,6 +82,7 @@ files:
82
82
  - README.md
83
83
  - Rakefile
84
84
  - VERSION
85
+ - bin/console
85
86
  - bin/setup
86
87
  - lib/rack/app.rb
87
88
  - lib/rack/app/constants.rb
@@ -90,6 +91,7 @@ files:
90
91
  - lib/rack/app/file.rb
91
92
  - lib/rack/app/file/parser.rb
92
93
  - lib/rack/app/file/parser/erb.rb
94
+ - lib/rack/app/file/parser/factory.rb
93
95
  - lib/rack/app/file/server.rb
94
96
  - lib/rack/app/file/streamer.rb
95
97
  - lib/rack/app/file/version.rb
@@ -101,6 +103,7 @@ files:
101
103
  - lib/rack/app/test.rb
102
104
  - lib/rack/app/utils.rb
103
105
  - lib/rack/app/version.rb
106
+ - lib/rack/app/view.rb
104
107
  - rack-app.gemspec
105
108
  - spike/routing_time.rb
106
109
  homepage: https://github.com/adamluzsi/rack-app.rb