Esempio n. 1
0
        def mapper(atom_field_name, tiddler, default):
            logging.debug(
                "atom-custom:: doing a mapping on field %s \n atom-custom::with tiddler %s \n atom-custom::and config %s"
                % (atom_field_name, tiddler, mappings))
            tid = Tiddler(tiddler['title'], tiddler['bag'])
            tid = serializer.as_tiddler(tid, tiddler)
            try:
                tid.recipe = tiddler['recipe']
            except KeyError:
                pass
            if atom_field_name in mappings:
                val = mappings[atom_field_name]
                if atom_field_name == 'link' or atom_field_name == 'id' and val.startswith(
                        "/"):
                    sh = config['server_host']
                    val = u"%s://%s%s" % (sh['scheme'], sh['host'], val)
                    wikified = "http://%s" % wikitext_to_wikklyhtml(
                        baseurl,
                        '',
                        val[7:],
                        self.environ,
                        tiddler=tid,
                        wikiwords=False)
                else:
                    wikified = wikitext_to_wikklyhtml(baseurl,
                                                      '',
                                                      val,
                                                      self.environ,
                                                      tiddler=tid,
                                                      wikiwords=False)
                return cgi.escape(wikified).decode("utf-8")

            else:
                return default
Esempio n. 2
0
def _view_transform(context,value,vtype,named_args={}):
    base = context.var_get_text("$BASE_URL")
    path =""
    environ = context.environ
    try:
        prefix = named_args["prefix"]
        prefix =_do_transclusion(prefix,context.tiddler)
    except KeyError:
        prefix = ""
    try:
        suffix =named_args["suffix"]
        suffix =_do_transclusion(suffix,context.tiddler)
    except KeyError:
        suffix = ""
    try:
        label = named_args["label"]
        label = _do_transclusion(label,context.tiddler)
    except KeyError:
        label = value
    #logging.debug("view_transform %s %s %s"%(value,vtype,params))
    if type(value) != type([]):
        values = [u"%s"%value] 
    else:
        values = []
        for val in value:
            if " " in val:
                values.append("[[%s]]"%val)
            else:
                values.append(val)
    out = ""
    for value in values:
        if not vtype or vtype =='text':
            transformed = value
            out += transformed
        elif vtype == 'wikified':
            out += wikitext_to_wikklyhtml(base,path, value, environ,wikiwords=False,tiddler=context.tiddler)
        elif vtype =='link':
            value = "[[%s]]"%(value)
            out += wikitext_to_wikklyhtml(base,path, value, environ,wikiwords=False,tiddler=context.tiddler)
        elif vtype=='date':
            YYYY = int(value[0:4])
            MM = int(value[4:6])
            DD = int(value[6:8])
            h = value[8:10]
            m = value[10:12]
            s = value[12:14]
            d = date(YYYY,MM,DD)
            out += d.strftime("%d %B %Y")
        elif vtype == 'linkexternal':
            out +=  u'<a href="%s%s%s">%s</a>'%(prefix,urllib.quote(value),suffix,label)
        else:
            logging.debug("unknown view type %s"%vtype)
        out += " "
    out = out[:-1]
    return out
Esempio n. 3
0
def tiddler(context, *args):
    base = context.var_get_text("$BASE_URL")
    path =""
    if not context.environ:
      return ""
    
    store = get_store(config)
    logging.debug("in tiddler macro")
    try:
        environ = context.environ
    except NoAttributeError:
        return _throw_error()
    try:
        tid = context.tiddler
    except NoAttributeError:
        return ""
    if tid.recipe:
        tids = control.get_tiddlers_from_recipe(store.get(Recipe(tid.recipe)))
    elif tid.bag:
        bag = store.get(Bag(tid.bag))
        tids = bag.list_tiddlers()
    else:
        return ""
    try:
        tiddler_requested = args[0].text
        for tiddler in tids:
            if tiddler.title == tiddler_requested:
                tiddler = store.get(tiddler)
    except Exception:
        tiddler = context.tiddler
    if tiddler:
        text = wikitext_to_wikklyhtml(base,path, tiddler.text, environ,tiddler=context.tiddler)
        return "%s"%text
    else:
        return ""#no tiddler with that name
Esempio n. 4
0
    def matcher(g):
        macro = g.group(1)
        wikitext = u"<<%s>>" % macro
        splash = u"%s" % wikitext_to_wikklyhtml(
            base_url, path_url, wikitext, environ, wikiwords=False, tiddler=tiddler
        ).decode("utf-8", "ignore")

        splash = re.sub("\&lt\;", "<", splash)
        splash = re.sub("\&gt\;", ">", splash)
        result = u"%s%s" % (g.group(0), splash)
        return result
