• Stars
    star
    1,188
  • Rank 39,371 (Top 0.8 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

NOT MAINTAINED

Deadweight

WARNING

This project is no longer maintained. I recommend that you use a different tool. I don't have a specific one to suggest, having never used any, but PurifyCSS and UnCSS both seem to be actively worked on.

Overview

Deadweight is a CSS coverage tool. Given a set of stylesheets and a set of URLs, it determines which selectors are actually used and reports which can be "safely" deleted.

Screencast!

Ryan Bates has worked his magic once again. Head over here for an excellent introduction to Deadweight.

How to Install It

$ gem install deadweight

How to Use It

There are multiple ways to use Deadweight. It's designed to be completely agnostic of whatever framework (or indeed language) your website is built on, but optimised for Ruby and Rails.

Run it From the Command Line

$ deadweight -s styles.css -s ie.css index.html about.html
$ deadweight -s http://www.tigerbloodwins.com/index.css http://www.tigerbloodwins.com/
$ deadweight --root http://kottke.org/ -s '/templates/2009/css.php?p=mac' / /everfresh /about

Integrate it With Your Integration Tests

Deadweight can hijack your Rails integration tests (both the spartan Test::Unit type and the refreshing Cucumber variety), capturing every page that is returned by your app during testing and saving you the trouble of manually specifying a ton of URLs and login processses.

First, put this in your Gemfile:

group :test do
  gem 'colored'
  gem 'deadweight', :require => 'deadweight/hijack/rails'
end

Then, run your integration tests with the environment variable DEADWEIGHT set to true:

rake test DEADWEIGHT=true
rake cucumber DEADWEIGHT=true

Let me know how it goes. It's not terribly customisable at the moment (you can't specify what exact stylesheets to look at, or what selectors to ignore). I'm looking for your feedback on how you'd like to be able to do that.

Rake Task

# lib/tasks/deadweight.rake

require 'deadweight'

Deadweight::RakeTask.new do |dw|
  dw.stylesheets = ["/stylesheets/style.css"]
  dw.pages = ["/", "/page/1", "/about"]
end

Running rake deadweight will output all unused rules, one per line. Note that it looks at http://localhost:3000 by default, so you'll need to have script/server (or whatever your server command looks like) running.

Call it Directly from Ruby

require 'deadweight'

dw = Deadweight.new
dw.stylesheets = ["/stylesheets/style.css"]
dw.pages = ["/", "/page/1", "/about"]
puts dw.run

Pipe In CSS Rules from STDIN

$ cat styles.css | deadweight index.html

Use it as an HTTP Proxy

$ deadweight -l deadweight.log -s styles.css -w http://github.com/ -P

Setting the Root URL

By default, Deadweight uses http://localhost:3000 as the base URL for all paths. To change it, set root:

dw.root = "http://staging.example.com"      # staging server
dw.root = "http://example.com/staging-area" # urls can have paths in
dw.root = "/path/to/some/html"              # local paths work too

What About Stuff Added by Javascript?

Deadweight is completely ignorant of classes, IDs or tags added by your Javascript layer, but you can filter them out by setting ignore_selectors:

dw.ignore_selectors = /hover|lightbox|superimposed_kittens/

The command-line tool also has basic support for Lyndon with the -L flag, which simply pipes all HTML through the lyndon executable to execute any embedded or linked JS.

You Can Use Mechanize for Complex Stuff

Set mechanize to true and add a Proc to pages (rather than a String), and Deadweight will execute it using Mechanize:

dw.mechanize = true

# go through the login form to get to a protected URL
dw.pages << proc {
  fetch('/login')
  form = agent.page.forms.first
  form.username = 'username'
  form.password = 'password'
  agent.submit(form)
  fetch('/secret-page')
}

# use HTTP basic auth
dw.pages << proc {
  agent.auth('username', 'password')
  fetch('/other-secret-page')
}

The agent method returns the Mechanize instance. The fetch method is a wrapper around agent.get that will abort in the event of an HTTP error status.

If You Install colored, It'll Look Nicer

gem install colored

Copyright

Copyright (c) 2009 Aanand Prasad. See LICENSE for details.

More Repositories

1

git-up

NOT MAINTAINED
Ruby
2,609
star
2

docker-wait

NOT MAINTAINED
Shell
154
star
3

jquery.tappable.js

NOT MAINTAINED
JavaScript
85
star
4

compose-file

Parser for the Compose file format (version 3)
Go
62
star
5

wick

NOT MAINTAINED
Ruby
33
star
6

do_notation

Haskell-style monad do-notation for Ruby
Ruby
25
star
7

gogol

A little sketch of a text-based time-rewinding game
CoffeeScript
17
star
8

cmon

HTML preprocessor for stable, cross-browser layouts
Ruby
16
star
9

itunes-web-interface

A web interface to iTunes
Ruby
14
star
10

feepogram

A tiny DSL for non-trivial bloopsaphone projects.
Ruby
10
star
11

docker-hubot

Dockerfile for building an IRC-enabled hubot
Shell
9
star
12

diversity-calculator

JavaScript
8
star
13

geocities-forever-html

HTML
8
star
14

anthrobot-twitterbot-example

Example Twitter bot using anthrobot. Source of https://twitter.com/_your_butt_
Python
7
star
15

tanktrum

A videogame.
Scala
6
star
16

datamosher

Python
6
star
17

shadowplay

JavaScript
6
star
18

jobdoer

JavaScript
4
star
19

do-notation.js

JavaScript
4
star
20

cdcovers

The source of cdcovers.heroku.com
Ruby
3
star
21

composit

Little HTML5 app that composites Flickr photos for any search term
JavaScript
3
star
22

geocities-forever

Python
3
star
23

re-readability

Arc90โ€™s Readability + John Holdunโ€™s Re-Reader = Aanand Prasadโ€™s Unnecessary Fussiness
Ruby
3
star
24

ive-seen-footage

Ruby
3
star
25

1901

A bloopsaphone cover of Phoenix's "1901"
Ruby
2
star
26

nnnnext

Source of nnnnext.com
JavaScript
2
star
27

wordpadbot

Python
2
star
28

compose-extends-demo

Python
2
star
29

anthrobot

Python
2
star
30

lrug-talk

1
star
31

aanand.github.com

HTML
1
star
32

fig-django-test

Python
1
star
33

howaboutnow

Python
1
star
34

NounNews

@NounNews Twitter Bot Source
Ruby
1
star
35

sass-align

nicely align property values in .sass files
Ruby
1
star
36

mandoline

Command-line tool to delete Cucumber features/scenarios by tag
Ruby
1
star
37

slitscanner

Python
1
star
38

transformers-talk

Ruby
1
star
39

vim-frank

The ignoble innocent.
Vim Script
1
star
40

docker-dnsutils

Docker image for Ubuntu's dnsutils package
Shell
1
star
41

scotruby-talk

Ruby
1
star
42

AirPiano

LeapMotion-controlled virtual piano. Not even nearly working yet.
C++
1
star