Ejemplo n.º 1
0

def markdown_preview(text, length=150):
    if not text:
        return ''
    try:
        md = html.fromstring(unicode(markdown(text)))
        text = md.text_content()
    except:
        pass
    if length: 
        text = truncate(text, length=length, whole_word=True)
    return text.replace('\n', ' ')


_flash = _Flash()


def flash_success(message):
    _flash(message, category='success')


def flash_error(message):
    _flash(message, category='error')


def flash_notice(message):
    _flash(message, category='notice')


def render_value(value):
Ejemplo n.º 2
0
def markdown(*args, **kwargs):
    return literal(_markdown(*args, **kwargs))


def markdown_preview(text, length=140):
    if not text:
        return ''
    md = html.fromstring(unicode(markdown(text)))
    text = md.text_content()
    if length:
        text = truncate(text, length=length, whole_word=True)
    return text


_flash = _Flash()


def flash_success(message):
    _flash(message, category='success')


def flash_error(message):
    _flash(message, category='error')


def flash_notice(message):
    _flash(message, category='notice')


def render_value(value):
Ejemplo n.º 3
0
import datetime
import xml.utils.iso8601 as iso8601

from docutils.core import publish_parts
from webhelpers.date import distance_of_time_in_words
from webhelpers.html.converters import textilize
from webhelpers.html.tags import auto_discovery_link, link_to, select, stylesheet_link
from webhelpers.text import truncate
from webhelpers.pylonslib import Flash as _Flash
from webhelpers.pylonslib.secure_form import auth_token_hidden_field
from webob.exc import strip_tags

from kai.lib.highlight import code_highlight, langdict


success_flash = _Flash('success')
failure_flash = _Flash('failure')

def load_stylesheet_assets():
    import pylons
    import os
    path = os.path.join(pylons.config['pylons.paths']['static_files'], 'css',
                        'CSSLIST')
    f = open(path,'r')
    stylesheets = f.read()
    f.close()
    return ['/css/%s.css' % f for f in stylesheets.split()]

def parse_iso_date(iso_date):
    return datetime.datetime.fromtimestamp(iso8601.parse(iso_date))
Ejemplo n.º 4
0
"""Helper functions

Consists of functions to typically be used within templates, but also
available to Controllers. This module is available to templates as 'h'.
"""

import re
from routes import util
from webhelpers.pylonslib import Flash as _Flash
flash = _Flash('flash')
error = _Flash('error')

github_re = re.compile(r'^(?:git|http)://github.com/([^/]*)/([^/]*).git$')
repo_or_cz_re = re.compile(r'^(?:git|http)://repo.or.cz/([^/]*)$')

def get_url(obj):
    return util.url_for(controller='query', action='query', id=obj.id)

def _github_handle(repo, obj, match):
    values = {'user' : match.group(1),
              'repo' : match.group(2),
              'sha1' : obj.id,
              'type' : obj.type}
    if obj.type == 'commit':
        return 'http://github.com/%(user)s/%(repo)s/commit/%(sha1)s' % values
    elif obj.type == 'tree' or obj.type == 'blob':
        path_pair = obj.get_path(repo)
        # Could be in the middle of indexing
        if not path_pair:
            return None
        commit, path = path_pair
Ejemplo n.º 5
0
# -*- coding: utf-8 -*-
#
# Copyright 2010 LDLP (Laboratoire Départemental de Prehistoire du Lazaret)
# http://lazaret.unice.fr/opensource/ - [email protected]
#
# This file is part of ArcheologicalAdressbook and is released under
# the GNU Affero General Public License 3 or any later version.
# See LICENSE.txt or <http://www.gnu.org/licenses/agpl.html>
#
""" Helper functions

Consists of functions to typically be used within templates, but also
available to Controllers. This module is available to templates as 'h'.

"""

from pylons import url
from webhelpers.html.tags import *
from webhelpers.html.tags import ModelTags
from webhelpers.html.tools import *
from webhelpers import paginate
from webhelpers.pylonslib.secure_form import secure_form
from webhelpers.pylonslib import Flash as _Flash


flash_message = _Flash()