Example #1
0
    def test_custom_renderer ( self ):
        '''custom renderer'''

        def render_row ( tag, data ):
            T = html
            tag.clear ( )
            return tag [
                [ T.td [ _i ] for _i in data ]
            ]
        register_global ( 'render_row', render_row )

        vars = dict ( 
            title = my_name ( ),
            my_data = [
                range ( 5 ),
                range ( 5, 10 ),
                range ( 10, 15 )
            ]
        )
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise
Example #2
0
def test_register_global():
    """register_global() function"""
    params = dict(
        title=my_name()
    )
    register_global('global_message', 'This is a global variable')

    _test_name = my_name()
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
Example #3
0
    def test_register_global(self):
        '''register_global() function'''

        vars = dict(title=my_name())
        register_global('global_message', 'This is a global variable')

        test_name = my_name()
        t = Template(html, root=template_root())
        actual = t.render('index', vars, namespace='v')
        expected = expected_output()
        try:
            self.assertEqual(actual, expected)
        except AssertionError:
            diff(actual, expected)
            raise
Example #4
0
def test_custom_renderer_notag():
    """custom renderer returning non-Tag type"""
    def render_text(tag, data):
        tag.clear()
        return data
    register_global('render_text', render_text)

    params = dict(
        title=my_name(),
        message='hello, world'
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
Example #5
0
def test_register_flattener():
    """register_flattener() function"""
    def flatten_date(o):
        return escape(o.strftime('%Y/%m/%d'))
    register_flattener(datetime, flatten_date)
    register_global('flatten_date', flatten_date)

    params = dict(
        title=my_name(),
        today=datetime(2008, 4, 17)
    )
    _test_name = my_name()
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
Example #6
0
    def test_custom_renderer_notag(self):
        '''custom renderer returning non-Tag type'''
        def render_text(tag, data):
            tag.clear()
            return data

        register_global('render_text', render_text)

        vars = dict(title=my_name(), message='hello, world')
        t = Template(html, root=template_root())
        actual = t.render('index', vars, namespace='v')
        expected = expected_output()
        try:
            self.assertEqual(actual, expected)
        except AssertionError:
            diff(actual, expected)
            raise
Example #7
0
    def test_register_global ( self ):
        '''register_global() function'''

        vars = dict ( 
            title = my_name ( )
        )
        register_global ( 'global_message', 'This is a global variable' )

        test_name = my_name ( )
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise
Example #8
0
    def test_register_flattener(self):
        '''register_flattener() function'''
        def flatten_date(o):
            return escape(o.strftime('%Y/%m/%d'))

        register_flattener(datetime, flatten_date)
        register_global('flatten_date', flatten_date)

        vars = dict(title=my_name(), today=datetime(2008, 4, 17))
        test_name = my_name()
        t = Template(html, root=template_root())
        actual = t.render('index', vars, namespace='v')
        expected = expected_output()
        try:
            self.assertEqual(actual, expected)
        except AssertionError:
            diff(actual, expected)
            raise
Example #9
0
    def test_custom_loader_stack ( self ):
        '''custom loader stack'''

        class PathLoader ( object ):
            __slots__ = [ 'paths' ]

            def __init__ ( self, *paths ):
                self.paths = paths

            def stat ( self, template, root ):
                for p in self.paths:
                    f = os.path.join ( root, p, template )
                    if os.path.isfile ( f ):
                        timestamp = long ( os.stat ( f ).st_mtime )
                        uid = f
                        return uid, timestamp
                raise OSError, 'No such file or directory %s' % template

            def load ( self, uid ):
                return file ( uid, 'U' ).read ( )

        loader = PathLoader ( 
            template_root ( ), 
            os.path.join ( template_root ( ), 'path1' ), 
            os.path.join ( template_root ( ), 'path2' ), 
            os.path.join ( template_root ( ), 'path3' ), 
        )
        register_global ( 'path_loader', loader )
        
        vars = dict ( 
            title = my_name ( ),
            message = 'hello, world'
        )
        test_name = my_name ( )
        t = Template ( html, root = template_root ( ) ) 
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise
Example #10
0
    def test_custom_renderer(self):
        '''custom renderer'''
        def render_row(tag, data):
            T = html
            tag.clear()
            return tag[[T.td[_i] for _i in data]]

        register_global('render_row', render_row)

        vars = dict(title=my_name(),
                    my_data=[range(5), range(5, 10),
                             range(10, 15)])
        t = Template(html, root=template_root())
        actual = t.render('index', vars, namespace='v')
        expected = expected_output()
        try:
            self.assertEqual(actual, expected)
        except AssertionError:
            diff(actual, expected)
            raise
Example #11
0
    def test_custom_renderer_notag ( self ):
        '''custom renderer returning non-Tag type'''

        def render_text ( tag, data ):
            tag.clear ( )
            return data
        register_global ( 'render_text', render_text )

        vars = dict ( 
            title = my_name ( ),
            message = 'hello, world'
        )
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise
Example #12
0
    def test_register_flattener ( self ):
        '''register_flattener() function'''

        def flatten_date ( o ):
            return escape ( o.strftime ( '%Y/%m/%d' ) )
        register_flattener ( datetime, flatten_date )
        register_global ( 'flatten_date', flatten_date )

        vars = dict ( 
            title = my_name ( ),
            today = datetime ( 2008, 4, 17 )
        )
        test_name = my_name ( )
        t = Template ( html, root = template_root ( ) )
        actual = t.render ( 'index', vars, namespace = 'v' )
        expected = expected_output ( )
        try:
            self.assertEqual ( actual, expected )
        except AssertionError:
            diff ( actual, expected )
            raise
Example #13
0
def test_custom_renderer():
    """custom renderer"""
    def render_row(tag, data):
        T = html
        tag.clear()
        return tag[
            [T.td[_i] for _i in data]
        ]
    register_global('render_row', render_row)

    params = dict(
        title=my_name(),
        my_data=[
            range(5),
            range(5, 10),
            range(10, 15)
        ]
    )
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
Example #14
0
    def test_custom_loader_stack(self):
        '''custom loader stack'''
        class PathLoader(object):
            __slots__ = ['paths']

            def __init__(self, *paths):
                self.paths = paths

            def stat(self, template, root):
                for p in self.paths:
                    f = os.path.join(root, p, template)
                    if os.path.isfile(f):
                        timestamp = long(os.stat(f).st_mtime)
                        uid = f
                        return uid, timestamp
                raise OSError, 'No such file or directory %s' % template

            def load(self, uid):
                return file(uid, 'U').read()

        loader = PathLoader(
            template_root(),
            os.path.join(template_root(), 'path1'),
            os.path.join(template_root(), 'path2'),
            os.path.join(template_root(), 'path3'),
        )
        register_global('path_loader', loader)

        vars = dict(title=my_name(), message='hello, world')
        test_name = my_name()
        t = Template(html, root=template_root())
        actual = t.render('index', vars, namespace='v')
        expected = expected_output()
        try:
            self.assertEqual(actual, expected)
        except AssertionError:
            diff(actual, expected)
            raise
Example #15
0
def test_custom_loader_stack():
    """custom loader stack"""
    class PathLoader(object):
        __slots__ = ['paths']

        def __init__(self, *paths):
            self.paths = paths

        def stat(self, template, root):
            for p in self.paths:
                f = os.path.join(root, p, template)
                if os.path.isfile(f):
                    timestamp = int(os.stat(f).st_mtime)
                    uid = f
                    return uid, timestamp
            raise OSError('No such file or directory %s' % template)

        def load(self, uid):
            return open(uid, 'U').read()

    loader = PathLoader(
        template_root(),
        os.path.join(template_root(), 'path1'),
        os.path.join(template_root(), 'path2'),
        os.path.join(template_root(), 'path3'),
    )
    register_global('path_loader', loader)

    params = dict(
        title=my_name(),
        message='hello, world'
    )
    _test_name = my_name()
    t = Template(html, root=template_root())
    actual = t.render('index', params, namespace='v')
    expected = expected_output()
    assert actual == expected
Example #16
0
import logging 

import tornado.web
from tornado.web import _utf8
from tornado import httpclient, httputil
from tornado.options import options

import trombi
import breve
from breve.tags.html import tags as T

from libs.plugin import Plugins, PluginTemplateLoader

# plugins = Plugins ()
breve.register_global ('plugin_loader', PluginTemplateLoader ())

breve.register_global ('config', {
    'blog_url': options.url,
    'blog_title': options.title,
    'blog_description': options.description,
    'blog_author': options.author
})


def Template ():
    return breve.Template (T, options.templates)


def allow_any (*privileges):
    """returns a decorator that authorizes an OR joined list:
Example #17
0
        # no lexer found
        lexer = get_lexer_by_name ('text')
    parsed = highlight (u'\n'.join (content), lexer, PYGMENTS_FORMATTER)
    return [ nodes.raw (u'', parsed, format = 'html')]

pygments_directive.arguments = (1, 0, 1)
pygments_directive.content = 1
directives.register_directive ('sourcecode', pygments_directive)


# if there's an existing render_article_body(), save it
_render_article_body = breve.globals.get_globals ().get ('render_article_body', str)

def rst2html (content):
    if not content.startswith ('.. format: rst'):
        return _render_article_body (content)

    return breve.tags.xml (
        publish_parts (
            content, 
            writer_name="html",
            settings_overrides = { 
                'halt_level': 6,
                'file_insertion_enabled': 1,
                'raw_enabled': 1 
            }
        )["html_body"]
    )

breve.register_global ('render_article_body', rst2html)
Example #18
0
 def dbcallback (cls, db):
     cls.couchdb = db
     cls.plugins = Plugins (db)
     breve.register_global ('plugins', cls.plugins)
Example #19
0
            'tags': xhtml.tags}, 
    '(x)html': {
            'xml_encoding': '',
            'doctype': '<!DOCTYPE html>', 
            'xmlns': 'http://www.w3.org/1999/xhtml', 
            'tags': xhtml.tags},
    'html': {
            'xml_encoding': '',#XML Decl.
            'doctype': html4.doctype, # Doctype Decl.
            'xmlns': html4.xmlns, 
            'tags': html4.tags}
    }


for k in ['url_for', 'get_flashed_messages']:
    breve.register_global(k, getattr(flask, k))


class Breve(object):
    
    default_options = dict(
        #: extension for template file names
        #: breve adds a dot in any case
        extension = 'b', 
        
        #: XML declaration string
        xml_encoding = '', 
        #: Doctype declaration string
        doctype = '<!DOCTYPE html>', 
        xmlns = 'http://www.w3.org/1999/xhtml', 
        tags = xhtml.tags, 
Example #20
0
''' this plugin defines the schema and API for a blog
'''

depends  = ['theme']
provides = 'blog'
macros   = ['macros']
install  = {
    "views": {
        "articles_by_date": {
            "map": "function(doc) { if (doc.date) emit(doc.date, doc); }"
        }
    }
}


import breve

_render_article_body = breve.globals.get_globals ().get ('render_article_body', str)
breve.register_global ('render_article_body', _render_article_body)


Example #21
0
'''Uses jflickrfeed and jquery to display a flickr feed.
See http://www.gethifi.com/blog/a-jquery-flickr-feed-plugin for details.
You can obtain your flickr user ID at http://www.flickr.com/services/api/explore/?method=flickr.photos.getAllContexts
'''

settings = {
    'user_id': '30531103@N00',
    'thumb_count': 6
}

depends   = ['jquery']
js        = ['jflickrfeed.min.js']
css       = ['style.css']
templates = ['template']

import breve
breve.register_global ('flickr_data', settings)
Example #22
0
css       = ['pygments.css', 'style.css']
macros    = []
templates = []
js        = []
views     = []


import breve
import markdown

# if there's an existing render_article_body(), save it
_render_article_body = breve.globals.get_globals ().get ('render_article_body', str)

md = markdown.Markdown (
        extensions=['codehilite', 'footnotes'], 
        # extension_configs={'footnotes' : ('PLACE_MARKER','~~~~~~~~')},
        # safe_mode=True,
        output_format='xhtml'
)

def markdown2html (content):
    if not content.startswith ('<!-- format: markdown -->'):
        return _render_article_body (content)

    return breve.tags.xml (
        md.convert (content)
    )

breve.register_global ('render_article_body', markdown2html)