ps-smurf 1.2.0
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.
- data/Gemfile +20 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +68 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/closure-compiler/COPYING +202 -0
- data/lib/closure-compiler/README +289 -0
- data/lib/closure-compiler/compiler.jar +0 -0
- data/lib/closure-compiler/version +1 -0
- data/lib/jsmin.rb +262 -0
- data/lib/smurf.rb +17 -0
- data/lib/smurf/javascript.rb +74 -0
- data/lib/smurf/noop.rb +8 -0
- data/lib/smurf/rainpress.rb +168 -0
- data/lib/smurf/stylesheet.rb +17 -0
- data/test/integration_test.rb +13 -0
- data/test/javascript_test.rb +31 -0
- data/test/rails/app/controllers/application.rb +2 -0
- data/test/rails/config/application.rb +17 -0
- data/test/rails/config/boot.rb +9 -0
- data/test/rails/config/environment.rb +5 -0
- data/test/rails/config/environments/test.rb +7 -0
- data/test/rails/config/routes.rb +5 -0
- data/test/rails/public/javascripts/cache/expected.js +2 -0
- data/test/rails/public/javascripts/projwcss/jscss.css +3 -0
- data/test/rails/public/javascripts/testing.js +3 -0
- data/test/rails/public/stylesheets/bar.css +44 -0
- data/test/rails/public/stylesheets/cache/expected-basic.css +1 -0
- data/test/rails/public/stylesheets/foo.css +48 -0
- data/test/stylesheet_test.rb +41 -0
- data/test/test_helper.rb +48 -0
- metadata +187 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module Smurf
|
2
|
+
class Stylesheet
|
3
|
+
def self.minifies?(paths) !paths.grep(%r[\.css(\?\d+)?$]).empty?; end
|
4
|
+
|
5
|
+
def initialize(content)
|
6
|
+
@content = content.nil? ? nil : minify(content)
|
7
|
+
end
|
8
|
+
|
9
|
+
def minified; @content; end
|
10
|
+
|
11
|
+
# TODO: deal with string values better (urls, content blocks, etc.)
|
12
|
+
def minify(content)
|
13
|
+
Rainpress.compress(content)
|
14
|
+
end
|
15
|
+
|
16
|
+
end # Stylesheet
|
17
|
+
end # Smurf
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
context "link tags when caching on" do
|
4
|
+
setup do
|
5
|
+
javascript_include_tag('testing', :cache => 'cache/actual')
|
6
|
+
stylesheet_link_tag('foo', 'bar', :cache => 'cache/actual-basic')
|
7
|
+
stylesheet_link_tag('foo', 'bar', '/javascripts/projwcss/jscss', :cache => 'cache/actual-plus')
|
8
|
+
end
|
9
|
+
|
10
|
+
should_have_same_contents('/javascripts/cache/expected.js', '/javascripts/cache/actual.js')
|
11
|
+
should_have_same_contents('/stylesheets/cache/expected-basic.css', '/stylesheets/cache/actual-basic.css')
|
12
|
+
should_have_same_contents('/stylesheets/cache/expected-plus.css', '/stylesheets/cache/actual-plus.css')
|
13
|
+
end # link tags when caching on
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
context "Javascript minifier" do
|
4
|
+
|
5
|
+
should "want to minify files in the javascripts directory" do
|
6
|
+
Smurf::Javascript.minifies?(["a/b/javascripts/bar.js", "c/d/javascripts/baz.js"])
|
7
|
+
end
|
8
|
+
|
9
|
+
should "want to minify files in the stylesheets directory" do
|
10
|
+
Smurf::Javascript.minifies?(["a/b/stylesheets/bar.js", "c/d/stylesheets/baz.js"])
|
11
|
+
end
|
12
|
+
|
13
|
+
should "want to minify nothing but stylesheets" do
|
14
|
+
Smurf::Javascript.minifies?(["a/b/javascripts/bar.css", "c/d/javascripts/baz.css"])
|
15
|
+
end.not!
|
16
|
+
|
17
|
+
context "working with multi-line strings" do
|
18
|
+
setup do
|
19
|
+
input = StringIO.new()
|
20
|
+
input.puts("var foo='bar \\")
|
21
|
+
input.puts(" bar \\")
|
22
|
+
input.puts(" baz';")
|
23
|
+
input.rewind
|
24
|
+
input.read
|
25
|
+
end
|
26
|
+
|
27
|
+
should "not affect the string" do
|
28
|
+
Smurf::Javascript.new(topic).minified
|
29
|
+
end.equals("\nvar foo='bar bar baz';")
|
30
|
+
end # working with multi-line strings
|
31
|
+
end # Javascript minifier
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require "action_controller/railtie"
|
5
|
+
require "action_view/railtie"
|
6
|
+
|
7
|
+
# Auto-require default libraries and those for the current Rails environment.
|
8
|
+
Bundler.require :default, Rails.env
|
9
|
+
|
10
|
+
module Smurf
|
11
|
+
class Application < Rails::Application
|
12
|
+
config.session_store :cookie_store, {:key => "_smurf_session"}
|
13
|
+
config.secret_token = "i own you." * 3
|
14
|
+
|
15
|
+
config.root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
abbr, acronym {
|
2
|
+
border: 0;
|
3
|
+
font-variant: normal;
|
4
|
+
}
|
5
|
+
|
6
|
+
sup {
|
7
|
+
vertical-align: text-top;
|
8
|
+
}
|
9
|
+
/*
|
10
|
+
hello, my name is sam
|
11
|
+
*/
|
12
|
+
sub {
|
13
|
+
vertical-align: text-bottom;
|
14
|
+
}
|
15
|
+
|
16
|
+
input, textarea, select{
|
17
|
+
font-family: inherit;
|
18
|
+
font-size: inherit;
|
19
|
+
font-weight: inherit;
|
20
|
+
}
|
21
|
+
|
22
|
+
input, textarea, select {
|
23
|
+
*font-size: 100%;
|
24
|
+
}
|
25
|
+
|
26
|
+
legend { color:#000; }
|
27
|
+
|
28
|
+
del, ins {
|
29
|
+
text-decoration:none;
|
30
|
+
}
|
31
|
+
|
32
|
+
smurf {
|
33
|
+
content: "pa pa";
|
34
|
+
}
|
35
|
+
|
36
|
+
.smurf :link li {
|
37
|
+
color:blue;
|
38
|
+
}
|
39
|
+
|
40
|
+
smurf #smurf , :smurf .smurf {
|
41
|
+
color : black;
|
42
|
+
}
|
43
|
+
|
44
|
+
smurfdom { papa: smurf }
|
@@ -0,0 +1 @@
|
|
1
|
+
html{color:#000;background:#FFF}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal}li{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:''}abbr,acronym{border:0;font-variant:normal}sup{vertical-align:text-top}sub{vertical-align:text-bottom}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit}input,textarea,select{*font-size:100%}legend{color:#000}del,ins{text-decoration:none}smurf{content:"pa pa"}.smurf :link li{color:blue}smurf #smurf,:smurf .smurf{color:black}smurfdom{papa:smurf}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
|
3
|
+
Code licensed under the BSD License:
|
4
|
+
http://developer.yahoo.net/yui/license.txt
|
5
|
+
version: 2.6.0
|
6
|
+
*/
|
7
|
+
|
8
|
+
html {
|
9
|
+
color: #000;
|
10
|
+
background: #FFF;
|
11
|
+
}
|
12
|
+
|
13
|
+
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td {
|
14
|
+
margin: 0;
|
15
|
+
padding: 0;
|
16
|
+
}
|
17
|
+
|
18
|
+
table {
|
19
|
+
border-collapse: collapse;
|
20
|
+
border-spacing: 0;
|
21
|
+
}
|
22
|
+
|
23
|
+
fieldset, img {
|
24
|
+
border: 0;
|
25
|
+
}
|
26
|
+
|
27
|
+
address, caption, cite, code, dfn, em, strong, th, var {
|
28
|
+
font-style: normal;
|
29
|
+
font-weight: normal;
|
30
|
+
}
|
31
|
+
|
32
|
+
li {
|
33
|
+
list-style: none;
|
34
|
+
}
|
35
|
+
|
36
|
+
caption, th {
|
37
|
+
text-align: left;
|
38
|
+
}
|
39
|
+
|
40
|
+
h1, h2, h3, h4, h5, h6 {
|
41
|
+
font-size: 100%;
|
42
|
+
font-weight: normal;
|
43
|
+
}
|
44
|
+
|
45
|
+
q:before, q:after {
|
46
|
+
content: '';
|
47
|
+
}
|
48
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
context "Stylesheet minifier" do
|
4
|
+
setup { Smurf::Stylesheet }
|
5
|
+
helper(:minify) { |content| topic.new(content).minified }
|
6
|
+
|
7
|
+
should "want to minify files in the stylesheets directory" do
|
8
|
+
topic.minifies?(["a/b/stylesheets/bar.css", "c/d/stylesheets/baz.css?12344"])
|
9
|
+
end
|
10
|
+
|
11
|
+
should "want to minify files in the javascripts directory" do
|
12
|
+
topic.minifies?(["a/b/javascripts/bar.css?12345", "c/d/javascripts/baz.css"])
|
13
|
+
end
|
14
|
+
|
15
|
+
should "want to minify nothing but javascripts" do
|
16
|
+
topic.minifies?(["a/b/stylesheet/foo.js", "c/d/javascripts/baz.js"])
|
17
|
+
end.not!
|
18
|
+
|
19
|
+
context "minifying a non-existent pattern in a stylesheet" do
|
20
|
+
should("succeed for removing comments") do
|
21
|
+
minify("hi { mom: super-awesome; } ")
|
22
|
+
end.equals("hi{mom:super-awesome}")
|
23
|
+
|
24
|
+
should("succeed when no spaces to compress") do
|
25
|
+
minify("hi{mom:super-awesome}")
|
26
|
+
end.equals("hi{mom:super-awesome}")
|
27
|
+
|
28
|
+
# nothing outside, means nothing inside. they are complementary
|
29
|
+
should "succeed when no outside or inside blocks" do
|
30
|
+
minify("how-did: this-happen; typo: maybe;}")
|
31
|
+
end.equals("how-did: this-happen; typo: maybe}")
|
32
|
+
|
33
|
+
asserts "when no last semi-colon in block" do
|
34
|
+
minify("hi { mom: super-awesome } ")
|
35
|
+
end.equals("hi{mom:super-awesome}")
|
36
|
+
|
37
|
+
asserts("empty string when no content provided") { minify("") }.equals("")
|
38
|
+
|
39
|
+
asserts("nil even if nil provided") { minify(nil) }.nil
|
40
|
+
end # minifying a non-existent pattern in a stylesheet
|
41
|
+
end # Stylesheet minifier
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require ::File.expand_path('../rails/config/environment', __FILE__)
|
3
|
+
|
4
|
+
# Rails.public_path = Rails.root + "test" + "rails" + "public"
|
5
|
+
require 'riot'
|
6
|
+
require 'ostruct'
|
7
|
+
|
8
|
+
# require 'smurf'
|
9
|
+
require ::File.expand_path('../../lib/smurf', __FILE__)
|
10
|
+
|
11
|
+
class AssetFile
|
12
|
+
def self.base_path
|
13
|
+
@path ||= Rails.public_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.read(relative_path)
|
17
|
+
File.read(base_path + relative_path)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Riot::Context
|
22
|
+
def should_have_same_contents(expected_path, actual_path)
|
23
|
+
asserts "#{actual_path} has the same file contents as #{expected_path}" do
|
24
|
+
AssetFile.read(actual_path)
|
25
|
+
end.equals(AssetFile.read(expected_path))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Riot::Situation
|
30
|
+
include ActionView::Helpers::TagHelper
|
31
|
+
include ActionView::Helpers::AssetTagHelper
|
32
|
+
|
33
|
+
def controller; nil; end
|
34
|
+
|
35
|
+
def config
|
36
|
+
OpenStruct.new({
|
37
|
+
:assets_dir => Rails.public_path,
|
38
|
+
:javascripts_dir => Rails.public_path + "/javascripts",
|
39
|
+
:stylesheets_dir => Rails.public_path + "/stylesheets",
|
40
|
+
:perform_caching => true
|
41
|
+
})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
at_exit do
|
46
|
+
artifacts = Dir.glob(File.join(AssetFile.base_path, '**', 'cache', 'actual*.*'))
|
47
|
+
FileUtils.rm(artifacts)
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ps-smurf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Justin 'Gus' Knowlden
|
14
|
+
- Nicolas Viennot
|
15
|
+
- Ryan Grove
|
16
|
+
- Paul Schreiber
|
17
|
+
autorequire:
|
18
|
+
bindir: bin
|
19
|
+
cert_chain: []
|
20
|
+
|
21
|
+
date: 2012-04-12 00:00:00 Z
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
name: shoulda
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 31
|
44
|
+
segments:
|
45
|
+
- 3
|
46
|
+
- 12
|
47
|
+
version: "3.12"
|
48
|
+
name: rdoc
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
requirement: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 23
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 0
|
62
|
+
- 0
|
63
|
+
version: 1.0.0
|
64
|
+
name: bundler
|
65
|
+
prerelease: false
|
66
|
+
type: :development
|
67
|
+
requirement: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 49
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 8
|
78
|
+
- 3
|
79
|
+
version: 1.8.3
|
80
|
+
name: jeweler
|
81
|
+
prerelease: false
|
82
|
+
type: :development
|
83
|
+
requirement: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
name: rcov
|
95
|
+
prerelease: false
|
96
|
+
type: :development
|
97
|
+
requirement: *id005
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
name: riot
|
109
|
+
prerelease: false
|
110
|
+
type: :development
|
111
|
+
requirement: *id006
|
112
|
+
description: Rails plugin to automatically minify JS and CSS when their bundles get cached.
|
113
|
+
email: paulschreiber@gmail.com
|
114
|
+
executables: []
|
115
|
+
|
116
|
+
extensions: []
|
117
|
+
|
118
|
+
extra_rdoc_files:
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.rdoc
|
121
|
+
files:
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.rdoc
|
125
|
+
- Rakefile
|
126
|
+
- VERSION
|
127
|
+
- lib/closure-compiler/COPYING
|
128
|
+
- lib/closure-compiler/README
|
129
|
+
- lib/closure-compiler/compiler.jar
|
130
|
+
- lib/closure-compiler/version
|
131
|
+
- lib/jsmin.rb
|
132
|
+
- lib/smurf.rb
|
133
|
+
- lib/smurf/javascript.rb
|
134
|
+
- lib/smurf/noop.rb
|
135
|
+
- lib/smurf/rainpress.rb
|
136
|
+
- lib/smurf/stylesheet.rb
|
137
|
+
- test/integration_test.rb
|
138
|
+
- test/javascript_test.rb
|
139
|
+
- test/rails/app/controllers/application.rb
|
140
|
+
- test/rails/config/application.rb
|
141
|
+
- test/rails/config/boot.rb
|
142
|
+
- test/rails/config/environment.rb
|
143
|
+
- test/rails/config/environments/test.rb
|
144
|
+
- test/rails/config/routes.rb
|
145
|
+
- test/rails/public/javascripts/cache/expected.js
|
146
|
+
- test/rails/public/javascripts/projwcss/jscss.css
|
147
|
+
- test/rails/public/javascripts/testing.js
|
148
|
+
- test/rails/public/stylesheets/bar.css
|
149
|
+
- test/rails/public/stylesheets/cache/expected-basic.css
|
150
|
+
- test/rails/public/stylesheets/foo.css
|
151
|
+
- test/stylesheet_test.rb
|
152
|
+
- test/test_helper.rb
|
153
|
+
homepage: http://github.com/paulschreiber/ps-smurf
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
hash: 3
|
167
|
+
segments:
|
168
|
+
- 0
|
169
|
+
version: "0"
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
none: false
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
hash: 3
|
176
|
+
segments:
|
177
|
+
- 0
|
178
|
+
version: "0"
|
179
|
+
requirements: []
|
180
|
+
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 1.8.15
|
183
|
+
signing_key:
|
184
|
+
specification_version: 3
|
185
|
+
summary: Rails plugin to automatically minify JS and CSS when their bundles get cached
|
186
|
+
test_files: []
|
187
|
+
|