webcode-tk 1.2.0__tar.gz → 1.2.2__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.3
2
2
  Name: webcode-tk
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary:
5
5
  License: MIT
6
6
  Keywords: html,validation,css
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "webcode-tk"
3
- version = "1.2.0"
3
+ version = "1.2.2"
4
4
  description = ""
5
5
  authors = ["hundredvisionsguy <cwinikka@gmail.com>"]
6
6
  keywords = ["html", "validation", "css", ]
@@ -0,0 +1,38 @@
1
+ # __init__.py
2
+ """Deals with html and css documents to check their code.
3
+
4
+ ### Modules exported by this package:
5
+
6
+ - **`animation_tools`**: a library used to report back on animations applied.
7
+ As of now, we are focusing entirely on keyframe animations (not)
8
+ transitions.
9
+
10
+ - **`cascade_tools`**: library to calculate how the cascade affects font-size
11
+ and background color and color through inheritance and will be
12
+ used for calculating color contrast.
13
+
14
+ - **`color_keywords`**: helper library to align color keywords with their
15
+ properties and hex and rgb values.
16
+
17
+ - **`color_tools`**: processes CSS color related properties and values.
18
+
19
+ - **`css_tools`**: creates Stylesheet objects that store CSS information.
20
+
21
+ - **`font_tools`**: A collection of functions used to process font-related
22
+ styles.
23
+
24
+ - **`html_tools`**: gets html files from a project folder, gets the HTML code
25
+ from files, gets number of a particular element in a file
26
+ or folder, gets elements as tags, and much more.
27
+
28
+ - **`ux_tools`**: gets readability stats for paragraphs of text (could
29
+ be from just `p` tags or a list of other tags e.g. `li`,
30
+ `div`, etc.).
31
+
32
+ - **`utils.py`**: a library of helper functions to reduce the workload of the
33
+ other libraries.
34
+
35
+ - **`validator_tools`**: sends HTML or CSS code to the W3C Validator to check
36
+ for errors.
37
+ """
38
+ __version__ = "1.2.2"
@@ -2,6 +2,9 @@
2
2
  A group of functions that work with css_tools and cascade_tools to provide
3
3
  reports on CSS animations.
4
4
  """
5
+ from collections.abc import Iterable
6
+ from typing import Union
7
+
5
8
  from file_clerk import clerk
6
9
 
7
10
  from webcode_tk import css_tools
@@ -118,46 +121,85 @@ def get_keyframe_data(report: list) -> dict:
118
121
 
119
122
 
120
123
  def get_keyframe_report(
121
- keyframe_results: list, pct_goal: int, overall_goal: int
124
+ project_folder: str, num_goal: int, pct_goal=None, from_to_goals=None
122
125
  ) -> list:
123
- """returns a list of pass/fail messages (1 for each file)
126
+ """returns a list of pass/fail messages (1 for each goal in each file).
127
+
128
+ A report that allows you to set the minimum number of keyframes for each
129
+ file. By setting num_goal, you are stating how many keyframes in all you
130
+ expect to see in a project.
131
+
132
+ You can also set a minimum number of percentage keyframes, and the minimum
133
+ number of from {} and to {} keyframes.
134
+
135
+ NOTE: for every goal, there will be a report on that goal (one for each
136
+ file). If your project has two files, and you set all three goals (
137
+ num_goal, pct_goal, and from_to_goals), the report will create a list of
138
+ 6 messages.
124
139
 
125
140
  Args:
126
- keyframe_results: a list of filenames with number of percentage
127
- keyframes and from and to keyframes.
141
+ project_folder: the folder that houses the project.
142
+ num_goal: the minimum number of keyframes per file (overall)
128
143
  pct_goal: the minimum number of percentage keyframes we would want
129
144
  to see.
130
- overall_goal: the total number of keyframes in case there are not
131
- the minimum number of percentage keyframes.
145
+ from_to_goals: the minimum number of from and to keyframes.
132
146
 
133
147
  Returns:
134
148
  results: a list of messages (one for each file in the project) with
135
149
  a pass or fail with number present of each type.
136
150
  """
