Loading ...
Sorry, an error occurred while loading the content.
 

Re: [Cheetahtemplate-discuss] Cheetah's #include base directory

Expand Messages
  • R. Tyler Ballance
    ... Howdy! Sorry I missed you on IRC, we re quite a ways apart as far as time zones are concerned ;) ... Personally I don t use the #include directive ever (I
    Message 1 of 11 , Dec 29, 2009
      On Tue, 29 Dec 2009, Pablo Antonio wrote:

      > Hello,
      > this is my first day with Cheetah. I have an old app which uses
      > the web.py framework and Cheetah for templating.

      Howdy! Sorry I missed you on IRC, we're quite a ways apart as far as time zones
      are concerned ;)

      > Thing is some files have an '#include "<file>"' at the top. They usually
      > include some header with the DOCTYPE and a title and that's pretty much
      > it. Well, the problem is this <file> is being searched in the current
      > directory the app is located, and not in the ./templates/ dir which is
      > where the templates are.

      Personally I don't use the #include directive ever (I find it too much like
      Smarty (read: hacky)). That said, you *might* be able to override the method on
      your base template class `serverSidePath` which is what the #include directive
      handler uses to locate the included template. In effect:

      #import os.path
      #def serverSidePath(**kwargs)
      ## serverSidePath takes a `path` keyword arg

      ## Assuming your templates directory is called `templates`
      #return os.path.join(os.getcwd(), 'templates', kwargs['path'))
      #end def

      I'm making a couple of assumptions in the code above, namely that `os.getcwd()`
      will return the application's base directory. That said, let me know if you
      can't get serverSidePath to work for you, I'll be on IRC for the next 8-12
      hours while I work so feel free to ping me there :)

      > How can I fix this? Is this different in newer versions? I'm using 2.0.1
      > (the newest in Ubuntu's repositories).

      It's worth noting that v2.4.1 is the latest release
      (http://pypi.python.org/pypi/Cheetah/2.4.1)

      Cheers,
      -R. Tyler Ballance
      --------------------------------------
      Jabber: rtyler@...
      GitHub: http://github.com/rtyler
      Twitter: http://twitter.com/agentdero
      Blog: http://unethicalblogger.com
    • Aahz
      ... All right, how do you do create global template elements such as page footers? I want to write them in Cheetah rather than Python because they re
      Message 2 of 11 , Jan 26, 2010
        On Tue, Dec 29, 2009, R. Tyler Ballance wrote:
        > On Tue, 29 Dec 2009, Pablo Antonio wrote:
        >>
        >> Thing is some files have an '#include "<file>"' at the top. They usually
        >> include some header with the DOCTYPE and a title and that's pretty much
        >> it. Well, the problem is this <file> is being searched in the current
        >> directory the app is located, and not in the ./templates/ dir which is
        >> where the templates are.
        >
        > Personally I don't use the #include directive ever (I find it too much
        > like Smarty (read: hacky)).

        All right, how do you do create global template elements such as page
        footers? I want to write them in Cheetah rather than Python because
        they're primarily HTML.
        --
        Aahz (aahz@...) <*> http://www.pythoncraft.com/

        import antigravity

        ------------------------------------------------------------------------------
        The Planet: dedicated and managed hosting, cloud storage, colocation
        Stay online with enterprise data centers and the best network in the business
        Choose flexible plans and management services without long-term contracts
        Personal 24x7 support from experience hosting pros just a phone call away.
        http://p.sf.net/sfu/theplanet-com
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • R. Tyler Ballance
        ... I use inheritance between pre-compiled templates (since it s tricky to do with dynamic compilation), here s an example: base.tmpl:
        Message 3 of 11 , Jan 26, 2010
          On Tue, 26 Jan 2010, Aahz wrote:

          > On Tue, Dec 29, 2009, R. Tyler Ballance wrote:
          > > On Tue, 29 Dec 2009, Pablo Antonio wrote:
          > >>
          > >> Thing is some files have an '#include "<file>"' at the top. They usually
          > >> include some header with the DOCTYPE and a title and that's pretty much
          > >> it. Well, the problem is this <file> is being searched in the current
          > >> directory the app is located, and not in the ./templates/ dir which is
          > >> where the templates are.
          > >
          > > Personally I don't use the #include directive ever (I find it too much
          > > like Smarty (read: hacky)).
          >
          > All right, how do you do create global template elements such as page
          > footers? I want to write them in Cheetah rather than Python because
          > they're primarily HTML.

          I use inheritance between pre-compiled templates (since it's tricky to do with
          dynamic compilation), here's an example:

          base.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/base.tmpl
          index.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/index.tmpl

          Cheers,
          -R. Tyler Ballance
          --------------------------------------
          Jabber: rtyler@...
          GitHub: http://github.com/rtyler
          Twitter: http://twitter.com/agentdero
          Blog: http://unethicalblogger.com
        • Aahz
          ... Ah-ha. Well, since I *do* want dynamic compilation for development, I guess I m going to need to put in some skill sweat to figure out how to make that
          Message 4 of 11 , Jan 28, 2010
            On Tue, Jan 26, 2010, R. Tyler Ballance wrote:
            > On Tue, 26 Jan 2010, Aahz wrote:
            >>
            >> All right, how do you do create global template elements such as page
            >> footers? I want to write them in Cheetah rather than Python because
            >> they're primarily HTML.
            >
            > I use inheritance between pre-compiled templates (since it's tricky to do with
            > dynamic compilation), here's an example:
            >
            > base.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/base.tmpl
            > index.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/index.tmpl

            Ah-ha. Well, since I *do* want dynamic compilation for development, I
            guess I'm going to need to put in some skill sweat to figure out how to
            make that work.
            --
            Aahz (aahz@...) <*> http://www.pythoncraft.com/

            import antigravity

            ------------------------------------------------------------------------------
            The Planet: dedicated and managed hosting, cloud storage, colocation
            Stay online with enterprise data centers and the best network in the business
            Choose flexible plans and management services without long-term contracts
            Personal 24x7 support from experience hosting pros just a phone call away.
            http://p.sf.net/sfu/theplanet-com
            _______________________________________________
            Cheetahtemplate-discuss mailing list
            Cheetahtemplate-discuss@...
            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          • R. Tyler Ballance
            ... Indeed; I think adding the ability to use inheritance with dynamic compilation would be a good feature to add to Cheetah but I m uncertain on what the API
            Message 5 of 11 , Jan 28, 2010
              On Thu, 28 Jan 2010, Aahz wrote:

              > On Tue, Jan 26, 2010, R. Tyler Ballance wrote:
              > > On Tue, 26 Jan 2010, Aahz wrote:
              > >>
              > >> All right, how do you do create global template elements such as page
              > >> footers? I want to write them in Cheetah rather than Python because
              > >> they're primarily HTML.
              > >
              > > I use inheritance between pre-compiled templates (since it's tricky to do with
              > > dynamic compilation), here's an example:
              > >
              > > base.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/base.tmpl
              > > index.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/index.tmpl
              >
              > Ah-ha. Well, since I *do* want dynamic compilation for development, I
              > guess I'm going to need to put in some skill sweat to figure out how to
              > make that work.

              Indeed; I think adding the ability to use inheritance with dynamic compilation
              would be a good feature to add to Cheetah but I'm uncertain on what the API
              would look like?

              Should I create fake modules for templates based on their paths? I.e. if your
              base.tmpl was located in proj/views does it make sense that inheritors of that
              base.tmpl would do:

              #from proj.views import base
              #extends base.base

              For the dynamic compilation I think I'm going to have to fudge the modules to
              make it work, i'm just worried about it being non-obvious to developers :/

              Cheers,
              -R. Tyler Ballance
              --------------------------------------
              Jabber: rtyler@...
              GitHub: http://github.com/rtyler
              Twitter: http://twitter.com/agentdero
              Blog: http://unethicalblogger.com
            • Aahz
              ... We already have code we use to deal with dynamic vs pre-compiled, which I guess I ll just extend a bit to deal with including templates: def
              Message 6 of 11 , Mar 16, 2010
                On Thu, Jan 28, 2010, R. Tyler Ballance wrote:
                > On Thu, 28 Jan 2010, Aahz wrote:
                >> On Tue, Jan 26, 2010, R. Tyler Ballance wrote:
                >>> On Tue, 26 Jan 2010, Aahz wrote:
                >>>>
                >>>> All right, how do you do create global template elements such as page
                >>>> footers? I want to write them in Cheetah rather than Python because
                >>>> they're primarily HTML.
                >>>
                >>> I use inheritance between pre-compiled templates (since it's tricky
                >>> to do with dynamic compilation), here's an example:
                >>>
                >>> base.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/base.tmpl
                >>> index.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/index.tmpl
                >>
                >> Ah-ha. Well, since I *do* want dynamic compilation for development, I
                >> guess I'm going to need to put in some skill sweat to figure out how to
                >> make that work.
                >
                > Indeed; I think adding the ability to use inheritance with dynamic
                > compilation would be a good feature to add to Cheetah but I'm
                > uncertain on what the API would look like?

                We already have code we use to deal with dynamic vs pre-compiled, which
                I guess I'll just extend a bit to deal with "including" templates:

                def getTemplate(name):
                return os.path.join(os.path.realpath(os.path.join("..","..", "resource","html","templates")), name) + ".tmpl"

                def run_template(tmpl_name, searchList, development=None):
                if development is None:
                development = "-d" in sys.argv or "--DEVELOPMENT" in sys.argv
                if development:
                logging.debug("Getting dev template: %s", tmpl_name)
                t = Template(file=getTemplate(tmpl_name), searchList=searchList)
                else:
                logging.debug("Getting compiled template: %s", tmpl_name)
                t = getattr(templates, tmpl_name)(searchList=searchList)
                return t.respond()

                Obviously, getTemplate() relies on knowledge of our environment and would
                need updating to work in the general case. Similarly, the "templates"
                package is also an artifact of our environment, and our build system
                auto-generates the __init__.py of the package to hoist the template
                classes into the root package namespace.

                Hopefully this gives you ideas for something that can work in Cheetah.

                But at least soon I will tell our developers to just use e.g.
                $run_template('footer')
                which isn't quite as nice as template inheritance but is straightforward
                and will still be considerably better than what we currently have.
                --
                Aahz (aahz@...) <*> http://www.pythoncraft.com/

                "Many customs in this life persist because they ease friction and promote
                productivity as a result of universal agreement, and whether they are
                precisely the optimal choices is much less important." --Henry Spencer

                ------------------------------------------------------------------------------
                Download Intel® Parallel Studio Eval
                Try the new software tools for yourself. Speed compiling, find bugs
                proactively, and fine-tune applications for parallel performance.
                See why Intel Parallel Studio got high marks during beta.
                http://p.sf.net/sfu/intel-sw-dev
                _______________________________________________
                Cheetahtemplate-discuss mailing list
                Cheetahtemplate-discuss@...
                https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
              • Tavis Rudd
                Wouldn t template inheritance with dynamic compilation just require installing the Cheetah import hook? ... Download Intel® Parallel Studio Eval Try the
                Message 7 of 11 , Mar 16, 2010
                  Wouldn't template inheritance with dynamic compilation just require
                  installing the Cheetah import hook?

                  On Tue, 16 Mar 2010, Aahz wrote:

                  > On Thu, Jan 28, 2010, R. Tyler Ballance wrote:
                  >> On Thu, 28 Jan 2010, Aahz wrote:
                  >>> On Tue, Jan 26, 2010, R. Tyler Ballance wrote:
                  >>>> On Tue, 26 Jan 2010, Aahz wrote:
                  >>>>>
                  >>>>> All right, how do you do create global template elements such as page
                  >>>>> footers? I want to write them in Cheetah rather than Python because
                  >>>>> they're primarily HTML.
                  >>>>
                  >>>> I use inheritance between pre-compiled templates (since it's tricky
                  >>>> to do with dynamic compilation), here's an example:
                  >>>>
                  >>>> base.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/base.tmpl
                  >>>> index.tmpl: http://github.com/rtyler/urlenco.de/blob/master/Urlencode/views/index.tmpl
                  >>>
                  >>> Ah-ha. Well, since I *do* want dynamic compilation for development, I
                  >>> guess I'm going to need to put in some skill sweat to figure out how to
                  >>> make that work.
                  >>
                  >> Indeed; I think adding the ability to use inheritance with dynamic
                  >> compilation would be a good feature to add to Cheetah but I'm
                  >> uncertain on what the API would look like?
                  >
                  > We already have code we use to deal with dynamic vs pre-compiled, which
                  > I guess I'll just extend a bit to deal with "including" templates:
                  >
                  > def getTemplate(name):
                  > return os.path.join(os.path.realpath(os.path.join("..","..", "resource","html","templates")), name) + ".tmpl"
                  >
                  > def run_template(tmpl_name, searchList, development=None):
                  > if development is None:
                  > development = "-d" in sys.argv or "--DEVELOPMENT" in sys.argv
                  > if development:
                  > logging.debug("Getting dev template: %s", tmpl_name)
                  > t = Template(file=getTemplate(tmpl_name), searchList=searchList)
                  > else:
                  > logging.debug("Getting compiled template: %s", tmpl_name)
                  > t = getattr(templates, tmpl_name)(searchList=searchList)
                  > return t.respond()
                  >
                  > Obviously, getTemplate() relies on knowledge of our environment and would
                  > need updating to work in the general case. Similarly, the "templates"
                  > package is also an artifact of our environment, and our build system
                  > auto-generates the __init__.py of the package to hoist the template
                  > classes into the root package namespace.
                  >
                  > Hopefully this gives you ideas for something that can work in Cheetah.
                  >
                  > But at least soon I will tell our developers to just use e.g.
                  > $run_template('footer')
                  > which isn't quite as nice as template inheritance but is straightforward
                  > and will still be considerably better than what we currently have.
                  > --
                  > Aahz (aahz@...) <*> http://www.pythoncraft.com/
                  >
                  > "Many customs in this life persist because they ease friction and promote
                  > productivity as a result of universal agreement, and whether they are
                  > precisely the optimal choices is much less important." --Henry Spencer
                  >
                  > ------------------------------------------------------------------------------
                  > Download Intel® Parallel Studio Eval
                  > Try the new software tools for yourself. Speed compiling, find bugs
                  > proactively, and fine-tune applications for parallel performance.
                  > See why Intel Parallel Studio got high marks during beta.
                  > http://p.sf.net/sfu/intel-sw-dev
                  > _______________________________________________
                  > Cheetahtemplate-discuss mailing list
                  > Cheetahtemplate-discuss@...
                  > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                  >

                  ------------------------------------------------------------------------------
                  Download Intel® Parallel Studio Eval
                  Try the new software tools for yourself. Speed compiling, find bugs
                  proactively, and fine-tune applications for parallel performance.
                  See why Intel Parallel Studio got high marks during beta.
                  http://p.sf.net/sfu/intel-sw-dev
                  _______________________________________________
                  Cheetahtemplate-discuss mailing list
                  Cheetahtemplate-discuss@...
                  https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                • Aahz
                  ... Where is that documented? This is the first I ve heard of it, and I don t see it anywhere at http://www.cheetahtemplate.org/docs/users_guide_html/ -- Aahz
                  Message 8 of 11 , Mar 16, 2010
                    On Tue, Mar 16, 2010, Tavis Rudd wrote:
                    >
                    > Wouldn't template inheritance with dynamic compilation just require
                    > installing the Cheetah import hook?

                    Where is that documented? This is the first I've heard of it, and I
                    don't see it anywhere at
                    http://www.cheetahtemplate.org/docs/users_guide_html/
                    --
                    Aahz (aahz@...) <*> http://www.pythoncraft.com/

                    "Many customs in this life persist because they ease friction and promote
                    productivity as a result of universal agreement, and whether they are
                    precisely the optimal choices is much less important." --Henry Spencer

                    ------------------------------------------------------------------------------
                    Download Intel® Parallel Studio Eval
                    Try the new software tools for yourself. Speed compiling, find bugs
                    proactively, and fine-tune applications for parallel performance.
                    See why Intel Parallel Studio got high marks during beta.
                    http://p.sf.net/sfu/intel-sw-dev
                    _______________________________________________
                    Cheetahtemplate-discuss mailing list
                    Cheetahtemplate-discuss@...
                    https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                  • Tavis Rudd
                    I don t think it s documented in the main docs. Add: import Cheetah.ImportHooks Cheetah.ImportHooks.install() somewhere early in your python process startup.
                    Message 9 of 11 , Mar 16, 2010
                      I don't think it's documented in the main docs.
                      Add:
                      import Cheetah.ImportHooks
                      Cheetah.ImportHooks.install()

                      somewhere early in your python process' startup. The code is really old,
                      pre pep-302, but I think it should still work. If not, it should be easy
                      enough to use http://pypi.python.org/pypi/importlib/1.0.1 to update it.

                      Tavis

                      On Tue, 16 Mar 2010, Aahz wrote:

                      > On Tue, Mar 16, 2010, Tavis Rudd wrote:
                      >>
                      >> Wouldn't template inheritance with dynamic compilation just require
                      >> installing the Cheetah import hook?
                      >
                      > Where is that documented? This is the first I've heard of it, and I
                      > don't see it anywhere at
                      > http://www.cheetahtemplate.org/docs/users_guide_html/
                      > --
                      > Aahz (aahz@...) <*> http://www.pythoncraft.com/
                      >
                      > "Many customs in this life persist because they ease friction and promote
                      > productivity as a result of universal agreement, and whether they are
                      > precisely the optimal choices is much less important." --Henry Spencer
                      >
                      > ------------------------------------------------------------------------------
                      > Download Intel® Parallel Studio Eval
                      > Try the new software tools for yourself. Speed compiling, find bugs
                      > proactively, and fine-tune applications for parallel performance.
                      > See why Intel Parallel Studio got high marks during beta.
                      > http://p.sf.net/sfu/intel-sw-dev
                      > _______________________________________________
                      > Cheetahtemplate-discuss mailing list
                      > Cheetahtemplate-discuss@...
                      > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                      >

                      ------------------------------------------------------------------------------
                      Download Intel® Parallel Studio Eval
                      Try the new software tools for yourself. Speed compiling, find bugs
                      proactively, and fine-tune applications for parallel performance.
                      See why Intel Parallel Studio got high marks during beta.
                      http://p.sf.net/sfu/intel-sw-dev
                      _______________________________________________
                      Cheetahtemplate-discuss mailing list
                      Cheetahtemplate-discuss@...
                      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                    • Tavis Rudd
                      ... If the existing hook doesn t work as is, also see this http://code.google.com/p/importers/source/browse/docs/index.rst ... Download Intel® Parallel
                      Message 10 of 11 , Mar 16, 2010
                        On Tue, 16 Mar 2010, Tavis Rudd wrote:

                        > I don't think it's documented in the main docs.
                        > Add:
                        > import Cheetah.ImportHooks
                        > Cheetah.ImportHooks.install()
                        >
                        > somewhere early in your python process' startup. The code is really old,
                        > pre pep-302, but I think it should still work. If not, it should be easy
                        > enough to use http://pypi.python.org/pypi/importlib/1.0.1 to update it.
                        If the existing hook doesn't work as is, also see this
                        http://code.google.com/p/importers/source/browse/docs/index.rst



                        > Tavis
                        >
                        > On Tue, 16 Mar 2010, Aahz wrote:
                        >
                        >> On Tue, Mar 16, 2010, Tavis Rudd wrote:
                        >>>
                        >>> Wouldn't template inheritance with dynamic compilation just require
                        >>> installing the Cheetah import hook?
                        >>
                        >> Where is that documented? This is the first I've heard of it, and I
                        >> don't see it anywhere at
                        >> http://www.cheetahtemplate.org/docs/users_guide_html/
                        >> --
                        >> Aahz (aahz@...) <*> http://www.pythoncraft.com/
                        >>
                        >> "Many customs in this life persist because they ease friction and promote
                        >> productivity as a result of universal agreement, and whether they are
                        >> precisely the optimal choices is much less important." --Henry Spencer
                        >>
                        >> ------------------------------------------------------------------------------
                        >> Download Intel® Parallel Studio Eval
                        >> Try the new software tools for yourself. Speed compiling, find bugs
                        >> proactively, and fine-tune applications for parallel performance.
                        >> See why Intel Parallel Studio got high marks during beta.
                        >> http://p.sf.net/sfu/intel-sw-dev
                        >> _______________________________________________
                        >> Cheetahtemplate-discuss mailing list
                        >> Cheetahtemplate-discuss@...
                        >> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                        >>
                        >
                        > ------------------------------------------------------------------------------
                        > Download Intel® Parallel Studio Eval
                        > Try the new software tools for yourself. Speed compiling, find bugs
                        > proactively, and fine-tune applications for parallel performance.
                        > See why Intel Parallel Studio got high marks during beta.
                        > http://p.sf.net/sfu/intel-sw-dev
                        > _______________________________________________
                        > Cheetahtemplate-discuss mailing list
                        > Cheetahtemplate-discuss@...
                        > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                        >

                        ------------------------------------------------------------------------------
                        Download Intel® Parallel Studio Eval
                        Try the new software tools for yourself. Speed compiling, find bugs
                        proactively, and fine-tune applications for parallel performance.
                        See why Intel Parallel Studio got high marks during beta.
                        http://p.sf.net/sfu/intel-sw-dev
                        _______________________________________________
                        Cheetahtemplate-discuss mailing list
                        Cheetahtemplate-discuss@...
                        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                      Your message has been successfully submitted and would be delivered to recipients shortly.