Coder Social home page Coder Social logo

fiole's People

Contributors

florentx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fiole's Issues

Quick access to the absolute URL of a request

When building an API I often need to construct the absolute URL of a resource and then construct new ones using urlparse.urljoin(). Because of urljoin I need to be sure the URL ends in a trailing / as otherwise the results are very different. Currently I do this as such:

url = wsgiref.utils.request_uri(request.environ, include_query=False)
if url[-1:] != b'/':
    url += b'/'

However I'm rather jealous of the request.path variable and was wondering if it was possible to add maybe request.url or request.base_url or something which is the correct absolute URL with a guaranteed trailing /?

Provide the app to requests

It is useful to have access to the application object in a view. This can be done in two ways:

  1. Putting the app in environ: fiole.app. This is easily done in the .handle_request() method of Fiole.
  2. Passing in the app when creating the Request instance. This can again be easily done in the same place.

escape should be by default

If I read correctly the examples, the escape is not by default. I think it's too easy to forget to add |e once. better way would be to add |safe when needed.

Provide Accept-style header parsing

It would be nice if parsing of Accept HTTP headers is supported natively. IMHO this is a pretty important function to have when building a REST-like API. The best code I have found for this is from WebOb, and the class is very stand-alone (MIT licensed) so can be easily adopted.

Improve template location configuration

Hi,

Currently you can customise fiole.engine.loader.template_folder but it is only ever valid as a relative directory to fiole._get_root_folder(). Instead it would be nice if you could set it to any directory you like similar to how fiole.static_folder works.

To achieve this I created a subclass of Loader, which does way to much copy-pasting, but shows how I think this should be solved:

class Loader(fiole.Loader):
    """Subclass to control where templates are stored"""
    template_folder = os.path.join(fiole._get_root_folder(), 'templates')

    def load(self, name, source=None):
        """Return template by name."""
        if source is not None:
            return (name, unicode(source))
        if name in self.templates:
            return (name, self.templates[name])
        path = os.path.join(self.template_folder, name)
        with open(path, 'rb') as f:
            return (path, f.read().decode('utf-8'))

This allows you to re-assign Loader.template_folder to e.g. any absolute directory you like.

def and compound code

Bug is explained in below python code:

import fiole

parent_source = u"""
%def content():
    [parent content]
%enddef
{{content()}}
"""

child1_source = u"""
%extends("parent")
%def content():
    %if True:
        [child 1 content]
    %endif
%enddef
"""

child2_source = u"""
%extends("parent")
%def content():

    %if True:
        [child 2 content]
    %endif
%enddef
"""

fiole.get_template("parent", source=parent_source)

# BUG: this prints [parent content] instead [child 1 content]
print fiole.render_template(source=child1_source)

# This prints [child 2 content] as expected
print fiole.render_template(source=child2_source)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.