Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pluggable Views #1

Open
Deepwalker opened this issue Jul 31, 2015 · 6 comments
Open

Add pluggable Views #1

Deepwalker opened this issue Jul 31, 2015 · 6 comments

Comments

@Deepwalker
Copy link

Hi, I have something for you – https://github.com/Deepwalker/backslant

Actually, if you plan to implement Rails somehow, you need to provide something like ActiveView – one rails project can use wast amount of different view builders and all of them are interchangeable and play nice together.

And in backslant I really did play well with jinja2 – both using iterators inside (generators actually), and its damn simple to make them play well together.

Today I wrote simple thing to support include backslant templates into the jinja templates:

from jinja2.environment import Template
class BSTemplate(Template):
    def __new__(cls, *a, **kw):
        return object.__new__(cls)

    def __init__(self, bs_renderer):
        self.renderer = bs_renderer
        self.name = repr(bs_renderer)

    def root_render_func(self, context):
        return cohorts.render(context=context)

    def new_context(self, vars, shared=False, locals=None):
        return dict(vars=vars, locals=locals)

Its simple to add special case to jinja2, that will eliminate this staff, and will support just generators.

And this is damn simple proto – any view lib must support simple protocol – it return view instance that supports generator protocol.

And we have two libs that almost support it. Backslant actually did, and did it way simpler then jinja2.

@1st
Copy link
Contributor

1st commented Aug 17, 2015

Can you propose something in Pull Request that can be used to achieve this goal? For example, we can use Jinja2 and other template engines in he same way. It will be a decoration over the template engines with the same external interface.

@1st
Copy link
Contributor

1st commented Aug 17, 2015

By the way, we can do the same for Model layer by adding multiple ORM implementations and use the same interface to interact with them. For example, two developers can use different ORM depends on their needs or qualification. Don't sure that mess of different libs inside one project is a good idea - but it will open the doors to flexibility and allow to integrate other projects with different libs (ORM, template engines) to our existing project and use it without code changes.

@1st
Copy link
Contributor

1st commented Nov 19, 2015

@Deepwalker do you have any updates for this issue? I wish to release full-featured version of Python on Rails in coming weeks. You can help me to speed-up this process.

@1st 1st added this to the 1.0 milestone Nov 19, 2015
@Deepwalker
Copy link
Author

I can write separate ActiveView, that you can include to project as view layer. With support for jinja2, mako etc. Not sure if will be able to make all them interchangable, like in rails, but will try.

@1st
Copy link
Contributor

1st commented Nov 19, 2015

@Deepwalker thanks. I will push my changes to a View in coming days. Please check updates before you will push your changes and create Pull Request.

Our main goals now - create interface to use Model (#5) and View layers. It means that customer can select any ORM (SQL Alchemy, SQLObject, etc) and any Template Engine (Jinja2, Mako, etc). When we will do this - we can release a first stable version of the Python on Rails.

@1st 1st changed the title Create view libs protocol. Add pluggable View Nov 19, 2015
@1st 1st changed the title Add pluggable View Add pluggable Views Nov 19, 2015
@1st
Copy link
Contributor

1st commented Nov 20, 2015

Added support for Jinja2 templates. Updated example blog app to use these templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants