TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.86k stars 214 forks source link

Plugin system for transcrypt #82

Closed sideffect0 closed 8 years ago

JdeH commented 8 years ago

Hi,

You mean something like 'require' for node.js? This already works (see demo):

# Compile with p. command line switch (see docs).
# The example will be served at URL: http://localhost:8080 in your browser

http = require ('http')

class Demo:
    texts = (
        'Welcome to the world of node.js',
        'You can have your cake and eat it',
        'Use node\'s ecosystem while programming in Python',
        'Using node.js from Transcrypt is easy',
        'Take a Python ride into the node.js world'
    )

    def __init__ (self, port):
        print ('Demo server started on port', port)
        self.server = http.createServer (self.serve)
        self.server.listen (port)
        self.oldIndex = 0
        self.newIndex = 0
        self.count = 0

    def serve (self, request, response):
        response.writeHead (200)

        print ('Serving page', self.count)
        self.count += 1

        while self.newIndex == self.oldIndex:
            self.newIndex = int (Math.random () * len (self.texts))
        self.oldIndex = self.newIndex

        response.end ('<h1>{}</h1>'.format (
            self.texts [self.newIndex]
        ))

demo = Demo (8080)

Or do you mean something specifically Pythonic, e.g. automatically downloading modules from PyPi if they aren't yet installed? Problem is by far not all modules are suitable for Transcrypt.

Or am I completely missing your point? Please elaborate.

Kind regards Jacques

sideffect0 commented 8 years ago

i want to output a different file ( css ) instead of js from transcrypt, from pythonic syntax is that possible?

JdeH commented 8 years ago

Hi

Transcrypt translates Python to JS, it cannot output CSS. If I understand you properly, you want to use Python-like syntax to style pages. If you look at the ios_app demo, you'll see that all styling is just done in Python (so actually in JS). All style attributes can also be accessed dynamically from Python. That's how I try to do it most of the time since CSS and me don't wear well together.

As an alternative Alexander Tsepkov, creator of RapydScript, has made something called RapydCSS, that seems to go in the direction you indicate:

http://rapydscript.pyjeon.com/rapydcss

I have no experience with it.

sideffect0 commented 8 years ago

@JdeH any way to transcrypt with React Native/React ? or electron

JdeH commented 8 years ago

Yes, you can use react. There's a react demo in the demo directory. No experience with electron yet.

sideffect0 commented 8 years ago

@JdeH any possiblities including more functions related to reactjs ? atleast it would be good if include option to add developer a plugin for transcrypt compiler like pytest plugin :) waiting for something like https://github.com/fxfactorial/ocaml-reactjs in transcrypt :)