Skip to content

Commit 155bfa2

Browse files
author
Juan Carlos
committed
Fix log
1 parent 4e24584 commit 155bfa2

File tree

1 file changed

+0
-24
lines changed

1 file changed

+0
-24
lines changed

css_html_js_minify/css_minifier.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import re
99
import itertools
1010

11-
import logging as log
12-
1311
from .variables import EXTENDED_NAMED_COLORS, CSS_PROPS_TEXT
1412

1513

@@ -78,7 +76,6 @@ def sort_properties(css_unsorted_string):
7876
sort it by defined rule, and return sorted buffer if it's CSS property.
7977
This function depends on '_prioritify' function.
8078
"""
81-
log.debug("Alphabetically Sorting all CSS / SCSS Properties.")
8279
css_pgs = _compile_props(CSS_PROPS_TEXT, grouped=False) # Do Not Group.
8380
pattern = re.compile(r'(.*?{\r?\n?)(.*?)(}.*?)|(.*)',
8481
re.DOTALL + re.MULTILINE)
@@ -102,7 +99,6 @@ def sort_properties(css_unsorted_string):
10299

103100
def remove_comments(css):
104101
"""Remove all CSS comment blocks."""
105-
log.debug("Removing all Comments.")
106102
iemac, preserve = False, False
107103
comment_start = css.find("/*")
108104
while comment_start >= 0: # Preserve comments that look like `/*!...*/`.
@@ -132,7 +128,6 @@ def remove_comments(css):
132128

133129
def remove_unnecessary_whitespace(css):
134130
"""Remove unnecessary whitespace characters."""
135-
log.debug("Removing all unnecessary white spaces.")
136131

137132
def pseudoclasscolon(css):
138133
"""Prevent 'p :link' from becoming 'p:link'.
@@ -168,19 +163,16 @@ def pseudoclasscolon(css):
168163

169164
def remove_unnecessary_semicolons(css):
170165
"""Remove unnecessary semicolons."""
171-
log.debug("Removing all unnecessary semicolons.")
172166
return re.sub(r";+\}", "}", css)
173167

174168

175169
def remove_empty_rules(css):
176170
"""Remove empty rules."""
177-
log.debug("Removing all unnecessary empty rules.")
178171
return re.sub(r"[^\}\{]+\{\}", "", css)
179172

180173

181174
def normalize_rgb_colors_to_hex(css):
182175
"""Convert `rgb(51,102,153)` to `#336699`."""
183-
log.debug("Converting all rgba to hexadecimal color values.")
184176
regex = re.compile(r"rgb\s*\(\s*([0-9,\s]+)\s*\)")
185177
match = regex.search(css)
186178
while match:
@@ -193,14 +185,12 @@ def normalize_rgb_colors_to_hex(css):
193185

194186
def condense_zero_units(css):
195187
"""Replace `0(px, em, %, etc)` with `0`."""
196-
log.debug("Condensing all zeroes on values.")
197188
return re.sub(r"([\s:])(0)(px|em|%|in|q|ch|cm|mm|pc|pt|ex|rem|s|ms|"
198189
r"deg|grad|rad|turn|vw|vh|vmin|vmax|fr)", r"\1\2", css)
199190

200191

