railz_lite 0.2.6 → 0.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f212021508124c75b30ec2d598c39939597f7263f8a08d8909efedc5d13220e7
4
- data.tar.gz: 2b45fc4a2b46f7aa168a48d1fc0c222cbeca5007c1c1df7400bbd591363388a7
3
+ metadata.gz: e77147f68729fb2f1b68f730aa31e1e50ca822df8990e6fb35ba9eb2e02cbf5d
4
+ data.tar.gz: e96ec7817513298e3899cde8d3e9d3f43cbc97589302443db38c4ec8a993258b
5
5
  SHA512:
6
- metadata.gz: d9a20d00eeab48b8738ee9f136468f97081a2b14c1819c9473277374a169cc8dbe85a45ee4ed48bfcc4df24856791019cf994df791d062c4a339d5d0ea83bc03
7
- data.tar.gz: 0646d6b6f01ac5c7998e9bf3c0431a34777cf22f7ac46e34756b2fc197832c9794949d2de2398c2ccbdaa5f2c8d59497a3dacaca62d9c2e5ace82fa1eae261bf
6
+ metadata.gz: 5968f44535f416c2524445365be98cacfe92894e1ed1079268cb8261ea0c44bd8101ad9f7fb62d84677fb0f2e5f57937f955144046bb1c399659b61c0065acb2
7
+ data.tar.gz: 958a09155c32bd8707908f4a820a2cc5e8f4116e0d90fa91c44ca24855827df3e4819ab31a410beffeb866615013418012890bab1237d105e0e9111bba4664ac
@@ -13,17 +13,21 @@ class Static
13
13
  req = Rack::Request.new(env)
14
14
  path = req.path
15
15
 
16
- if can_match?(path)
17
- file_server.call(env)
18
- else
16
+ asset_dir = get_asset_dir(path)
17
+
18
+ if asset_dir.nil?
19
19
  app.call(env)
20
+ else
21
+ file_server.call(env, asset_dir)
20
22
  end
21
23
  end
22
24
 
23
25
  private
24
26
 
25
- def can_match?(path)
26
- root_paths.any? { |root| path.index("/#{root}") }
27
+ # return the root directory of asset request ex => 'films/assets/app.css' would return 'assets'
28
+ def get_asset_dir(path)
29
+ root_paths.each { |root| return root if path.include?(root) }
30
+ nil
27
31
  end
28
32
  end
29
33
 
@@ -37,9 +41,9 @@ class FileServer
37
41
  '.js' => 'text/javascript'
38
42
  }
39
43
 
40
- def call(env)
44
+ def call(env, asset_dir)
41
45
  res = Rack::Response.new
42
- file_name = requested_file_name(env)
46
+ file_name = requested_file_name(env, asset_dir)
43
47
 
44
48
  if File.exist?(file_name)
45
49
  serve_file(file_name, res)
@@ -60,10 +64,11 @@ class FileServer
60
64
  res.write(file)
61
65
  end
62
66
 
63
- def requested_file_name(env)
67
+ def requested_file_name(env, asset_dir)
64
68
  req = Rack::Request.new(env)
65
- path = req.path
66
69
  dir = Dir.pwd
67
- File.join(dir, path)
70
+ path = req.path
71
+ filename = File.basename(path)
72
+ File.join(dir, asset_dir, filename)
68
73
  end
69
74
  end
@@ -24,7 +24,7 @@ end
24
24
 
25
25
  app = Rack::Builder.new do
26
26
  use ShowExceptions # generates helpful error messages
27
- use Static # serves static assets from /public
27
+ use Static # serves static assets from /public and /assets
28
28
  run app
29
29
  end.to_app
30
30
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailzLite
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.7"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railz_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - bryan lynch