コード例 #1
0
    def templater(self, req):
        def header(**map):
            yield tmpl('header', encoding=encoding.encoding, **map)

        def footer(**map):
            yield tmpl("footer", **map)

        def motd(**map):
            if self.motd is not None:
                yield self.motd
            else:
                yield config('web', 'motd', '')

        def config(section, name, default=None, untrusted=True):
            return self.ui.config(section, name, default, untrusted)

        if self._baseurl is not None:
            req.env['SCRIPT_NAME'] = self._baseurl

        url = req.env.get('SCRIPT_NAME', '')
        if not url.endswith('/'):
            url += '/'

        vars = {}
        style = self.style
        if 'style' in req.form:
            vars['style'] = style = req.form['style'][0]
        start = url[-1] == '?' and '&' or '?'
        sessionvars = webutil.sessionvars(vars, start)

        staticurl = config('web', 'staticurl') or url + 'static/'
        if not staticurl.endswith('/'):
            staticurl += '/'

        style = 'style' in req.form and req.form['style'][0] or self.style
        mapfile = templater.stylemap(style)
        tmpl = templater.templater(mapfile,
                                   defaults={
                                       "header": header,
                                       "footer": footer,
                                       "motd": motd,
                                       "url": url,
                                       "staticurl": staticurl,
                                       "sessionvars": sessionvars
                                   })
        return tmpl
コード例 #2
0
ファイル: hgwebdir_mod.py プロジェクト: dkrisman/Traipse
    def templater(self, req):

        def header(**map):
            yield tmpl('header', encoding=encoding.encoding, **map)

        def footer(**map):
            yield tmpl("footer", **map)

        def motd(**map):
            if self.motd is not None:
                yield self.motd
            else:
                yield config('web', 'motd', '')

        def config(section, name, default=None, untrusted=True):
            return self.ui.config(section, name, default, untrusted)

        if self._baseurl is not None:
            req.env['SCRIPT_NAME'] = self._baseurl

        url = req.env.get('SCRIPT_NAME', '')
        if not url.endswith('/'):
            url += '/'

        vars = {}
        style = self.style
        if 'style' in req.form:
            vars['style'] = style = req.form['style'][0]
        start = url[-1] == '?' and '&' or '?'
        sessionvars = webutil.sessionvars(vars, start)

        staticurl = config('web', 'staticurl') or url + 'static/'
        if not staticurl.endswith('/'):
            staticurl += '/'

        style = 'style' in req.form and req.form['style'][0] or self.style
        mapfile = templater.stylemap(style)
        tmpl = templater.templater(mapfile,
                                   defaults={"header": header,
                                             "footer": footer,
                                             "motd": motd,
                                             "url": url,
                                             "staticurl": staticurl,
                                             "sessionvars": sessionvars})
        return tmpl
コード例 #3
0
ファイル: hgweb_mod.py プロジェクト: dkrisman/Traipse
    def templater(self, req):

        # determine scheme, port and server name
        # this is needed to create absolute urls

        proto = req.env.get('wsgi.url_scheme')
        if proto == 'https':
            proto = 'https'
            default_port = "443"
        else:
            proto = 'http'
            default_port = "80"

        port = req.env["SERVER_PORT"]
        port = port != default_port and (":" + port) or ""
        urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
        staticurl = self.config("web", "staticurl") or req.url + 'static/'
        if not staticurl.endswith('/'):
            staticurl += '/'

        # some functions for the templater

        def header(**map):
            yield tmpl('header', encoding=encoding.encoding, **map)

        def footer(**map):
            yield tmpl("footer", **map)

        def motd(**map):
            yield self.config("web", "motd", "")

        # figure out which style to use

        vars = {}
        style = self.config("web", "style", "paper")
        if 'style' in req.form:
            style = req.form['style'][0]
            vars['style'] = style

        start = req.url[-1] == '?' and '&' or '?'
        sessionvars = webutil.sessionvars(vars, start)
        mapfile = templater.stylemap(style, self.templatepath)

        if not self.reponame:
            self.reponame = (self.config("web", "name")
                             or req.env.get('REPO_NAME')
                             or req.url.strip('/') or self.repo.root)

        # create the templater

        tmpl = templater.templater(mapfile,
                                   defaults={"url": req.url,
                                             "staticurl": staticurl,
                                             "urlbase": urlbase,
                                             "repo": self.reponame,
                                             "header": header,
                                             "footer": footer,
                                             "motd": motd,
                                             "sessionvars": sessionvars
                                            })
        return tmpl
コード例 #4
0
    def templater(self, req):

        # determine scheme, port and server name
        # this is needed to create absolute urls

        proto = req.env.get('wsgi.url_scheme')
        if proto == 'https':
            proto = 'https'
            default_port = "443"
        else:
            proto = 'http'
            default_port = "80"

        port = req.env["SERVER_PORT"]
        port = port != default_port and (":" + port) or ""
        urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
        staticurl = self.config("web", "staticurl") or req.url + 'static/'
        if not staticurl.endswith('/'):
            staticurl += '/'

        # some functions for the templater

        def header(**map):
            yield tmpl('header', encoding=encoding.encoding, **map)

        def footer(**map):
            yield tmpl("footer", **map)

        def motd(**map):
            yield self.config("web", "motd", "")

        # figure out which style to use

        vars = {}
        style = self.config("web", "style", "paper")
        if 'style' in req.form:
            style = req.form['style'][0]
            vars['style'] = style

        start = req.url[-1] == '?' and '&' or '?'
        sessionvars = webutil.sessionvars(vars, start)
        mapfile = templater.stylemap(style, self.templatepath)

        if not self.reponame:
            self.reponame = (self.config("web", "name")
                             or req.env.get('REPO_NAME') or req.url.strip('/')
                             or self.repo.root)

        # create the templater

        tmpl = templater.templater(mapfile,
                                   defaults={
                                       "url": req.url,
                                       "staticurl": staticurl,
                                       "urlbase": urlbase,
                                       "repo": self.reponame,
                                       "header": header,
                                       "footer": footer,
                                       "motd": motd,
                                       "sessionvars": sessionvars
                                   })
        return tmpl