Created
June 30, 2019 00:16
-
-
Save sveetch/5cb3ea1243404f6dc789a34b37d0e377 to your computer and use it in GitHub Desktop.
Attempt to parse foundation breakpoints to compare them in pixels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Attempt to parse breakpoints to compare them in pixels | |
""" | |
from collections import OrderedDict | |
base_font_size = 16 | |
base_font_unit = "px" | |
def em_to_px(base, value): | |
if value.endswith("em") or value.endswith("rem"): | |
if value.endswith("em"): | |
unitless_value = float(value[:-len("em")]) | |
elif value.endswith("rem"): | |
unitless_value = float(value[:-len("rem")]) | |
return "{}px".format(unitless_value * base) | |
return value | |
foundation_breakpoints = OrderedDict(( | |
("small", "0"), | |
("medium", "640px"), | |
("large", "1024px"), | |
("xlarge", "1200px"), | |
("xxlarge", "1440px"), | |
)) | |
print("Foundation $breakpoints") | |
print("-----------------------") | |
for name, value in foundation_breakpoints.items(): | |
print("{name} = {value}".format(name=name, value=value)) | |
print() | |
sveetoy_breakpoints = OrderedDict(( | |
("small-range", ("0em", "40em")), | |
("medium-range", ("40.063em", "63.9375em")), | |
("large-range", ("64em", "90em")), | |
("xlarge-range", ("90.063em", "120em")), | |
("xxlarge-range", ("120.063em",)), | |
)) | |
print("Sveetoy $sv-breakpoints") | |
print("-----------------------") | |
for name, values in sveetoy_breakpoints.items(): | |
if len(values) == 1: | |
sizes = [values[0], "infinite"] | |
elif len(values) == 2: | |
sizes = values | |
else: | |
print("Invalid item:", values, len(values)) | |
raise ValueError | |
print("{name} = {value}".format( | |
name=name, | |
value=" to ".join( | |
[em_to_px(base_font_size, i) for i in sizes] | |
) | |
)) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment