예제 #1
0
def app(environ, start_response):
    try:
        path = environ['PATH_INFO'].strip('/')
        if path == 'favicon.ico':
            return dispatch_resource('++resource++yafowil.demo/favicon.ico',
                                     environ, start_response)
        if path == 'pygments.css':
            return pygments_styles(environ, start_response)
        if path.startswith('++resource++'):
            return dispatch_resource(path, environ, start_response)
        if path.startswith('++widget++'):
            splitted = path.split('/')
            plugin_name = splitted[0][10:]
            resources = get_resources(plugin_name)
            example = get_example(plugin_name)
            if splitted[1] != 'index.html':
                return execute_route(
                    example,
                    splitted[1],
                    environ,
                    start_response
                )
            sections = list()
            for section in example:
                sections.append({
                    'id': section['widget'].name,
                    'title': section.get('title', section['widget'].name),
                })
            forms = render_forms(example, environ, plugin_name)
        else:
            plugin_name = None
            resources = get_resources()
            sections = list()
            forms = None
        templates = PageTemplateLoader(curdir)
        template = templates['main.pt']
        body = template(
            resources=resources,
            forms=forms,
            example_names=sorted(get_example_names()),
            sections=sections,
            current_name=plugin_name
        )
        return Response(body=body)(environ, start_response)
    except:
        return Response(body=format_traceback())(environ, start_response)
예제 #2
0
    def test_examples_lookup(self):
        # Test examples lookup
        self.check_output("""
        ['yafowil'...]
        """, str(sorted(get_example_names())))

        factory.register_macro('field', 'field:label:error', {})

        self.assertEqual(get_example('inexistent'), None)

        examples = get_example('yafowil')
        self.check_output("""
        Plain Text
        ----------
        ...
        """, examples[0]['doc'])

        self.assertEqual(examples[0]['title'], 'Plain Text')
        self.assertEqual(examples[0]['widget'].name, 'yafowil-plaintext')
예제 #3
0
    def test_examples_lookup(self):
        # Test examples lookup
        self.check_output("""
        ['yafowil'...]
        """, str(sorted(get_example_names())))

        factory.register_macro('field', 'field:label:error', {})

        self.assertEqual(get_example('inexistent'), None)

        examples = get_example('yafowil')
        self.check_output(
            """
        Plain Text
        ----------
        ...
        """, examples[0]['doc'])

        self.assertEqual(examples[0]['title'], 'Plain Text')
        self.assertEqual(examples[0]['widget'].name, 'yafowil-plaintext')
예제 #4
0
 def example_names(self):
     return sorted(get_example_names())