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

Support for pyxl #49

Open
notpushkin opened this issue May 27, 2019 · 2 comments
Open

Support for pyxl #49

notpushkin opened this issue May 27, 2019 · 2 comments

Comments

@notpushkin
Copy link

Pyxl is a JSX-like syntax for Python:

image_name = "bolton.png"
image = <img src="/static/images/{image_name}" />

text = "Michael Bolton"
block = <div>{image}{text}</div>

element_list = [image, text]
block2 = <div>{element_list}</div>

It is not official, but was kinda endorsed by GvR who ported it to Python 3 at some point (gvanrossum/pyxl3). It would be much more useful with React though, as a replacement for JSX:

from react import React
...

__default__ = "App"

class App(React.Component):
    state = {"isLoadingComplete": False}

    def render(self):
        if not self.state["isLoadingComplete"] and not self.props["skipLoadingScreen"]:
            return <AppLoading
                startAsync={self.load_resources_async}
                onError={self.handle_loading_error}
                onFinish={self.handle_finish_loading}
            />
        else:
            return <View style={styles.container}>
                {<StatusBar barStyle="default" /> if Platform.OS == "ios" else None}
                <AppNavigator />
            </View>

    ...

What do you think?

@azazel75
Copy link
Collaborator

I must say that I don't like so much putting HTML into python code because of the mix of the two "major modes" and the fact that really that HTML is a lie. That said, I'm not using JavaScripthon at the moment (I haven't had the time to complete the work on the "MacroPy" branchso I may consider semething that will broad (maybe) its usage. Are you using It? BTW, speaking of MacroPy, It has included pyxl some time ago, maybe this notation is sufficient? It will offer major flexibility without the need to change pj an MacroPy it's already a dependency.

@azazel75
Copy link
Collaborator

Sorry, some kind of adaptation of pj would be required anyway, but it's unclear what would be the best path to follow: the first would be to translate the Python code but not the HTML, leaving further translation to the JS transpiler, the other would be to convert HTML to Python using MacroPy3 (or pyxl). I would prefer this latter one, but we need to find a generic way to tell pj to omit the conversion of the macropy imports or to import and apply the macropy pre processing by using maybe a comment or some other kind of notation

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

No branches or pull requests

2 participants