137
- results = []
138
- for item in keyframe_results:
139
- file, pct_keyframes, from_to_keyframes = item
140
- msg = ""
141
-
142
- # first check the percentage goal
143
- if pct_keyframes > pct_goal:
144
- msg = f"pass: {file} has {pct_keyframes} percentage keyframes."
151
+ report = []
152
+ animation_report = get_animation_report(project_folder)
153
+ keyframe_results = get_keyframe_data(animation_report)
154
+ for file, results in keyframe_results.items():
155
+ pct_keyframes = results["pct_keyframes"]
156
+ if isinstance(pct_keyframes, Iterable):
157
+ pct_keyframes = len(pct_keyframes)
158
+ num_froms_tos = results["froms_tos"]
159
+ if isinstance(num_froms_tos, Iterable):
160
+ num_froms_tos = len(num_froms_tos)
161
+ overall_num = pct_keyframes + num_froms_tos
162
+ if overall_num >= num_goal:
163
+ msg = f"pass: {file} has {overall_num} keyframes (enough "
164
+ msg += "overall to meet)."
145
165
  else:
146
- # if that fails, check overall
147
- num_overall = pct_keyframes + from_to_keyframes
148
- if num_overall >= overall_goal:
149
- msg = f"pass: {file} has {num_overall} keyframes (enough "
150
- msg += "overall to meet)."
166
+ remaining = num_goal - overall_num
167
+ msg = f"fail: {file} has only {overall_num} keyframes (needs "
168
+ msg += f"{remaining} more to pass)."
169
+ report.append(msg)
170
+ if pct_goal:
171
+ if pct_keyframes >= pct_goal:
172
+ msg = f"pass: {file} has {pct_keyframes} percentage "
173
+ msg += "keyframes."
174
+ else:
175
+ msg = f"fail: {file} does not have enough percentage "
176
+ msg += "keyframes to pass."
177
+ report.append(msg)
178
+ if from_to_goals:
179
+ if num_froms_tos >= from_to_goals:
180
+ msg = f"pass: {file} has {num_froms_tos} from and to "
181
+ msg += "keyframes."
151
182
  else:
152
- msg = f"fail: {file} does not have enough keyframes to pass."
153
- results.append(msg)
154
- return results
183
+ msg = f"fail: {file} does not have enough from and to "
184
+ msg += "keyframes to pass."
185
+ report.append(msg)
186
+ return report
155
187
 
156
188
 
157
189
  def get_animation_properties_report(
158
- animation_values: list, num_goal: int, specific_properties=None
159
- ):
160
- """returns a list of pass/fail messages (1 for each file)
190
+ project_folder: str, num_goal: int, specific_properties=None
191
+ ) -> list:
192
+ """returns a list of pass/fail messages based on number and type of
193
+ unique animation keyframe properties.
194
+
195
+ You can specify just the number of unique properties or you can specify
196
+ both the number as well as check for specific targetted properties. If you
197
+ specify both, both must be met for a pass.
198
+
199
+ NOTE: In the case of the transform properties, you can just specify
200
+ transform, or you can include the type of transform in the form of
201
+ transform- + the transform value (eg. transform-rotate(),
202
+ transform-translate(), transfrom-skew(), etc.)
161
203
 
162
204
  Since animation_values might have multiple entries for the same file,
163
205
  we need to track a per file record to see if it meets or not.