Esempio n. 5
0
 def mapper(atom_field_name,tiddler,default):
     logging.debug("atom-custom:: doing a mapping on field %s \n atom-custom::with tiddler %s \n atom-custom::and config %s"%(atom_field_name,tiddler,mappings))
     tid = Tiddler(tiddler['title'],tiddler['bag'])
     tid = serializer.as_tiddler(tid,tiddler)
     try:
         tid.recipe = tiddler['recipe']
     except KeyError:
         pass
     if atom_field_name in mappings:
       val = mappings[atom_field_name]
       if atom_field_name == 'link' or atom_field_name == 'id' and val.startswith("/"):
         sh =config['server_host']
         val = u"%s://%s%s"%(sh['scheme'],sh['host'],val)
         wikified = "http://%s"%wikitext_to_wikklyhtml(baseurl, '', val[7:], self.environ,tiddler=tid,wikiwords=False)
       else:
         wikified = wikitext_to_wikklyhtml(baseurl, '', val, self.environ,tiddler=tid,wikiwords=False)
       return cgi.escape(wikified).decode("utf-8")
       
     else:
       return default
Esempio n. 6
0
 def _plain_textify_string(self, title):
     """
     Take a string that may be HTML and turn it
     into plain text by finding all the included
     text.
     """
     output = wikitext_to_wikklyhtml('', '', unicode(title), self.environ)
     rights = output.split('>')
     lefts = []
     for chunk in rights:
         try:
             lefts.append(chunk[0:chunk.index('<')])
         except ValueError:
             lefts.append(chunk)
     return ''.join(lefts)
Esempio n. 7
0
 def _plain_textify_string(self, title):
     """
     Take a string that may be HTML and turn it
     into plain text by finding all the included
     text.
     """
     output = wikitext_to_wikklyhtml('', '', unicode(title), self.environ)
     rights = output.split('>')
     lefts = []
     for chunk in rights:
         try:
             lefts.append(chunk[0:chunk.index('<')])
         except ValueError:
             lefts.append(chunk)
     return ''.join(lefts)
Esempio n. 8
0
    def matcher(g):
        macro = g.group(1)
        wikitext = u"<<%s>>" % macro
        splash = u"%s" % wikitext_to_wikklyhtml(base_url,
                                                path_url,
                                                wikitext,
                                                environ,
                                                wikiwords=False,
                                                tiddler=tiddler).decode(
                                                    'utf-8', 'ignore')

        splash = re.sub('\&lt\;', '<', splash)
        splash = re.sub('\&gt\;', '>', splash)
        result = u"%s%s" % (g.group(0), splash)
        return result
Esempio n. 9
0
def tags(context,*args):
    base = context.var_get_text("$BASE_URL")
    path =""
    try:
        tiddler = context.tiddler
    except NoAttributeError:
        return _throw_error()
    tagresult = "<ul>"
  
    if len(tiddler.tags) == 0:
        tagresult += "<li>no tags</li>"
    else:
        tagresult +=u"<li class=\"listTitle\">tags: </li>"
        for tag in tiddler.tags:
            taglink = "%s"%wikitext_to_wikklyhtml(base,path, "[[%s]]"%tag, context.environ,wikiwords=False,tiddler=context.tiddler)
            tagresult += "<li>%s</li>"%(taglink)
  
    tagresult += "</ul>"
    return "<html>%s</html>"%tagresult
Esempio n. 10
0
def tiddler(context, *args):
    base = context.var_get_text("$BASE_URL")
    path = ""
    if not context.environ:
        return ""

    store = get_store(config)
    logging.debug("in tiddler macro")
    try:
        environ = context.environ
    except NoAttributeError:
        return _throw_error()
    try:
        tid = context.tiddler
    except NoAttributeError:
        return ""
    if tid.recipe:
        tids = control.get_tiddlers_from_recipe(store.get(Recipe(tid.recipe)))
    elif tid.bag:
        bag = store.get(Bag(tid.bag))
        tids = bag.list_tiddlers()
    else:
        return ""
    try:
        tiddler_requested = args[0].text
        for tiddler in tids:
            if tiddler.title == tiddler_requested:
                tiddler = store.get(tiddler)
    except Exception:
        tiddler = context.tiddler
    if tiddler:
        text = wikitext_to_wikklyhtml(base,
                                      path,
                                      tiddler.text,
                                      environ,
                                      tiddler=context.tiddler)
        return "%s" % text
    else:
        return ""  #no tiddler with that name
