Example #1
0
    def test_transform(self):
        jsx_path = join(TEST_ROOT, 'files/test.jsx')
        js_path = join(TEST_ROOT, 'files/test.js')

        with open(js_path, 'rU') as js:
            self.assertEquals(jsx.transform(jsx_path), js.read())

        malformed_path = join(TEST_ROOT, 'files/malformed.jsx')
        self.assertRaises(jsx.TransformError,
                          lambda: jsx.transform(malformed_path))
Example #2
0
    def test_transform(self):
        jsx_path = join(TEST_ROOT, 'files/test.jsx')
        js_path = join(TEST_ROOT, 'files/test.js')

        with open(js_path, 'rU') as js:
            self.assertEquals(
                jsx.transform(jsx_path),
                unicode(js.read()))

        malformed_path = join(TEST_ROOT, 'files/malformed.jsx')
        self.assertRaises(
            jsx.TransformError,
            lambda: jsx.transform(malformed_path))
Example #3
0
 def compile_jsx(filename):
     """ Parse the JSX on the fly if we're in debug mode """
     filename = re.sub(r"\-[0-9]+", "", filename)
     jsx_path = os.path.join(app.root_path, 'static/js/%sx' % filename)
     print jsx_path
     try:
         js = jsx.transform(jsx_path)
         return app.response_class(response=js, mimetype='text/javascript')
     except jsx.TransformError as e:
         return app.response_class(response="%s" % e, status=500)
Example #4
0
 def compile_jsx(filename):
     """ Parse the JSX on the fly if we're in debug mode """
     filename = re.sub(r"\-[0-9]+", "", filename)
     jsx_path = os.path.join(app.root_path, 'static/js/%sx' % filename)
     print jsx_path
     try:
         js = jsx.transform(jsx_path)
         return app.response_class(response=js, mimetype='text/javascript')
     except jsx.TransformError as e:
         return app.response_class(response="%s" % e, status=500)
Example #5
0
def transform_jsx_view(jsx_filepath):
    """
    web2py .jsx View compilieren 
    und js als String zurückgeben
    """
    js = ''
    if jsx_filepath.endswith('.jsx'):
        # .jsx Datei wird geöffnenet und umgewandelt
        js_filepath = jsx_filepath.replace('.jsx', '.js')
        js = jsx.transform(jsx_filepath)
    return js
Example #6
0
    def process(self):
        one, two, three = zip(*self.x)

        for z in two[0]:
            current_dir = "{}/{}".format(JSX_FILES_DIR, z)

            """
            Creating directory for compiled js
            """
            self.create_dir_and_file(z)

            """
            Walking through current directory and grabbing all JSX files to compile
            """
            self.x = os.walk(current_dir)
            one, two, three = zip(*self.x)

            for t in three[0]:
                jsx.transform(jsx_path="{}/{}".format(current_dir, t),
                              js_path="{}/{}/{}".format(JSX_FILES_COMPILED_DIR, z, str(t).replace("jsx", "js")))
Example #7
0
    def parse_import_path(self, path):
        url_base = self.url_base
        url_map = self.url_map

        path = normalize_path(path)
        if path.find('!') >= 0 :
            path = path.split('!')
            prefix = path[0]
            if prefix in url_map:
                path = normalize_path(url_base + url_map[prefix] + path[1])
            else: 
                raise Exception('prefix not found ! (' + prefix + ')')    
        else:
            path = url_base + path

        if os.path.isfile(path):
            fileext = os.path.splitext(path)[1]
            if fileext == '.js' and jsx:
                with open(path) as handler:
                    content = handler.read().decode('utf-8')
                if self._match_jsx_notation(content):
                    temp = tempfile.mkstemp(fileext)
                    self._tempfile.append(temp)
                    jsx.transform(path, temp[1])
                    path = temp[1]
            if fileext == '.scss' and SCSSCompiler:
                compiler = SCSSCompiler(search_path=(self.scss_root,))
                temp = tempfile.mkstemp('.css')
                self._tempfile.append(temp)
                with open(path) as handler:
                    content = handler.read().decode('utf-8')
                content = compiler.compile_string(content)
                os.write(temp[0], content.encode('utf-8'))
                path = temp[1]

        return path
Example #8
0
    def parse_import_path(self, path):
        url_base = self.url_base
        url_map = self.url_map

        path = normalize_path(path)
        if path.find('!') >= 0:
            path = path.split('!')
            prefix = path[0]
            if prefix in url_map:
                path = normalize_path(url_base + url_map[prefix] + path[1])
            else:
                raise Exception('prefix not found ! (' + prefix + ')')
        else:
            path = url_base + path

        if os.path.isfile(path):
            fileext = os.path.splitext(path)[1]
            if fileext == '.js' and jsx:
                with open(path) as handler:
                    content = handler.read()
                if self._match_jsx_notation(content):
                    temp = tempfile.mkstemp(fileext)
                    self._tempfile.append(temp)
                    jsx.transform(path, temp[1])
                    path = temp[1]
            if fileext == '.scss' and SCSSCompiler:
                compiler = SCSSCompiler(search_path=(self.scss_root, ))
                temp = tempfile.mkstemp('.css')
                self._tempfile.append(temp)
                with open(path) as handler:
                    content = handler.read()
                content = compiler.compile_string(content)
                os.write(temp[0], content.encode('utf-8'))
                path = temp[1]

        return path
Example #9
0
    def get_content(cls, abspath, start=None, end=None):
        # Only override in the case of a JSX file
        ext = abspath.split('.')[-1]
        if ext.lower() != 'jsx':
            static = super(JSXStaticFileHandler, cls).get_content(
                abspath, start=start, end=end)

            for x in static:
                yield x
            return

        content = jsx.transform(abspath)
        buf = StringIO.StringIO(content)

        if start is not None:
            buf.seek(start)

        if end is not None:
            remaining = end - (start or 0)
        else:
            remaining = None

        chunk_size = 64 * 1024
        while True:
            if remaining is not None and remaining < chunk_size:
                chunk_size = remaining

            chunk = buf.read(chunk_size)

            if chunk:
                if remaining is not None:
                    remaining -= len(chunk)
                yield chunk

            else:
                if remaining is not None:
                    assert remaining == 0
                return
Example #10
0
from react import jsx

# For a single file, you can use a shortcut method.
jsx.transform("website/public/js/riverComponents.jsx", js_path="website/public/js/riverComponents.js")
Example #11
0
def transform_component(file_path, filename):
    try:
        return jsx.transform(file_path,
                             js_path='/static/bundles/{}'.format(filename))
    except:
        raise Exception("Unable to compile")
Example #12
0
from react import jsx

# For a single file, you can use a shortcut method.
jsx.transform('website/public/js/riverComponents.jsx',
              js_path='website/public/js/riverComponents.js')
Example #13
0
from flask import Flask, request, render_template, url_for
import json
from react import jsx
import youtube_dl

app = Flask(__name__)
ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s%(ext)s'})


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/api/url')
def get_url():
    with ydl:
        result = ydl.extract_info(request.args.get('q'), download=False)
    print result['url']
    return json.dumps({'url': result['url'], 'thumbnail': result['thumbnail']})


if __name__ == "__main__":
    with open('static/js/main.js', "w") as jsx_file:
        jsx_file.write(jsx.transform('static/js/main.jsx'))
    app.run(debug=True)