java.lang.Object
io.sf.carte.doc.style.css.util.Minify
Minify a CSS style sheet.
The regular minification methods first attempt a full minification by using the CSS parser, but in case that an unrecognized syntax is found, a safe, shallow minified serialization is used (with no CSS parsing involved).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Configuration of normal minification.static interface
Configuration common to shallow and normal minification. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Prints to standard output a minification of the CSS style sheet located at the supplied URI.static String
Minifies a CSS style sheet.static String
minifyCSS
(String css, Minify.Config config, PrintStream err) Minifies a CSS style sheet and prints parsing errors to a stream.static boolean
minifyCSS
(URL url, Minify.Config config, StringBuilder buffer, PrintStream err) Minifies a CSS style sheet.static String
Minifies a CSS style sheet.static boolean
minifyCSS
(Path cssPath, Minify.Config config, StringBuilder buffer) Minifies a CSS style sheet.static boolean
minifyCSS
(Path cssPath, Minify.Config config, StringBuilder buffer, PrintStream err) Minifies a CSS style sheet.static void
shallowMinify
(Reader cssReader, Minify.ShallowConfig config, StringBuilder buffer) Perform a safe, shallow minification that does not attempt to minify values nor media features.static void
shallowMinify
(Reader cssReader, StringBuilder buffer) Perform a safe, shallow minification that does not attempt to minify values nor media features.
-
Constructor Details
-
Minify
public Minify()
-
-
Method Details
-
main
public static void main(String[] args) throws URISyntaxException, IllegalArgumentException, IOException Prints to standard output a minification of the CSS style sheet located at the supplied URI.The argument array must contain the style sheet path or URI, and any additional configuration:
--charset
, followed by a valid character set name.--disable-shorthand
. If followed by a comma-separated list of shorthand names, it disables the advanced minification for those shorthands. If alone, all advanced shorthand minification is disabled (same as--disable-shorthand all
).
If the configuration options are invalid, exits with a status code of
2
.If the given sheet contains error(s), a shallower minification is performed and the process exits with a status of
1
.- Parameters:
args
- the arguments, including at least the URI or path to a style sheet.- Throws:
URISyntaxException
- if the URI has wrong syntax.IllegalArgumentException
- if the URI is otherwise incorrect.IOException
- if an I/O error happened.
-
minifyCSS
Minifies a CSS style sheet.- Parameters:
css
- the serialized style sheet.- Returns:
- the minified serialization.
-
minifyCSS
Minifies a CSS style sheet and prints parsing errors to a stream.- Parameters:
css
- the serialized style sheet.config
- the minification configuration, ornull
if defaults should be used.err
- the error reporting stream, ornull
if no stream.- Returns:
- the minified serialization.
-
minifyCSS
Minifies a CSS style sheet.- Parameters:
cssPath
- the path to autf-8
-encoded style sheet.- Returns:
- the minified serialization.
- Throws:
IOException
-
minifyCSS
public static boolean minifyCSS(Path cssPath, Minify.Config config, StringBuilder buffer) throws IOException Minifies a CSS style sheet.- Parameters:
cssPath
- the path to the style sheet.config
- the minification configuration, ornull
if defaults should be used.buffer
- the buffer to write the minified serialization, or the original file if an error is found.- Returns:
true
if the style sheet was fully minified,false
if an error was found and the minification was shallow.- Throws:
IOException
-
minifyCSS
public static boolean minifyCSS(Path cssPath, Minify.Config config, StringBuilder buffer, PrintStream err) throws IOException Minifies a CSS style sheet.- Parameters:
cssPath
- the path to the style sheet.config
- the minification configuration, ornull
if defaults should be used.buffer
- the buffer to write the minified serialization.err
- the error reporting stream, ornull
if no stream.- Returns:
true
if the style sheet was fully minified,false
if a syntax error was found and the minification was shallow.- Throws:
IOException
-
minifyCSS
public static boolean minifyCSS(URL url, Minify.Config config, StringBuilder buffer, PrintStream err) throws IOException Minifies a CSS style sheet.- Parameters:
url
- the url to the style sheet.config
- the minification configuration, ornull
if defaults should be used.buffer
- the buffer to write the minified serialization.err
- the error reporting stream, ornull
if no stream.- Returns:
true
if the style sheet was fully minified,false
if a syntax error was found and the minification was shallow.- Throws:
IOException
-
shallowMinify
Perform a safe, shallow minification that does not attempt to minify values nor media features.- Parameters:
cssReader
- theReader
with the style sheet.buffer
- the output buffer.- Throws:
IOException
- if an I/O error happened reading the style sheet.
-
shallowMinify
public static void shallowMinify(Reader cssReader, Minify.ShallowConfig config, StringBuilder buffer) throws IOException Perform a safe, shallow minification that does not attempt to minify values nor media features.- Parameters:
cssReader
- theReader
with the style sheet.config
- the minification configuration, ornull
if defaults should be used.buffer
- the output buffer.- Throws:
IOException
- if an I/O error happened reading the style sheet.
-