Ejemplo n.º 1
0
    def testOnlySource_withRulesAndBlocks(self):
        file_map = {
            'docA.md': self.join_lines(
                'outer content',
                '<block blockA>',
                'inner content',
                '</block blockA>',
                'outer content'),
        }
        class AppliedRule(Rule):
            counter = 0
            def apply(self, content):
                self.counter += 1
                return 'segment {}: '.format(self.counter) + content
        config_builder = ConfigBuilder()
        config_builder.append_postprocess_rules(AppliedRule())

        with self.mock_open(file_map):
            result = publish(config_builder.build(), source='docA.md', no_write=True)
        self.assertEquals(
            self.join_lines(
                'segment 1: outer content',
                'segment 2: inner content',
                'segment 3: outer content'),
            result)
Ejemplo n.º 2
0
    def testOnlySource_withRulesAndBlocks(self):
        file_map = {
            'docA.md':
            self.join_lines('outer content', '<block blockA>', 'inner content',
                            '</block blockA>', 'outer content'),
        }

        class AppliedRule(Rule):
            counter = 0

            def apply(self, content):
                self.counter += 1
                return 'segment {}: '.format(self.counter) + content

        config_builder = ConfigBuilder()
        config_builder.append_postprocess_rules(AppliedRule())

        with self.mock_open(file_map):
            result = publish(config_builder.build(),
                             source='docA.md',
                             no_write=True)
        self.assertEquals(
            self.join_lines('segment 1: outer content',
                            'segment 2: inner content',
                            'segment 3: outer content'), result)
Ejemplo n.º 3
0
    def testOnlySource_withRules(self):
        file_map = {
            'docA.md': 'original content',
        }
        class AppliedRule(Rule):
            def apply(self, content):
                return content + ' rule1'
        class NotAppliedRule(Rule):
            def apply(self, content):
                return content + 'rule2'
        config_builder = ConfigBuilder()
        config_builder.append_preprocess_rules(
                AppliedRule(src=r'\.md'),
                NotAppliedRule(dst=r'\.html'))
        config_builder.append_postprocess_rules(AppliedRule(), NotAppliedRule(src=r'\.py'))

        with self.mock_open(file_map):
            result = publish(config_builder.build(), source='docA.md', no_write=True)
        self.assertEquals('original content rule1 rule1', result)
Ejemplo n.º 4
0
    def testOnlySource_withRules(self):
        file_map = {
            'docA.md': 'original content',
        }

        class AppliedRule(Rule):
            def apply(self, content):
                return content + ' rule1'

        class NotAppliedRule(Rule):
            def apply(self, content):
                return content + 'rule2'

        config_builder = ConfigBuilder()
        config_builder.append_preprocess_rules(AppliedRule(src=r'\.md'),
                                               NotAppliedRule(dst=r'\.html'))
        config_builder.append_postprocess_rules(AppliedRule(),
                                                NotAppliedRule(src=r'\.py'))

        with self.mock_open(file_map):
            result = publish(config_builder.build(),
                             source='docA.md',
                             no_write=True)
        self.assertEquals('original content rule1 rule1', result)
Ejemplo n.º 5
0
 def testRules(self):
     rule1, rule2, rule3, = Rule(), Rule(), Rule()
     builder = ConfigBuilder().append_preprocess_rules(rule1)
     builder.append_compiler_rules(rule2)
     builder.append_postprocess_rules(rule3)
     self.assertSequenceEqual([rule1, rule2, rule3], builder.build().rules)