mcnamara 0.0.4 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Change.log +0 -11
- data/LICENSE +0 -19
- data/README +16 -18
- data/Rakefile +1 -1
- data/VERSION +0 -1
- data/lib/mcnamara.rb +31 -57
- metadata +2 -2
data/Change.log
CHANGED
@@ -1,11 +0,0 @@
|
|
1
|
-
-- Nov. 25th, 2009
|
2
|
-
|
3
|
-
* added some file name functionality to support a request:
|
4
|
-
"Would be nice to be able to name CSS files that cover multiple versions of a specific folder, e.g.:
|
5
|
-
style-msie-lte-6.css (less than or equal to IE 6.0)
|
6
|
-
style-msie-gt-6.css (greater than)
|
7
|
-
style-msie-7-to-8.css OR style-msie-8-to-7.css (reversed)"
|
8
|
-
|
9
|
-
-- Nov. 24th, 2009
|
10
|
-
|
11
|
-
* coded initial version of McNamara
|
data/LICENSE
CHANGED
@@ -1,19 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 Kristan 'Krispy' Uccello <krispy@soldierofcode.com> - Soldier Of Code
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
5
|
-
in the Software without restriction, including without limitation the rights
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
8
|
-
furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
data/README
CHANGED
@@ -2,18 +2,21 @@
|
|
2
2
|
|
3
3
|
STILL A WORK IN PROGRESS
|
4
4
|
|
5
|
-
After working on Spy vs Spy (http://github.com/kuccello/spy-vs-spy) I wanted to build a system that would allow me to
|
5
|
+
After working on Spy vs Spy (http://github.com/kuccello/spy-vs-spy) I wanted to build a system that would allow me to
|
6
|
+
serve up css specific to various browsers if I needed to. How many times have you fixed a css design in one browser only
|
7
|
+
to have it break in another. Then you fix the other and it break the first one! McNamara attempts to solve this issue
|
8
|
+
by allowing you to have css browser/platform overrides that will be served up in place of your default one.
|
6
9
|
|
7
10
|
Here's how it works:
|
8
11
|
|
9
|
-
Say you have a web application that serves up css from the directory "/home/kuccello/myapp/public/css" and you have a
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
Say you have a web application that serves up css from the directory "/home/kuccello/myapp/public/css" and you have a
|
13
|
+
css file called "style.css" in that directory. Now, you have a special case for Internet Explorer 6.0 and another case
|
14
|
+
for Safari. What you would do is create another file in your css directory (can even be a sub directory deeply nested!)
|
15
|
+
called "style-msie-6-0.css" and you put your full css into that (that is all the contents of style with the changes needed
|
16
|
+
for internet explorer. As well you would create a file called "style-safari.css" where you would put all of the contents
|
17
|
+
of "style.css" with the changes specific for Safari. Then you put the McNamara middleware upstream of what ever is serving
|
18
|
+
your css and voila! when the browser is Safari the "style-safari.css" is served and when the browser is IE6.0 then the
|
19
|
+
"style-msie-6-0.css" is served and all you need to reference in your html is "style.css"!!
|
17
20
|
|
18
21
|
= usage:
|
19
22
|
|
@@ -21,22 +24,17 @@ require 'mcnamara'
|
|
21
24
|
|
22
25
|
use SOC::McNamara, "/usr/local/some_css_dir"
|
23
26
|
|
27
|
+
|
24
28
|
All you need to do is have browser overrides for the css you want.
|
25
29
|
stylename-<browser lowercase>-<version.major>-<version.minor>-<version.sub>.css
|
26
30
|
stylename-<browser lowercase>-<version.major>-<version.minor>.css
|
27
|
-
stylename-<browser lowercase>-<version.major>-to-<version.major-1>.css
|
28
|
-
stylename-<browser lowercase>-<version.major>-to-<version.major-2>.css
|
29
|
-
stylename-<browser lowercase>-<version.major-1>-to-<version.major>.css
|
30
|
-
stylename-<browser lowercase>-<version.major-2>-to-<version.major>.css
|
31
|
-
stylename-<browser lowercase>-lte-<version.major>.css
|
32
|
-
stylename-<browser lowercase>-gte-<version.major>.css
|
33
|
-
stylename-<browser lowercase>-gt-<version.major>.css
|
34
|
-
stylename-<browser lowercase>-lt-<version.major>.css
|
35
31
|
stylename-<browser lowercase>-<version.major>.css
|
32
|
+
stylename-<platform lowercase spaces replaced with _>-<mobile>.css
|
33
|
+
stylename-<platform lowercase spaces replaced with _>.css
|
36
34
|
stylename-<browser lowercase>.css
|
37
35
|
|
38
36
|
= notes:
|
39
37
|
|
40
|
-
you can have spy-vs-spy upstream of this middleware
|
38
|
+
you can have spy-vs-spy upstream of this middleware
|
41
39
|
|
42
40
|
if you use this middleware then you don't need spy-vs-spy downstream
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.4
|
data/lib/mcnamara.rb
CHANGED
@@ -41,80 +41,54 @@ module SoldierOfCode
|
|
41
41
|
@css_dir = css_dir
|
42
42
|
end
|
43
43
|
|
44
|
-
def build_possible_overrides(spy_vs_spy)
|
45
|
-
|
46
|
-
possible_overrides = []
|
47
|
-
|
48
|
-
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major}-#{spy_vs_spy.version.minor}-#{spy_vs_spy.version.sub}.css" if spy_vs_spy.version.major && spy_vs_spy.version.minor && spy_vs_spy.version.sub
|
49
|
-
|
50
|
-
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major}-#{spy_vs_spy.version.minor}.css" if spy_vs_spy.version.major && spy_vs_spy.version.minor
|
51
|
-
|
52
|
-
# trickier conditionals
|
53
|
-
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major}-to-#{spy_vs_spy.version.major.to_i-1}.css" if spy_vs_spy.version.major && (spy_vs_spy.version.major.to_i - 1 > 0)
|
54
|
-
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major.to_i-1}-to-#{spy_vs_spy.version.major}.css" if spy_vs_spy.version.major && (spy_vs_spy.version.major.to_i - 1 > 0)
|
55
|
-
|
56
|
-
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major}-to-#{spy_vs_spy.version.major.to_i-2}.css" if spy_vs_spy.version.major && (spy_vs_spy.version.major.to_i - 2 > 0)
|
57
|
-
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major.to_i-2}-to-#{spy_vs_spy.version.major}.css" if spy_vs_spy.version.major && (spy_vs_spy.version.major.to_i - 2 > 0)
|
58
|
-
|
59
|
-
# multi version coverage
|
60
|
-
possible_overrides << "-#{spy_vs_spy.browser}-gte-#{spy_vs_spy.version.major}.css" if spy_vs_spy.version.major
|
61
|
-
possible_overrides << "-#{spy_vs_spy.browser}-lte-#{spy_vs_spy.version.major}.css" if spy_vs_spy.version.major
|
62
|
-
possible_overrides << "-#{spy_vs_spy.browser}-gt-#{spy_vs_spy.version.major}.css" if spy_vs_spy.version.major
|
63
|
-
possible_overrides << "-#{spy_vs_spy.browser}-lt-#{spy_vs_spy.version.major}.css" if spy_vs_spy.version.major
|
64
|
-
|
65
|
-
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major}.css" if spy_vs_spy.version.major
|
66
|
-
|
67
|
-
possible_overrides << "-#{spy_vs_spy.browser}.css"
|
68
|
-
|
69
|
-
return possible_overrides
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
44
|
def call(env)
|
74
45
|
|
75
46
|
begin
|
47
|
+
# establish what browser we are dealing with
|
48
|
+
# hey! is spy-vs-spy upstream?
|
49
|
+
spy_vs_spy = env['soldierofcode.spy-vs-spy']
|
50
|
+
unless spy_vs_spy
|
51
|
+
http_user_agent = env['HTTP_USER_AGENT']
|
52
|
+
env['soldierofcode.spy-vs-spy'] = SpyVsSpy.new(http_user_agent)
|
53
|
+
spy_vs_spy = env['soldierofcode.spy-vs-spy']
|
54
|
+
end
|
76
55
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
# establish what browser we are dealing with
|
82
|
-
# hey! is spy-vs-spy upstream?
|
83
|
-
spy_vs_spy = env['soldierofcode.spy-vs-spy']
|
84
|
-
unless spy_vs_spy
|
85
|
-
http_user_agent = env['HTTP_USER_AGENT']
|
86
|
-
env['soldierofcode.spy-vs-spy'] = SpyVsSpy.new(http_user_agent)
|
87
|
-
spy_vs_spy = env['soldierofcode.spy-vs-spy']
|
88
|
-
end
|
56
|
+
# look for what css we are after
|
57
|
+
request_path = env['REQUEST_PATH']
|
58
|
+
if request_path =~ /\.css$/
|
89
59
|
|
90
|
-
|
91
|
-
|
92
|
-
|
60
|
+
# need a base directory to scann...
|
61
|
+
# TODO -- ripe for a cache
|
62
|
+
possible_overrides = []
|
63
|
+
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major}-#{spy_vs_spy.version.minor}-#{spy_vs_spy.version.sub}.css" if spy_vs_spy.version.major && spy_vs_spy.version.minor && spy_vs_spy.version.sub
|
64
|
+
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major}-#{spy_vs_spy.version.minor}.css" if spy_vs_spy.version.major && spy_vs_spy.version.minor
|
65
|
+
possible_overrides << "-#{spy_vs_spy.browser}-#{spy_vs_spy.version.major}.css" if spy_vs_spy.version.major
|
66
|
+
|
67
|
+
possible_overrides << "-#{spy_vs_spy.browser}.css"
|
93
68
|
|
94
|
-
|
95
|
-
|
96
|
-
|
69
|
+
Dir["#{@css_dir}/**/*.css"].each do |css_file|
|
70
|
+
possible_overrides.each do |override|
|
71
|
+
request_path_sub = request_path[1..-1].downcase.sub(/\.css/, override)
|
97
72
|
|
98
|
-
|
73
|
+
file_of_intrest = request_path_sub.split("/").last
|
99
74
|
# puts "#{__FILE__}:#{__LINE__} #{__method__} #{file_of_intrest.downcase} |||| #{css_file.downcase[1..-1]}"
|
100
75
|
|
101
|
-
|
76
|
+
if css_file[1..-1].downcase =~ Regexp.new("#{file_of_intrest.downcase}$")
|
102
77
|
# puts "#{__FILE__}:#{__LINE__} #{__method__} I'm IN!!"
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
78
|
+
# this is the file we want to serve
|
79
|
+
css = 'Oh oo - I droped the bomb'
|
80
|
+
File.open(css_file, "r") {|f| css = f.read}
|
81
|
+
return [200,{"Content-Type"=>"text/css"},css]
|
108
82
|
end
|
109
83
|
end
|
110
|
-
|
111
84
|
end
|
85
|
+
else
|
86
|
+
@app.call(env)
|
87
|
+
end
|
112
88
|
rescue => e
|
113
89
|
puts "#{__FILE__}:#{__LINE__} #{__method__} #{e} - #{e.backtrace}"
|
114
90
|
end
|
115
91
|
|
116
|
-
@app.call(env)
|
117
|
-
|
118
92
|
end
|
119
93
|
end
|
120
94
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcnamara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.1"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristan "Krispy" Uccello
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-11-24 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|