webcode-tk 1.0.1__tar.gz → 1.0.4__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: webcode-tk
3
- Version: 1.0.1
3
+ Version: 1.0.4
4
4
  Summary:
5
5
  Home-page: https://github.com/HundredVisionsGuy/webcode-tk
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "webcode-tk"
3
- version = "1.0.1"
3
+ version = "1.0.4"
4
4
  description = ""
5
5
  authors = ["hundredvisionsguy <cwinikka@gmail.com>"]
6
6
  keywords = ["html", "validation", "css", ]
@@ -18,4 +18,4 @@ Modules exported by this package:
18
18
  - `validator_tools`: sends HTML or CSS code to the W3C Validator to check
19
19
  for errors.
20
20
  """
21
- __version__ = "1.0.1"
21
+ __version__ = "1.0.4"
@@ -1493,7 +1493,7 @@ def update_contrast_results(
1493
1493
 
1494
1494
 
1495
1495
  def get_color_contrast_details(tree: CSSAppliedTree, rating="AAA") -> list:
1496
- """returns a list of all all failures or a pass based on rating
1496
+ """returns a list of all failures or a pass based on rating
1497
1497
 
1498
1498
  We'll create a recursive inner nested function to traverse the DOM. We will
1499
1499
  target only the styles that are applied directly so as to not overwhelm the
@@ -1567,7 +1567,12 @@ def get_color_contrast_details(tree: CSSAppliedTree, rating="AAA") -> list:
1567
1567
 
1568
1568
  for element in elements:
1569
1569
  check_element(element, rating, filename)
1570
- if not results:
1570
+ if results:
1571
+ adjusted = []
1572
+ for result in results:
1573
+ adjusted.append("fail: " + result)
1574
+ results = adjusted
1575
+ else:
1571
1576
  # It's a success! Let's let them know
1572
1577
  msg = f"success: {filename} passes color contrast for {rating} Normal"
1573
1578
  msg += " and Large."
@@ -2312,14 +2312,15 @@ def fonts_applied_report(project_dir: str, min=1, max=2) -> list:
2312
2312
  report = []
2313
2313
  all_file_data = get_styles_by_html_files(project_dir)
2314
2314
  for file in all_file_data:
2315
+ font_families_applied = []
2315
2316
  number_of_fonts = 0
2316
2317
  filename = clerk.get_file_name(file.get("file"))
2317
2318
  stylesheets = file.get("stylesheets")
2318
- font_styles = []
2319
2319
  for sheet in stylesheets:
2320
2320
  font_details = get_font_families(sheet)
2321
2321
  number_of_fonts += len(font_details)
2322
2322
  for item in font_details:
2323
+ results = None
2323
2324
  selector = item.get("selector")
2324
2325
  family = item.get("family")
2325
2326
  if "," in family:
@@ -2328,22 +2329,36 @@ def fonts_applied_report(project_dir: str, min=1, max=2) -> list:
2328
2329
  first_font = family
2329
2330
  first_font = first_font.replace("'", "")
2330
2331
  first_font = first_font.replace('"', "")
2332
+ if first_font not in font_families_applied:
2333
+ font_families_applied.append(first_font)
2331
2334
  if first_font.lower() == "times new roman":
2332
2335
  results = f"fail: {filename}: {selector} element was set "
2333
2336
  results += "to the default font"
2334
- elif number_of_fonts >= min and number_of_fonts <= max:
2335
- results = f"pass: {filename}: {selector} element "
2336
- results += f"was set to {first_font}"
2337
- elif number_of_fonts < min:
2338
- results = f"fail: {filename} did not apply {min} fonts, "
2339
- results += f"instead, it applied {number_of_fonts} fonts."
2340
- if results not in font_styles:
2341
- font_styles.append(results)
2342
- # We have all font styles applied
2343
- if not font_styles:
2344
- report.append(f"fail: {filename} No modified fonts for {filename}")
2345
- else:
2346
- report += font_styles
2337
+ num_fonts = len(font_families_applied)
2338
+ if num_fonts >= min and num_fonts <= max:
2339
+ results = f"pass: {filename} applied {num_fonts} "
2340
+ if num_fonts == 1:
2341
+ current_font = font_families_applied[0]
2342
+ results += f"font: {current_font}"
2343
+ else:
2344
+ results += "fonts:"
2345
+ for i in range(num_fonts):
2346
+ current_font = font_families_applied[i]
2347
+ if current_font == font_families_applied[-1]:
2348
+ results += f"and {current_font}"
2349
+ elif num_fonts > 2:
2350
+ results += f" {current_font}, "
2351
+ else:
2352
+ results += f" {current_font} "
2353
+ results += "."
2354
+ elif num_fonts < min:
2355
+ results = f"fail: {filename} did not apply {min} fonts, "
2356
+ results += f"instead, it applied {num_fonts} fonts."
2357
+ elif num_fonts > max:
2358
+ results = f"fail: {filename} applied too many fonts; "
2359
+ results += f" it applied {num_fonts} fonts."
2360
+ if results and results not in report:
2361
+ report.append(results)
2347
2362
  if not report:
2348
2363
  report.append("fail: no html files to apply font styling to")
2349
2364
  return report
@@ -262,6 +262,7 @@ def get_project_validation(project_dir: str, type="html") -> list:
262
262
  will return a list of per-files errors
263
263
  """
264
264
  report = []
265
+ passing_files = []
265
266
  all_files = clerk.get_all_project_files(project_dir)
266
267
  for file in all_files:
267
268
  errors = []
@@ -274,24 +275,37 @@ def get_project_validation(project_dir: str, type="html") -> list:
274
275
  f"fail: {filename} has {len(errors)} validation errors."
275
276
  )
276
277
  else:
277
- report.append(f"pass: {filename} passes HTML validation!")
278
+ passing_files.append(filename)
278
279
  else:
279
- if file_type == "html":
280
+ if file_type == "html" and type == "css":
280
281
  style_tag = html.get_elements("style", file)
281
282
  if style_tag:
282
283
  code = html.get_element_content(style_tag)
283
284
  result = validate_css(code)
284
- errors += get_css_errors_list(result)
285
+ errors_list = get_css_errors_list(result)
286
+ if errors_list:
287
+ errors += errors_list
288
+ else:
289
+ passing_files.append(filename)
285
290
  if file_type == "css":
286
291
  code = clerk.file_to_string(file)
287
292
  result = validate_css(code)
288
- errors += get_css_errors_list(result)
293
+ errors_list = get_css_errors_list(result)
294
+ if errors_list:
295
+ errors += errors_list
296
+ else:
297
+ passing_files.append(filename)
289
298
  if errors:
290
299
  report.append(
291
300
  f"fail: {filename} has {len(errors)} css errors."
292
301
  )
293
302
  if not report:
294
- report.append("fail: no files present to validate")
303
+ if passing_files:
304
+ for passing_file in passing_files:
305
+ msg = f"pass: {passing_file} passes {type.upper()} validation"
306
+ report.append(msg)
307
+ if not passing_files:
308
+ report.append("fail: no files present to validate")
295
309
  # TODO - make sure this covers all scenarios
296
310
  return report
297
311
 
File without changes
File without changes