本文整理汇总了Python中blowdrycss.breakpointparser.BreakpointParser类的典型用法代码示例。如果您正苦于以下问题:Python BreakpointParser类的具体用法?Python BreakpointParser怎么用?Python BreakpointParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BreakpointParser类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_display_True
def test_is_display_True(self):
valid_css_classes = ('display-small-down', 'medium-only', 'giant-up', 'display-720-up', 'display-369-down')
names = ('display', 'display', 'display', 'display', 'display', )
values = ('none', 'none', 'none', 'none', 'none', )
for i, css_class in enumerate(valid_css_classes):
css_property = Property(name=names[i], value=values[i], priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
self.assertTrue(breakpoint_parser.is_display(), msg=css_class)
示例2: test_build_media_query_invalid_limit_key
def test_build_media_query_invalid_limit_key(self):
css_class = 'padding-100-small-up'
name = 'padding'
value = px_to_em('100')
expected = ''
css_property = Property(name=name, value=value, priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
breakpoint_parser.limit_key = 'invalid_key'
css = breakpoint_parser.build_media_query()
self.assertEqual(css, expected)
示例3: test_css_for_up_wrong_limit_key
def test_css_for_up_wrong_limit_key(self):
css_class = 'padding-100-small-up'
name = 'padding'
value = px_to_em('100')
expected = ''
css_property = Property(name=name, value=value, priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
breakpoint_parser.limit_key = '-only' # Change to WRONG LIMIT KEY
css = breakpoint_parser.css_for_up()
self.assertEqual(css, expected)
示例4: test_set_limit_key
def test_set_limit_key(self):
valid_css_classes = ['inline-small-up', 'inline-giant-down-i', 'green-xxsmall-only', 'padding-10-large-up', ]
names = ['display', 'display', 'color', 'padding', ]
values = ['inline', 'inline', 'green', '10', ]
priorities = ['', 'important', '', '', ]
expected = ['-up', '-down', '-only', '-up', ]
for i, css_class in enumerate(valid_css_classes):
css_property = Property(name=names[i], value=values[i], priority=priorities[i])
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
breakpoint_parser.set_limit_key()
self.assertEqual(breakpoint_parser.limit_key, expected[i])
示例5: test_is_display_False
def test_is_display_False(self):
invalid_css_classes = (
'inline-small-up', 'inline-giant-down', 'green-xxsmall-only', 'padding-10-large-up',
'padding-25-820-up', 'margin-5-2-5-2-1000-up',
)
names = ('display', 'display', 'color', 'padding', 'padding', 'margin', )
values = ('inline', 'inline', 'green', '10', '25', '5-2-5-2', )
for i, css_class in enumerate(invalid_css_classes):
css_property = Property(name=names[i], value=values[i], priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
self.assertFalse(breakpoint_parser.is_display(), msg=css_class)
示例6: test_strip_breakpoint_limit
def test_strip_breakpoint_limit(self):
valid_css_classes = [
'inline-small-up', 'inline-giant-down', 'green-xxsmall-only', 'padding-10-large-up',
'xlarge-only', 'large-down', 'xsmall-up',
]
names = ['display', 'display', 'color', 'padding', 'display', 'display', 'display', ]
values = ['inline', 'inline', 'green', '10', 'none', 'none', 'none', ]
expected = ['inline', 'inline', 'green', 'padding-10', '', '', '', ]
for i, css_class in enumerate(valid_css_classes):
css_property = Property(name=names[i], value=values[i], priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
clean_css_class = breakpoint_parser.strip_breakpoint_limit()
self.assertEqual(clean_css_class, expected[i])
示例7: test_build_media_query_up_general_usage
def test_build_media_query_up_general_usage(self):
css_class = 'padding-100-small-up'
name = 'padding'
value = px_to_em('100')
expected = (
'@media only screen and (min-width: 15.0625em) {\n' +
'\t.padding-100-small-up {\n' +
'\t\tpadding: 6.25em;\n' +
'\t}\n' +
'}\n\n'
)
css_property = Property(name=name, value=value, priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
css = breakpoint_parser.build_media_query()
self.assertEqual(css, expected)
示例8: test_build_media_query_up_display
def test_build_media_query_up_display(self):
css_class = 'display-small-up'
name = 'display'
value = 'none'
expected = (
'@media only screen and (max-width: 15.0625em) {\n' +
'\t.display-small-up {\n' +
'\t\tdisplay: none;\n' +
'\t}\n' +
'}\n\n'
)
css_property = Property(name=name, value=value, priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
css = breakpoint_parser.build_media_query()
self.assertEqual(css, expected)
示例9: test_css_for_up_display_custom
def test_css_for_up_display_custom(self):
css_class = 'display-720-up'
name = 'display'
value = 'none'
expected = (
'@media only screen and (max-width: 45.0em) {\n' +
'\t.display-720-up {\n' +
'\t\tdisplay: none;\n' +
'\t}\n' +
'}\n\n'
)
css_property = Property(name=name, value=value, priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
css = breakpoint_parser.css_for_up()
self.assertEqual(css, expected)
示例10: test_css_for_down_general_usage
def test_css_for_down_general_usage(self):
css_class = 'padding-100-medium-down'
name = 'padding'
value = px_to_em('100')
expected = (
'@media only screen and (max-width: 45.0em) {\n' +
'\t.padding-100-medium-down {\n' +
'\t\tpadding: 6.25em;\n' +
'\t}\n' +
'}\n\n'
)
css_property = Property(name=name, value=value, priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
css = breakpoint_parser.css_for_down()
self.assertEqual(css, expected)
示例11: test_css_for_down_display_custom
def test_css_for_down_display_custom(self):
css_class = 'display-369-down'
name = 'display'
value = 'none'
expected = (
'@media only screen and (min-width: 23.0625em) {\n' +
'\t.display-369-down {\n' +
'\t\tdisplay: none;\n' +
'\t}\n' +
'}\n\n'
)
css_property = Property(name=name, value=value, priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
css = breakpoint_parser.css_for_down()
self.assertEqual(css, expected)
示例12: test_css_for_only_general_usage_important
def test_css_for_only_general_usage_important(self):
css_class = 'padding-100-large-only-i'
name = 'padding'
value = px_to_em('100')
priority = 'important'
expected = (
'@media only screen and (min-width: 45.0625em) and (max-width: 64.0em) {\n' +
'\t.padding-100-large-only-i {\n' +
'\t\tpadding: 6.25em !important;\n' +
'\t}\n' +
'}\n\n'
)
css_property = Property(name=name, value=value, priority=priority)
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
css = breakpoint_parser.css_for_only()
self.assertEqual(css, expected)
示例13: test_css_for_only_display_shorthand
def test_css_for_only_display_shorthand(self):
css_class = 'large-only'
name = 'display'
value = 'none'
expected = (
'@media only screen and (max-width: 45.0625em) {\n' +
'\t.large-only {\n' +
'\t\tdisplay: none;\n' +
'\t}\n' +
'}\n\n' +
'@media only screen and (min-width: 64.0em) {\n' +
'\t.large-only {\n' +
'\t\tdisplay: none;\n' +
'\t}\n' +
'}\n\n'
)
css_property = Property(name=name, value=value, priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
css = breakpoint_parser.css_for_only()
self.assertEqual(css, expected)
示例14: __init__
def __init__(self, property_parser=ClassPropertyParser()):
message = 'MediaQueryBuilder Running...'
print(message)
logging.debug(msg=message)
self.property_parser = property_parser
self.css_media_queries = set()
self.media_query_text = ''
not_media_classes = dict()
for css_class in self.property_parser.class_set:
name = self.property_parser.get_property_name(css_class=css_class)
priority = self.property_parser.get_property_priority(css_class=css_class)
clean_css_class = '' # Prevents css_class from being modified.
if name:
# value='inherit' since we do not know if the class is valid yet.
inherit_property = Property(name=name, value='inherit', priority=priority)
scaling_parser = ScalingParser(css_class=css_class, css_property=inherit_property)
is_scaling = scaling_parser.is_scaling
if is_scaling:
clean_css_class = scaling_parser.strip_scaling_flag()
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=inherit_property)
is_breakpoint = breakpoint_parser.is_breakpoint
if is_breakpoint:
clean_css_class = breakpoint_parser.strip_breakpoint_limit()
if is_breakpoint and is_scaling: # Mixed syntax
not_media_classes[css_class] = ' (Breakpoint and scaling media query syntax cannot be combined.)'
continue
if not is_breakpoint and not is_scaling: # Missing syntax
not_media_classes[css_class] = ' is not a media query css_class selector.'
continue
else:
not_media_classes[css_class] = ' is not a media query css_class selector.'
continue
if clean_css_class and property_parser.is_important(css_class=clean_css_class):
clean_css_class = property_parser.strip_priority_designator(css_class=clean_css_class)
# Set property value.
# Handles case where css_class equals 'small-down', 'large-only', 'medium-up', etc.
# Specifically handle the 'display' case.
if clean_css_class and clean_css_class != 'display':
# Can return an empty string '' if css_class does not match any patterns in the property_alias_dict.
try:
encoded_property_value = self.property_parser.get_encoded_property_value(
property_name=name,
css_class=clean_css_class
)
value = self.property_parser.get_property_value(
property_name=name,
encoded_property_value=encoded_property_value
)
except ValueError: # Impossible to get here if get_property_name() is working properly.
not_media_classes[css_class] = ' property_name not found in property_alias_dict.'
continue
else:
value = 'none' # Breakpoint Parser Case -> display: none;
# Build CSS Property AND Add to css_media_queries OR Remove invalid css_class from class_set.
try:
css_property = Property(name=name, value=value, priority=priority)
if css_property.valid:
if is_breakpoint and breakpoint_parser:
breakpoint_parser.css_property = css_property
media_query = breakpoint_parser.build_media_query()
self.css_media_queries.add(media_query)
if is_scaling:
scaling_parser.css_property = css_property
media_query = scaling_parser.build_media_query()
self.css_media_queries.add(media_query)
else:
not_media_classes[css_class] = ' (cssutils invalid property value: ' + value + ')'
continue
# This exception can't be tested as clean_class_set() and get_property_value() prevent it.(Triple Redundant)
except SyntaxErr: # Special Case - Not Tested
not_media_classes[css_class] = ' (cssutils SyntaxErr invalid property value: ' + value + ')'
continue
# Clean out invalid CSS Classes.
for invalid_css_class, reason in not_media_classes.items():
self.property_parser.class_set.remove(invalid_css_class)
self.property_parser.removed_class_set.add(invalid_css_class + reason)