mcnamara 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/mcnamara.rb +27 -26
- metadata +1 -1
data/Rakefile
CHANGED
data/lib/mcnamara.rb
CHANGED
@@ -65,7 +65,7 @@ module SoldierOfCode
|
|
65
65
|
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major}.css" if spy_vs_spy.version.major
|
66
66
|
|
67
67
|
possible_overrides << "-#{spy_vs_spy.browser}.css"
|
68
|
-
|
68
|
+
|
69
69
|
return possible_overrides
|
70
70
|
|
71
71
|
end
|
@@ -73,46 +73,47 @@ module SoldierOfCode
|
|
73
73
|
def call(env)
|
74
74
|
|
75
75
|
begin
|
76
|
-
|
77
|
-
|
78
|
-
spy_vs_spy = env['soldierofcode.spy-vs-spy']
|
79
|
-
unless spy_vs_spy
|
80
|
-
http_user_agent = env['HTTP_USER_AGENT']
|
81
|
-
env['soldierofcode.spy-vs-spy'] = SpyVsSpy.new(http_user_agent)
|
76
|
+
# establish what browser we are dealing with
|
77
|
+
# hey! is spy-vs-spy upstream?
|
82
78
|
spy_vs_spy = env['soldierofcode.spy-vs-spy']
|
83
|
-
|
79
|
+
unless spy_vs_spy
|
80
|
+
http_user_agent = env['HTTP_USER_AGENT']
|
81
|
+
env['soldierofcode.spy-vs-spy'] = SpyVsSpy.new(http_user_agent)
|
82
|
+
spy_vs_spy = env['soldierofcode.spy-vs-spy']
|
83
|
+
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
# look for what css we are after
|
86
|
+
request_path = env['REQUEST_PATH']
|
87
|
+
if request_path =~ /\.css$/
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
# need a base directory to scann...
|
90
|
+
# TODO -- ripe for a cache
|
91
|
+
possible_overrides = build_possible_overrides(spy_vs_spy)
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
Dir["#{@css_dir}/**/*.css"].each do |css_file|
|
94
|
+
possible_overrides.each do |override|
|
95
|
+
request_path_sub = request_path[1..-1].downcase.sub(/\.css/, override)
|
96
96
|
|
97
|
-
|
97
|
+
file_of_intrest = request_path_sub.split("/").last
|
98
98
|
# puts "#{__FILE__}:#{__LINE__} #{__method__} #{file_of_intrest.downcase} |||| #{css_file.downcase[1..-1]}"
|
99
99
|
|
100
|
-
|
100
|
+
if css_file[1..-1].downcase =~ Regexp.new("#{file_of_intrest.downcase}$")
|
101
101
|
# puts "#{__FILE__}:#{__LINE__} #{__method__} I'm IN!!"
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
102
|
+
# this is the file we want to serve
|
103
|
+
css = 'Oh oo - I droped the bomb'
|
104
|
+
File.open(css_file, "r") {|f| css = f.read}
|
105
|
+
return [200, {"Content-Type"=>"text/css"}, css]
|
106
|
+
end
|
106
107
|
end
|
107
108
|
end
|
109
|
+
|
108
110
|
end
|
109
|
-
else
|
110
|
-
@app.call(env)
|
111
|
-
end
|
112
111
|
rescue => e
|
113
112
|
puts "#{__FILE__}:#{__LINE__} #{__method__} #{e} - #{e.backtrace}"
|
114
113
|
end
|
115
114
|
|
115
|
+
@app.call(env)
|
116
|
+
|
116
117
|
end
|
117
118
|
end
|
118
119
|
end
|