当前位置: 首页>>代码示例>>Python>>正文


Python BreakpointParser.strip_breakpoint_limit方法代码示例

本文整理汇总了Python中blowdrycss.breakpointparser.BreakpointParser.strip_breakpoint_limit方法的典型用法代码示例。如果您正苦于以下问题:Python BreakpointParser.strip_breakpoint_limit方法的具体用法?Python BreakpointParser.strip_breakpoint_limit怎么用?Python BreakpointParser.strip_breakpoint_limit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blowdrycss.breakpointparser.BreakpointParser的用法示例。


在下文中一共展示了BreakpointParser.strip_breakpoint_limit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_strip_breakpoint_limit

# 需要导入模块: from blowdrycss.breakpointparser import BreakpointParser [as 别名]
# 或者: from blowdrycss.breakpointparser.BreakpointParser import strip_breakpoint_limit [as 别名]
    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])
开发者ID:godber,项目名称:blowdrycss,代码行数:16,代码来源:test_BreakpointParser.py

示例2: __init__

# 需要导入模块: from blowdrycss.breakpointparser import BreakpointParser [as 别名]
# 或者: from blowdrycss.breakpointparser.BreakpointParser import strip_breakpoint_limit [as 别名]
    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)
开发者ID:nueverest,项目名称:blowdrycss,代码行数:89,代码来源:mediaquerybuilder.py


注:本文中的blowdrycss.breakpointparser.BreakpointParser.strip_breakpoint_limit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。