0.0
No commit activity in last 3 years
No release in over 3 years
Gem that, given a collection of HTML documents and CSS files, will remove any class attributes in the HTML set to CSS selectors that do not exist in the CSS files.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.6
 Project Readme

CSSDeadClass

Remove undefined CSS class attributes from your HTML.

Purpose

This Gem will, given a set of HTML files and a set of CSS files, remove any mentions in the class attributes of HTML objects classes that are not defined in the CSS files.

Sample Usage

Given the following files

index.html

<html>
<body>
	<h1 class="happy sad">Heading</h1>
	<p class="red blue">Hello</p>
</body>
</html>

app.css

.red {
	color: red;
}

.happy {
	color: black;
}

Running CSSDeadClass on those two files will change index.html to the following, remove calls to .sad and .blue, as they do not exist:

<html>
<body>
	<h1 class="happy">Heading</h1>
	<p class="red">Hello</p>
</body>
</html>

Installation

Install using gem css_dead_class.

Configuration

CSSDeadClass takes three options:

:css_files

An array of file paths to CSS files to scan.

:html_files

An array of file paths to HTML files to scan.

:classes_to_keep

An array of CSS classes to keep, regardless of presence in the HTML files. Can either be of the form .classname or classname.

Usage

Sample usage in a ruby program:

require 'css_dead_classes'

css_deadfiles = CSSDeadClass.new({
	html_files: Dir.glob("**/*.html"),
	css_files: Dir.glob("**/*.css"),
	classes_to_keep: [
		".no-js",
		"blue"
	]
})
css_deadfiles.parse