webcode-tk 0.7.4__tar.gz → 0.7.5__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.
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/PKG-INFO +1 -1
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/pyproject.toml +1 -1
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/webcode_tk/__init__.py +1 -1
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/webcode_tk/css_tools.py +119 -1
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/LICENSE.rst +0 -0
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/README.rst +0 -0
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/webcode_tk/color_keywords.py +0 -0
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/webcode_tk/color_tools.py +0 -0
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/webcode_tk/html_tools.py +0 -0
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/webcode_tk/ux_tools.py +0 -0
- {webcode_tk-0.7.4 → webcode_tk-0.7.5}/webcode_tk/validator_tools.py +0 -0
|
@@ -1295,7 +1295,12 @@ def get_color_codes_of_type(color_type: str, gradient: str) -> list:
|
|
|
1295
1295
|
|
|
1296
1296
|
|
|
1297
1297
|
def is_required_selector(selector_type: str, selector: str) -> bool:
|
|
1298
|
-
"""checks selector to see if it's required type or not
|
|
1298
|
+
"""checks selector to see if it's required type or not.
|
|
1299
|
+
|
|
1300
|
+
Example: you may wish to loop through selectors and see which
|
|
1301
|
+
ones are class selectors, or id selectors, etc..
|
|
1302
|
+
|
|
1303
|
+
It makes use of the list of regex_patterns for selector type.
|
|
1299
1304
|
|
|
1300
1305
|
Args:
|
|
1301
1306
|
selector_type: the type of selector in question, such as
|
|
@@ -1817,6 +1822,119 @@ def get_project_color_contrast(
|
|
|
1817
1822
|
return results
|
|
1818
1823
|
|
|
1819
1824
|
|
|
1825
|
+
def file_applies_property_by_selector(
|
|
1826
|
+
file_path: str, selector: str, property: str
|
|
1827
|
+
) -> bool:
|
|
1828
|
+
"""determines whether a specific property is applied to selector or not.
|
|
1829
|
+
|
|
1830
|
+
Args:
|
|
1831
|
+
file_path: path to html doc in question.
|
|
1832
|
+
selector: CSS selector (or element) that the property is applied.
|
|
1833
|
+
property: the CSS property we are looking for.
|
|
1834
|
+
|
|
1835
|
+
Returns:
|
|
1836
|
+
applies_property: whether that selector applies the property or not.
|
|
1837
|
+
"""
|
|
1838
|
+
applies_property = False
|
|
1839
|
+
style_sheets = get_all_stylesheets_by_file(file_path)
|
|
1840
|
+
|
|
1841
|
+
# look for the selector get all declaration block
|
|
1842
|
+
declarations = []
|
|
1843
|
+
for sheet in style_sheets:
|
|
1844
|
+
declaration_block = get_declaration_block_from_selector(
|
|
1845
|
+
selector, sheet
|
|
1846
|
+
)
|
|
1847
|
+
if declaration_block:
|
|
1848
|
+
declarations.append(declaration_block)
|
|
1849
|
+
combined_declaration_block = "\n".join(declarations)
|
|
1850
|
+
if combined_declaration_block:
|
|
1851
|
+
# check for property in declaration_block
|
|
1852
|
+
declarations = combined_declaration_block.split(";")
|
|
1853
|
+
for declaration in declarations:
|
|
1854
|
+
try:
|
|
1855
|
+
prop, value = declaration.split(":")
|
|
1856
|
+
if property in prop:
|
|
1857
|
+
applies_property = True
|
|
1858
|
+
break
|
|
1859
|
+
except ValueError:
|
|
1860
|
+
print("Declaration is missing a colon!")
|
|
1861
|
+
return applies_property
|
|
1862
|
+
|
|
1863
|
+
|
|
1864
|
+
def get_declaration_block_from_selector(
|
|
1865
|
+
selector: str, style_sheet: Stylesheet
|
|
1866
|
+
) -> str:
|
|
1867
|
+
declaration_block = ""
|
|
1868
|
+
for ruleset in style_sheet.rulesets:
|
|
1869
|
+
cur_selector = ruleset.selector
|
|
1870
|
+
if selector in cur_selector:
|
|
1871
|
+
# Check for grouped selectors
|
|
1872
|
+
grouped_selectors = cur_selector.split(",")
|
|
1873
|
+
if len(grouped_selectors) > 1:
|
|
1874
|
+
for item in grouped_selectors:
|
|
1875
|
+
if selector in item:
|
|
1876
|
+
if " " not in item:
|
|
1877
|
+
declaration_block += ruleset.declaration_block.text
|
|
1878
|
+
break
|
|
1879
|
+
elif is_selector_at_end_of_descendant(selector, item):
|
|
1880
|
+
declaration_block += ruleset.declaration_block.text
|
|
1881
|
+
break
|
|
1882
|
+
|
|
1883
|
+
# Check for descendant selectors
|
|
1884
|
+
if " " in cur_selector:
|
|
1885
|
+
# we have a descendant selector
|
|
1886
|
+
if is_selector_at_end_of_descendant(selector, cur_selector):
|
|
1887
|
+
declaration_block += ruleset.declaration_block.text
|
|
1888
|
+
continue
|
|
1889
|
+
declaration_block += ruleset.declaration_block.text + "\n"
|
|
1890
|
+
return declaration_block
|
|
1891
|
+
|
|
1892
|
+
|
|
1893
|
+
def is_selector_at_end_of_descendant(selector: str, cur_selector: str) -> bool:
|
|
1894
|
+
"""returns whether a selector is at the end of a descendant selector"""
|
|
1895
|
+
selector_at_end_of_descendant = False
|
|
1896
|
+
selectors = cur_selector.split()
|
|
1897
|
+
if selector in selectors[-1]:
|
|
1898
|
+
# selector must be at the end of descendant selector
|
|
1899
|
+
# or it doesn't count
|
|
1900
|
+
selector_at_end_of_descendant = True
|
|
1901
|
+
return selector_at_end_of_descendant
|
|
1902
|
+
|
|
1903
|
+
|
|
1904
|
+
def get_declaration_value_by_property(
|
|
1905
|
+
block: Union[str, DeclarationBlock], property: str
|
|
1906
|
+
) -> str:
|
|
1907
|
+
"""returns the value of a property from a declaration block
|
|
1908
|
+
|
|
1909
|
+
Args:
|
|
1910
|
+
block: the declaration block in question (could be as a string
|
|
1911
|
+
or as a DeclarationBlock)
|
|
1912
|
+
property: the property we are looking for
|
|
1913
|
+
|
|
1914
|
+
Returns:
|
|
1915
|
+
value: the value of the property"""
|
|
1916
|
+
value = ""
|
|
1917
|
+
try:
|
|
1918
|
+
block = block.text
|
|
1919
|
+
except AttributeError:
|
|
1920
|
+
declarations = block.strip()
|
|
1921
|
+
declarations = block.split(";")
|
|
1922
|
+
for item in declarations:
|
|
1923
|
+
item = item.strip()
|
|
1924
|
+
try:
|
|
1925
|
+
# check for @media rules
|
|
1926
|
+
if "{" in item:
|
|
1927
|
+
item_split = item.split("{")
|
|
1928
|
+
item = item_split[1].strip()
|
|
1929
|
+
prop, val = item.split(":")
|
|
1930
|
+
if prop.lower().strip() == property.lower():
|
|
1931
|
+
value = val.strip()
|
|
1932
|
+
continue
|
|
1933
|
+
except ValueError:
|
|
1934
|
+
print("Doh! no colon")
|
|
1935
|
+
return value
|
|
1936
|
+
|
|
1937
|
+
|
|
1820
1938
|
if __name__ == "__main__":
|
|
1821
1939
|
insane_gradient = """
|
|
1822
1940
|
-moz-radial-gradient(0% 200%, ellipse cover,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|