201192
def condense_multidimensional_zeros(css):
202193
"""Replace `:0 0 0 0;`, `:0 0 0;` etc. with `:0;`."""
203-
log.debug("Condensing all multidimensional zeroes on values.")
204194
return css.replace(":0 0 0 0;", ":0;").replace(
205195
":0 0 0;", ":0;").replace(":0 0;", ":0;").replace(
206196
"background-position:0;", "background-position:0 0;").replace(
@@ -209,13 +199,11 @@ def condense_multidimensional_zeros(css):
209199

210200
def condense_floating_points(css):
211201
"""Replace `0.6` with `.6` where possible."""
212-
log.debug("Condensing all floating point values.")
213202
return re.sub(r"(:|\s)0+\.(\d+)", r"\1.\2", css)
214203

215204

216205
def condense_hex_colors(css):
217206
"""Shorten colors from #AABBCC to #ABC where possible."""
218-
log.debug("Condensing all hexadecimal color values.")
219207
regex = re.compile(
220208
r"""([^\"'=\s])(\s*)#([0-9a-f])([0-9a-f])([0-9a-f])"""
221209
r"""([0-9a-f])([0-9a-f])([0-9a-f])""", re.I | re.S)
@@ -234,19 +222,16 @@ def condense_hex_colors(css):
234222

235223
def condense_whitespace(css):
236224
"""Condense multiple adjacent whitespace characters into one."""
237-
log.debug("Condensing all unnecessary white spaces.")
238225
return re.sub(r"\s+", " ", css)
239226

240227

241228
def condense_semicolons(css):
242229
"""Condense multiple adjacent semicolon characters into one."""
243-
log.debug("Condensing all unnecessary multiple adjacent semicolons.")
244230
return re.sub(r";;+", ";", css)
245231

246232

247233
def wrap_css_lines(css, line_length=80):
248234
"""Wrap the lines of the given CSS to an approximate length."""
249-
log.debug("Wrapping lines to ~{0} max line lenght.".format(line_length))
250235
lines, line_start = [], 0
251236
for i, char in enumerate(css):
252237
# Its safe to break after } characters.
@@ -260,14 +245,12 @@ def wrap_css_lines(css, line_length=80):
260245

261246
def condense_font_weight(css):
262247
"""Condense multiple font weights into shorter integer equals."""
263-
log.debug("Condensing font weights on values.")
264248
return css.replace('font-weight:normal;', 'font-weight:400;').replace(
265249
'font-weight:bold;', 'font-weight:700;')
266250

267251

268252
def condense_std_named_colors(css):
269253
"""Condense named color values to shorter replacement using HEX."""
270-
log.debug("Condensing standard named color values.")
271254
for color_name, color_hexa in iter(tuple({
272255
':aqua;': ':#0ff;', ':blue;': ':#00f;',
273256
':fuchsia;': ':#f0f;', ':yellow;': ':#ff0;'}.items())):
@@ -277,7 +260,6 @@ def condense_std_named_colors(css):
277260

278261
def condense_xtra_named_colors(css):
279262
"""Condense named color values to shorter replacement using HEX."""
280-
log.debug("Condensing extended named color values.")
281263
for k, v in iter(tuple(EXTENDED_NAMED_COLORS.items())):
282264
same_color_but_rgb = 'rgb({0},{1},{2})'.format(v[0], v[1], v[2])
283265
if len(k) > len(same_color_but_rgb):
@@ -287,19 +269,16 @@ def condense_xtra_named_colors(css):
287269

288270
def remove_url_quotes(css):
289271
"""Fix for url() does not need quotes."""
290-
log.debug("Removing quotes from url.")
291272
return re.sub(r'url\((["\'])([^)]*)\1\)', r'url(\2)', css)
292273

293274

294275
def condense_border_none(css):
295276
"""Condense border:none; to border:0;."""
296-
log.debug("Condense borders values.")
297277
return css.replace("border:none;", "border:0;")
298278

299279

300280
def add_encoding(css):
301281
"""Add @charset 'UTF-8'; if missing."""
302-
log.debug("Adding encoding declaration if needed.")
303282
return '@charset "utf-8";' + css if "@charset" not in css.lower() else css
304283

305284

@@ -312,13 +291,11 @@ def restore_needed_space(css):
312291

313292
def unquote_selectors(css):
314293
"""Fix CSS for some specific selectors where Quotes is not needed."""
315-
log.debug("Removing unnecessary Quotes on selectors of CSS classes.")
316294
return re.compile('([a-zA-Z]+)="([a-zA-Z0-9-_\.]+)"]').sub(r'\1=\2]', css)
317295

318296

319297
def css_minify(css, wrap=False, comments=False, sort=False, noprefix=False):
320298
"""Minify CSS main function."""
321-
log.info("Compressing CSS...")
322299
css = remove_comments(css) if not comments else css
323300
css = sort_properties(css) if sort else css
324301
css = unquote_selectors(css)
@@ -339,5 +316,4 @@ def css_minify(css, wrap=False, comments=False, sort=False, noprefix=False):
339316
css = condense_semicolons(css)
340317
css = add_encoding(css) if not noprefix else css
341318
css = restore_needed_space(css)
342-
log.info("Finished compressing CSS !.")
343319
return css.strip()

0 commit comments

Comments
 (0)