@@ -174,54 +216,46 @@ def get_animation_properties_report(
174
216
  results: a list of messages (one for each file in the project) with
175
217
  a pass or fail with number present of each type.
176
218
  """
177
- results = []
178
- properties_targetted = set()
179
- current_file = animation_values[0].get("file")
180
- for item in animation_values:
181
- filename = item.get("file")
182
- if filename != current_file:
183
- # we are on to a new file, it's time to create a message
219
+ report = []
220
+ animation_report = get_animation_report(project_folder)
221
+ for item in animation_report:
222
+ filename = utils.get_first_dict_key(item)
223
+ properties_targetted = item[filename].get("properties")
224
+ num_properties = len(properties_targetted)
225
+ num_remaining = num_goal - num_properties
226
+ if num_remaining > 0:
227
+ msg = f"fail: {filename} did not target enough properties; should"
228
+ msg += f"target {num_remaining} properties more."
229
+ report.append(msg)
230
+ else:
184
231
  if specific_properties:
185
232
  # make sure it's a list
186
233
  msg = get_targetted_properties_msg(
187
- specific_properties, properties_targetted, current_file
234
+ specific_properties, properties_targetted, filename
188
235
  )
189
- results.append(msg)
236
+ report.append(msg)
190
237
  else:
191
238
  # Now lets check for num of unique properties
192
239
  msg = get_num_properties_msg(
193
- num_goal, properties_targetted, current_file
240
+ num_goal, properties_targetted, filename
194
241
  )
195
- results.append(msg)
196
-
197
- # now is the time to restart our list of properties
198
- properties_targetted = set()
199
- current_file = filename
200
-
201
- # will need to change the key on the animations_values list
202
- properties = item.get("values_targetted")
203
- for property in properties:
204
- # add only unique properties
205
- properties_targetted.add(property)
206
-
207
- # process the current file (now that we're done looping)
208
- # check to see if there are any required properties
209
- if specific_properties:
210
- # make sure it's a list
211
- msg = get_targetted_properties_msg(
212
- specific_properties, properties_targetted, current_file
213
- )
214
- results.append(msg)
215
- else:
216
- # Now lets check for num of unique properties
217
- msg = get_num_properties_msg(
218
- num_goal, properties_targetted, current_file
219
- )
220
- results.append(msg)
221
- return results
242
+ report.append(msg)
243
+
244
+ # now is the time to restart our list of properties
245
+ properties_targetted = set()
246
+ return report
247
+
222
248
 
249
+ def get_num_properties_msg(
250
+ num_goal: int,
251
+ properties_targetted: Union[list, tuple, set],
252
+ current_file: str,
253
+ ) -> str:
254
+ """Returns a pass/fail message based on whether a file targets the min
255
+ number of properties found.
223
256
 
224
- def get_num_properties_msg(num_goal, properties_targetted, current_file):
257
+ Args:
258
+ num_goal: the number of unique properties that should be targetted"""
225
259
  num_unique_props = len(properties_targetted)
226
260
  if num_unique_props >= num_goal:
227
261
  msg = f"pass: {current_file}'s animations targetted the minimum "
@@ -235,8 +269,27 @@ def get_num_properties_msg(num_goal, properties_targetted, current_file):
235
269
 
236
270
 
237
271
  def get_targetted_properties_msg(
238
- properties, properties_targetted, current_file
239
- ):
272
+ properties: Union[list, tuple],
273
+ properties_targetted: Union[list, tuple],
274
+ current_file: str,
275
+ ) -> str:
276
+ """returns whether the file addresses all targetted keyframe properties or
277
+ not.
278
+
279
+ Receives the keyframe properties found in a file's styles and returns a
280
+ message that states whether the file has targetted all required properties
281
+ in the form of "pass" or "fail".
282
+
283
+ Args:
284
+ properties: a list or tuple of the keyframe properties targetted in a
285
+ file's stylesheets or not.
286
+ properties_targetted: a list or tuple of the properties that the file
287
+ should contain.
288
+ current_file: the name of the HTML document we are checking.
289
+
290
+ Returns:
291
+ msg: a string that begins with 'pass:' or 'fail:', and details on what
292
+ was missing if a fail."""
240
293
  properties = list(properties)
241
294
  for property in properties_targetted:
242
295
  if property in properties:
@@ -1,27 +0,0 @@
1
- # __init__.py
2
- """Deals with html and css documents to check their code.
3
-
4
- Modules exported by this package:
5
- - `animation_tools`: a library used to report back on animations applied. As
6
- of now, we are focusing entirely on keyframe animations (not)
7
- transitions.
8
- - `cascade_tools`: library to calculate how the cascade affects font-size
9
- and background color and color through inheritance and will be
10
- used for calculating color contrast.
11
- - `color_keywords`: helper library to align color keywords with their
12
- properties and hex and rgb values.
13
- - `color_tools`: processes CSS color related properties and values.
14
- - `css_tools`: creates Stylesheet objects that store CSS information.
15
- - `font_tools`: A collection of functions used to process font-related styles.
16
- - `html_tools`: gets html files from a project folder, gets the HTML code
17
- from files, gets number of a particular element in a file
18
- or folder, gets elements as tags, and much more.
19
- - `ux_tools`: gets readability stats for paragraphs of text (could
20
- be from just `p` tags or a list of other tags e.g. `li`,
21
- `div`, etc.).
22
- - `utils.py`: a library of helper functions to reduce the workload of the
23
- other libraries.
24
- - `validator_tools`: sends HTML or CSS code to the W3C Validator to check
25
- for errors.
26
- """
27
- __version__ = "1.2.0"
File without changes
File without changes