faithfulgeek-naked_rack 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.textile +44 -0
- data/VERSION.yml +4 -0
- data/lib/naked_rack.rb +58 -0
- metadata +58 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 faithfulgeek
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
h1. naked_rack
|
2
|
+
|
3
|
+
CSS Naked Day is fast approaching. Is your site ready? By installing the @naked_rack@ middleware, your site will show its true colors on April 9th, 2009. For those who dare, use the @:remove_js => true@ option to prove your strength.
|
4
|
+
|
5
|
+
h2. CSS Naked Day? wtf?
|
6
|
+
|
7
|
+
CSS Naked Day is a day for web designers and developers to show off how hard they've worked to keep their site's semantically marked up and styled solely through CSS. Any well designed site should be usable even after losing its styles. CSS Naked Day is a day to prove that theory.
|
8
|
+
|
9
|
+
For more information on CSS Naked Day please see http://naked.dustindiaz.com/.
|
10
|
+
|
11
|
+
h2. Options
|
12
|
+
|
13
|
+
@naked_rack@ supports the following options:
|
14
|
+
|
15
|
+
@:display_banner => [true]|false@ - This will replace all stylesheet tags with an HTML comment advertising CSS Naked Day (not to mention giving itself some love)
|
16
|
+
@:remove_js => true|[false]@ - Also take out any @script@ tags. Prove your unobtrusiveness with this option.
|
17
|
+
@:permanent => true|[false]@ - Ignores the date and puts the site in permanent naked mode. This is really meant to be used during testing, but make sure you turn it off!
|
18
|
+
|
19
|
+
h2. Installation
|
20
|
+
|
21
|
+
Rails (in @config/environment.rb@):
|
22
|
+
|
23
|
+
@config.middleware.use "NakedRack"[, options]@
|
24
|
+
|
25
|
+
Sinatra:
|
26
|
+
|
27
|
+
@use NakedRack[, options]@
|
28
|
+
|
29
|
+
Rackup Script:
|
30
|
+
|
31
|
+
@use NakedRack[, options]@
|
32
|
+
|
33
|
+
|
34
|
+
Thanks for using naked_rack! Hope everyone has a safe and happy CSS Naked Day.
|
35
|
+
|
36
|
+
hr.
|
37
|
+
|
38
|
+
Developed by:
|
39
|
+
|
40
|
+
@joefiorini (irc: faithfulgeek)
|
41
|
+
|
42
|
+
== Copyright
|
43
|
+
|
44
|
+
Copyright (c) 2009 faithfulgeek. See LICENSE for details.
|
data/VERSION.yml
ADDED
data/lib/naked_rack.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'hpricot'
|
2
|
+
|
3
|
+
class NakedRack
|
4
|
+
|
5
|
+
DEFAULT_OPTIONS = { :display_banner => true, :remove_js => false, :permanent => false }
|
6
|
+
|
7
|
+
def initialize(app, options={})
|
8
|
+
@app = app
|
9
|
+
@options = options.reverse_merge(DEFAULT_OPTIONS)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
return @app.call(env) unless today_is_naked_css_day? or @options[:permanent]
|
14
|
+
status, headers, response = @app.call(env)
|
15
|
+
body = ''
|
16
|
+
response.each do |str|
|
17
|
+
body = remove_link_tags(str).to_html
|
18
|
+
body = remove_style_tags(body).to_html
|
19
|
+
body = remove_js_tags(body).to_html if @options[:remove_js]
|
20
|
+
end
|
21
|
+
headers['Content-Length'] = body.length.to_s
|
22
|
+
[status, headers, body]
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def remove_link_tags body
|
28
|
+
remove_tags body, "//link[@rel='stylesheet']"
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_style_tags body
|
32
|
+
remove_tags body, "style"
|
33
|
+
end
|
34
|
+
|
35
|
+
def remove_js_tags body
|
36
|
+
remove_tags body, "script"
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove_tags body, search_str
|
40
|
+
h_doc = Hpricot(body)
|
41
|
+
elems = h_doc.search(search_str)
|
42
|
+
if @options[:display_banner]
|
43
|
+
replace_with_banner! elems
|
44
|
+
else
|
45
|
+
elems.remove
|
46
|
+
end
|
47
|
+
h_doc
|
48
|
+
end
|
49
|
+
|
50
|
+
def today_is_naked_css_day?
|
51
|
+
Date.today.month == 4 and Date.today.day == 9
|
52
|
+
end
|
53
|
+
|
54
|
+
def replace_with_banner! h_elems
|
55
|
+
h_elems.each { |elem| elem.swap("<!-- Happy CSS Naked Day! Brought to you by naked_rack and Joe Fiorini -->") }
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faithfulgeek-naked_rack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- faithfulgeek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-09 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: joe@faithfulgeek.org
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.textile
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- README.textile
|
27
|
+
- VERSION.yml
|
28
|
+
- lib/naked_rack.rb
|
29
|
+
- LICENSE
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://github.com/faithfulgeek/naked_rack
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options:
|
34
|
+
- --inline-source
|
35
|
+
- --charset=UTF-8
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: Gem to allow you to run your Rack-supported web app naked for CSS Naked Day on April 9th.
|
57
|
+
test_files: []
|
58
|
+
|