csspress 0.0.1
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/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +32 -0
- data/PostInstall.txt +8 -0
- data/README.txt +63 -0
- data/Rakefile +4 -0
- data/bin/css +198 -0
- data/config/hoe.rb +72 -0
- data/config/requirements.rb +15 -0
- data/lib/csspress.rb +21 -0
- data/lib/csspress/declaration.rb +144 -0
- data/lib/csspress/rule.rb +123 -0
- data/lib/csspress/style_sheet.rb +243 -0
- data/lib/csspress/template_builder.rb +73 -0
- data/lib/csspress/version.rb +20 -0
- data/lib/templates/default.csst +1 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/spec/csspress_spec.rb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- data/website/index.html +15 -0
- data/website/index.txt +3 -0
- data/website/stylesheets/screen.css +18 -0
- data/website/template.html.erb +14 -0
- metadata +99 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 David Madden
|
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/Manifest.txt
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
bin/css
|
8
|
+
config/hoe.rb
|
9
|
+
config/requirements.rb
|
10
|
+
lib/csspress.rb
|
11
|
+
lib/csspress/declaration.rb
|
12
|
+
lib/csspress/rule.rb
|
13
|
+
lib/csspress/style_sheet.rb
|
14
|
+
lib/csspress/template_builder.rb
|
15
|
+
lib/csspress/version.rb
|
16
|
+
lib/templates/default.csst
|
17
|
+
script/console
|
18
|
+
script/destroy
|
19
|
+
script/generate
|
20
|
+
script/txt2html
|
21
|
+
setup.rb
|
22
|
+
spec/csspress_spec.rb
|
23
|
+
spec/spec.opts
|
24
|
+
spec/spec_helper.rb
|
25
|
+
tasks/deployment.rake
|
26
|
+
tasks/environment.rake
|
27
|
+
tasks/rspec.rake
|
28
|
+
tasks/website.rake
|
29
|
+
website/index.html
|
30
|
+
website/index.txt
|
31
|
+
website/stylesheets/screen.css
|
32
|
+
website/template.html.erb
|
data/PostInstall.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
= csspress
|
2
|
+
|
3
|
+
Project Page:
|
4
|
+
- http://csspress.rubyforge.org
|
5
|
+
RubyForge Page:
|
6
|
+
- http://rubyforge.org/projects/csspress/
|
7
|
+
|
8
|
+
== DESCRIPTION:
|
9
|
+
|
10
|
+
Press out only the juice worth serving from you CSS files (and optimize it a little while your at it).
|
11
|
+
|
12
|
+
When you are building a website, a well formatted and clearly commented CSS file can make it really easy
|
13
|
+
for developers to see what is going on and build beautiful pages. All of this extra stuff however needs to be downloaded by a end user who is never going to read it, but has to wait for it.
|
14
|
+
|
15
|
+
CSSpress to the rescue! CSSpress allows you to quickly and easily remove comments and whitespace from your
|
16
|
+
CSS files as well as optimize specific property values. It will even tell you how much space you have saved.
|
17
|
+
|
18
|
+
Download speed is important. Only serve what you need to.
|
19
|
+
|
20
|
+
== FEATURES/PROBLEMS:
|
21
|
+
|
22
|
+
Features:
|
23
|
+
* Comment stripping
|
24
|
+
* White space stripping
|
25
|
+
|
26
|
+
Problems
|
27
|
+
* No optimization as of yet.
|
28
|
+
|
29
|
+
== SYNOPSIS:
|
30
|
+
|
31
|
+
Usage exapmle:
|
32
|
+
$> css foo.css
|
33
|
+
|
34
|
+
This will output a compressed version of foo.css to csspress-foo.css
|
35
|
+
|
36
|
+
== INSTALL:
|
37
|
+
|
38
|
+
sudo gem install
|
39
|
+
|
40
|
+
== LICENSE:
|
41
|
+
|
42
|
+
(The MIT License)
|
43
|
+
|
44
|
+
Copyright (c) 2008 David Madden
|
45
|
+
|
46
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
47
|
+
a copy of this software and associated documentation files (the
|
48
|
+
'Software'), to deal in the Software without restriction, including
|
49
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
50
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
51
|
+
permit persons to whom the Software is furnished to do so, subject to
|
52
|
+
the following conditions:
|
53
|
+
|
54
|
+
The above copyright notice and this permission notice shall be
|
55
|
+
included in all copies or substantial portions of the Software.
|
56
|
+
|
57
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
58
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
59
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
60
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
61
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
62
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
63
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/css
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Created by David Madden on 2008-5-15
|
4
|
+
# Copyright (c) 2008. All rights reserved.
|
5
|
+
#
|
6
|
+
# == Synopsis
|
7
|
+
# This program strips comments and white space from
|
8
|
+
# Valid CSS files.
|
9
|
+
#
|
10
|
+
# (Please make sure the CSS is valid!!. CSSpress will
|
11
|
+
# not validate CSS for you and is less likely to work if
|
12
|
+
# given invalid CSS code).
|
13
|
+
#
|
14
|
+
# == Examples
|
15
|
+
# This will output a compressed version of
|
16
|
+
# foo.css to csspress-foo.css
|
17
|
+
# css foo.css
|
18
|
+
#
|
19
|
+
# Other examples:
|
20
|
+
# css -v bar.css
|
21
|
+
# css -h
|
22
|
+
#
|
23
|
+
# == Usage
|
24
|
+
# css [options] source_file
|
25
|
+
#
|
26
|
+
# For help use:
|
27
|
+
# css -h
|
28
|
+
#
|
29
|
+
# == Options
|
30
|
+
# -h, --help Displays help message
|
31
|
+
# -s, --stats Output compression information
|
32
|
+
# -v, --version Display the version, then exit
|
33
|
+
#
|
34
|
+
# == Author
|
35
|
+
# David Madden
|
36
|
+
#
|
37
|
+
require 'optparse' # for parsing cmd line options
|
38
|
+
require 'rdoc/usage' # for outputing rdoc to terminal
|
39
|
+
require 'ostruct' # useful in cmd line option usage
|
40
|
+
require 'csspress' # load all of the application code
|
41
|
+
|
42
|
+
class App #:nodoc: all
|
43
|
+
|
44
|
+
# Get the version number from the version file.
|
45
|
+
# This keeps it consistent.
|
46
|
+
#
|
47
|
+
VERSION = Csspress::VERSION::STRING
|
48
|
+
|
49
|
+
# The command line flags passed into the application
|
50
|
+
#
|
51
|
+
attr_reader :options
|
52
|
+
|
53
|
+
# Initalise the App object with the command line arguments
|
54
|
+
# and standared input. Also set up the @options object with
|
55
|
+
# and default settings.
|
56
|
+
#
|
57
|
+
def initialize(arguments, stdin)
|
58
|
+
@arguments = arguments
|
59
|
+
@stdin = stdin
|
60
|
+
# Set defaults
|
61
|
+
@options = OpenStruct.new
|
62
|
+
# e.g. @options.stats = true
|
63
|
+
end
|
64
|
+
|
65
|
+
# Parse the cmd line options, check arguments,
|
66
|
+
# then process the command.
|
67
|
+
#
|
68
|
+
def run
|
69
|
+
if parsed_options? && arguments_valid?
|
70
|
+
process_arguments
|
71
|
+
process_command
|
72
|
+
else
|
73
|
+
output_usage
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
protected
|
78
|
+
|
79
|
+
# Check all options are valid and execute their behaviour
|
80
|
+
#
|
81
|
+
def parsed_options?
|
82
|
+
# Specify options
|
83
|
+
opts = OptionParser.new
|
84
|
+
|
85
|
+
# Flag ---------------------> Behaviour
|
86
|
+
opts.on('-v', '--version') { output_version ; exit 0 }
|
87
|
+
opts.on('-h', '--help') { output_help }
|
88
|
+
opts.on('-s', '--stats') { @options.stats = true }
|
89
|
+
|
90
|
+
# Parse the ARGS for options and return false if this fails
|
91
|
+
opts.parse!(@arguments) rescue return false
|
92
|
+
|
93
|
+
# options parsed successfully
|
94
|
+
true
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
# Confirms that a file argument has been passed in
|
99
|
+
#
|
100
|
+
def arguments_valid?
|
101
|
+
# check args has 1 field (file name)
|
102
|
+
true if @arguments.length == 1
|
103
|
+
end
|
104
|
+
|
105
|
+
def output_help
|
106
|
+
output_version
|
107
|
+
# FIXME: Having to do this manually at the moment
|
108
|
+
# because RubyGems breaks this
|
109
|
+
#RDoc::usage() #exits app
|
110
|
+
#output_usage
|
111
|
+
end
|
112
|
+
|
113
|
+
def output_usage
|
114
|
+
# FIXME: Having to do this manually at the moment
|
115
|
+
# because RubyGems breaks this
|
116
|
+
# RDoc::usage('usage') # gets usage from comments above
|
117
|
+
puts "\nUsage\n" +
|
118
|
+
" css [options] source_file\n" +
|
119
|
+
"\n" +
|
120
|
+
"For help use:\n" +
|
121
|
+
" css -h\n\n"
|
122
|
+
end
|
123
|
+
|
124
|
+
def output_version
|
125
|
+
puts "CSSpress version #{VERSION}"
|
126
|
+
end
|
127
|
+
|
128
|
+
# Setup the arguments
|
129
|
+
def process_arguments
|
130
|
+
# TO DO - place in local vars, etc
|
131
|
+
end
|
132
|
+
|
133
|
+
# use CSSpress on the file that was passed in.
|
134
|
+
# and output that file to pressed_filename.css
|
135
|
+
#
|
136
|
+
def process_command
|
137
|
+
begin
|
138
|
+
file_in = @arguments[0]
|
139
|
+
# Get the dir
|
140
|
+
path = File.dirname(file_in)
|
141
|
+
# Get the file name
|
142
|
+
name = File.basename(file_in)
|
143
|
+
|
144
|
+
# Create name for tar file
|
145
|
+
file_out = "csspress-" << name.dup
|
146
|
+
|
147
|
+
# Do the compression stuff
|
148
|
+
ss = StyleSheet.new
|
149
|
+
ss.load( file_in )
|
150
|
+
tb = TemplateBuilder.new( ss )
|
151
|
+
|
152
|
+
# Change working dir to files dir
|
153
|
+
Dir.chdir(path)
|
154
|
+
|
155
|
+
out = File.new( file_out, "w" )
|
156
|
+
out.write(tb.publish)
|
157
|
+
out.close
|
158
|
+
rescue Declaration::PropertyError => e
|
159
|
+
puts e
|
160
|
+
rescue IOError => e
|
161
|
+
puts e
|
162
|
+
end
|
163
|
+
output_stats(file_in, file_out) if @options.stats
|
164
|
+
#process_standard_input # [Optional]
|
165
|
+
end
|
166
|
+
|
167
|
+
#def process_standard_input
|
168
|
+
# input = @stdin.read
|
169
|
+
# TO DO - process input
|
170
|
+
|
171
|
+
# [Optional]
|
172
|
+
# @stdin.each do |line|
|
173
|
+
# # TO DO - process each line
|
174
|
+
#end
|
175
|
+
#end
|
176
|
+
|
177
|
+
# Output file size saving following compression
|
178
|
+
# in bytes and as a percentage of the original.
|
179
|
+
#
|
180
|
+
def output_stats(original, compressed)
|
181
|
+
# Get the size of both files
|
182
|
+
original_size = File.stat(original).size
|
183
|
+
compressed_size = File.stat(compressed).size
|
184
|
+
|
185
|
+
# Calculate size difference in bytes
|
186
|
+
diff = (original_size - compressed_size)
|
187
|
+
|
188
|
+
# Calculate this as a percentage of the original
|
189
|
+
per = (diff.to_f / original_size.to_f) * 100
|
190
|
+
|
191
|
+
# print to terminal
|
192
|
+
puts "CSSpress saved #{diff} bytes (#{per.floor}%)."
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Create and run the application
|
197
|
+
app = App.new(ARGV, STDIN)
|
198
|
+
app.run
|
data/config/hoe.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'csspress/version'
|
2
|
+
|
3
|
+
AUTHOR = 'David Madden' # can also be an array of Authors
|
4
|
+
EMAIL = "csspress@moose56.com"
|
5
|
+
DESCRIPTION = "Strip white space and comments from CSS as well as a little optimization."
|
6
|
+
GEM_NAME = 'csspress' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'csspress' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
# ['activesupport', '>= 1.3.1']
|
12
|
+
] # An array of rubygem dependencies [name, version]
|
13
|
+
|
14
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
15
|
+
@config = nil
|
16
|
+
RUBYFORGE_USERNAME = "moose56"
|
17
|
+
def rubyforge_username
|
18
|
+
unless @config
|
19
|
+
begin
|
20
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
21
|
+
rescue
|
22
|
+
puts <<-EOS
|
23
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
24
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
25
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
26
|
+
EOS
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
REV = nil
|
35
|
+
# UNCOMMENT IF REQUIRED:
|
36
|
+
# REV = YAML.load(`svn info`)['Revision']
|
37
|
+
VERS = Csspress::VERSION::STRING + (REV ? ".#{REV}" : "")
|
38
|
+
RDOC_OPTS = ['--quiet', '--title', 'csspress documentation',
|
39
|
+
"--opname", "index.html",
|
40
|
+
"--line-numbers",
|
41
|
+
"--main", "README",
|
42
|
+
"--inline-source"]
|
43
|
+
|
44
|
+
class Hoe
|
45
|
+
def extra_deps
|
46
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
47
|
+
@extra_deps
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generate all the Rake tasks
|
52
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
53
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
54
|
+
p.developer(AUTHOR, EMAIL)
|
55
|
+
p.description = DESCRIPTION
|
56
|
+
p.summary = DESCRIPTION
|
57
|
+
p.url = HOMEPATH
|
58
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
59
|
+
p.test_globs = ["test/**/test_*.rb"]
|
60
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
61
|
+
|
62
|
+
# == Optional
|
63
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
64
|
+
#p.extra_deps = EXTRA_DEPENDENCIES
|
65
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
66
|
+
end
|
67
|
+
|
68
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
69
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
70
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
71
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
72
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
data/lib/csspress.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Press out only the juice worth serving from you CSS files (and optimize it a little while your at it).
|
2
|
+
#
|
3
|
+
# For usage see README
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
6
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
7
|
+
|
8
|
+
# As this file is added to the path, all application classes are requred here.
|
9
|
+
#
|
10
|
+
# (In the future it may be better to have the classes require what they need
|
11
|
+
# themselves as opposed to this)
|
12
|
+
#
|
13
|
+
require "csspress/declaration"
|
14
|
+
require "csspress/rule"
|
15
|
+
require "csspress/style_sheet"
|
16
|
+
require "csspress/template_builder"
|
17
|
+
require "csspress/version"
|
18
|
+
|
19
|
+
module Csspress
|
20
|
+
|
21
|
+
end
|