Esempio n. 11
0
def tiddlers(context, *args):
    base = context.var_get_text("$BASE_URL")
    path = ""

    if not context.environ:
        return ""
    else:
        environ = context.environ

    store = get_store(config)

    tid = context.tiddler
    if tid.recipe:
        tids = control.get_tiddlers_from_recipe(store.get(Recipe(tid.recipe)))
    elif tid.bag:
        bag = store.get(Bag(tid.bag))
        tids = list(bag.list_tiddlers())
    else:
        return u""

    tiddlerTemplate = args[0].text
    templateText = ""
    for tid in tids:
        tid = store.get(tid)
        if tid.title == tiddlerTemplate:
            templateText = tid.text
    p = parseParams(args)
    if "filter" in p:
        filterBag = Bag("filter", tmpbag=True)
        filterBag.add_tiddlers(tids)
        filtered_tiddlers = filter_tiddlers(filterBag, p["filter"])
        output = u""
        for filtered_tiddler in filtered_tiddlers:
            output += u"%s" % wikitext_to_wikklyhtml(
                base, path, templateText, environ, tiddler=filtered_tiddler)
        return "<html>%s</html>" % output
    else:
        return u""
Esempio n. 12
0
def tiddlers(context, *args):
    base = context.var_get_text("$BASE_URL")
    path = ""
    
    if not context.environ:
        return ""
    else:
      environ = context.environ
    
    store = get_store(config)
    
    tid = context.tiddler
    if tid.recipe:
        tids = control.get_tiddlers_from_recipe(store.get(Recipe(tid.recipe)))
    elif tid.bag:
        bag = store.get(Bag(tid.bag))
        tids = list(bag.list_tiddlers())
    else:
        return u""
    
    tiddlerTemplate = args[0].text
    templateText = ""  
    for tid in tids:
        tid = store.get(tid)
        if tid.title == tiddlerTemplate:
            templateText = tid.text
    p = parseParams(args)
    if "filter" in p:
        filterBag = Bag("filter",tmpbag=True)
        filterBag.add_tiddlers(tids)
        filtered_tiddlers = filter_tiddlers(filterBag,p["filter"])
        output = u""
        for filtered_tiddler in filtered_tiddlers:
            output += u"%s"%wikitext_to_wikklyhtml(base,path, templateText, environ,tiddler=filtered_tiddler)
        return "<html>%s</html>"%output
    else:
        return u""
Esempio n. 13
0
def tags(context, *args):
    base = context.var_get_text("$BASE_URL")
    path = ""
    try:
        tiddler = context.tiddler
    except NoAttributeError:
        return _throw_error()
    tagresult = "<ul>"

    if len(tiddler.tags) == 0:
        tagresult += "<li>no tags</li>"
    else:
        tagresult += u"<li class=\"listTitle\">tags: </li>"
        for tag in tiddler.tags:
            taglink = "%s" % wikitext_to_wikklyhtml(base,
                                                    path,
                                                    "[[%s]]" % tag,
                                                    context.environ,
                                                    wikiwords=False,
                                                    tiddler=context.tiddler)
            tagresult += "<li>%s</li>" % (taglink)

    tagresult += "</ul>"
    return "<html>%s</html>" % tagresult
Esempio n. 14
0
def _view_transform(context, value, vtype, named_args={}):
    base = context.var_get_text("$BASE_URL")
    path = ""
    environ = context.environ
    try:
        prefix = named_args["prefix"]
        prefix = _do_transclusion(prefix, context.tiddler)
    except KeyError:
        prefix = ""
    try:
        suffix = named_args["suffix"]
        suffix = _do_transclusion(suffix, context.tiddler)
    except KeyError:
        suffix = ""
    try:
        label = named_args["label"]
        label = _do_transclusion(label, context.tiddler)
    except KeyError:
        label = value
    #logging.debug("view_transform %s %s %s"%(value,vtype,params))
    if type(value) != type([]):
        values = [u"%s" % value]
    else:
        values = []
        for val in value:
            if " " in val:
                values.append("[[%s]]" % val)
            else:
                values.append(val)
    out = ""
    for value in values:
        if not vtype or vtype == 'text':
            transformed = value
            out += transformed
        elif vtype == 'wikified':
            out += wikitext_to_wikklyhtml(base,
                                          path,
                                          value,
                                          environ,
                                          wikiwords=False,
                                          tiddler=context.tiddler)
        elif vtype == 'link':
            value = "[[%s]]" % (value)
            out += wikitext_to_wikklyhtml(base,
                                          path,
                                          value,
                                          environ,
                                          wikiwords=False,
                                          tiddler=context.tiddler)
        elif vtype == 'date':
            YYYY = int(value[0:4])
            MM = int(value[4:6])
            DD = int(value[6:8])
            h = value[8:10]
            m = value[10:12]
            s = value[12:14]
            d = date(YYYY, MM, DD)
            out += d.strftime("%d %B %Y")
        elif vtype == 'linkexternal':
            out += u'<a href="%s%s%s">%s</a>' % (prefix, urllib.quote(value),
                                                 suffix, label)
        else:
            logging.debug("unknown view type %s" % vtype)
        out += " "
    out = out[:-1]
    return out