Пример #1
0
def javascripts():
    if not hasattr(current_app, 'javascripts'):
        import coffeescript
        scripts = [
            'assets/javascripts/jquery.js',
            'assets/javascripts/es5-shim.js',
            'assets/javascripts/d3.v2.min.js',

            'assets/javascripts/batman.js',
            'assets/javascripts/batman.jquery.js',

            'assets/javascripts/jquery.gridster.js',
            'assets/javascripts/jquery.leanModal.min.js',

            #'assets/javascripts/dashing.coffee',
            'assets/javascripts/dashing.gridster.coffee',

            'assets/javascripts/jquery.knob.js',
            'assets/javascripts/rickshaw.min.js',
            #'assets/javascripts/application.coffee',
            'assets/javascripts/app.js',
            #'widgets/clock/clock.coffee',
            'widgets/number/number.coffee',
            'widgets/hotness/hotness.coffee',
            'widgets/progress_bars/progress_bars.coffee',
            'widgets/usage_gauge/usage_gauge.coffee',
        ]
        nizzle = True
        if not nizzle:
            scripts = ['assets/javascripts/application.js']

        output = []
        for path in scripts:
            path = '{1}/{0}'.format(path,os.path.dirname(os.path.realpath(__file__)))
            output.append('// JS: %s\n' % path)
            if '.coffee' in path:
                log.info('Compiling Coffee for %s ' % path)
                contents = coffeescript.compile_file(path)
            else:
                f = open(path)
                contents = f.read()
                f.close()

            output.append(contents)

        if nizzle:
            f = open('/tmp/foo.js', 'w')
            for o in output:
                print >> f, o
            f.close()

            f = open('/tmp/foo.js', 'rb')
            output = f.read()
            f.close()
            current_app.javascripts = output
        else:
            current_app.javascripts = ''.join(output)
        

    return Response(current_app.javascripts, mimetype='application/javascript')
Пример #2
0
def javascripts():
    if not hasattr(current_app, 'javascripts'):
        import coffeescript
        scripts = [
            prefix_path('assets/javascripts/jquery.js'),
            prefix_path('assets/javascripts/es5-shim.js'),
            prefix_path('assets/javascripts/d3.v2.min.js'),

            prefix_path('assets/javascripts/batman.js'),
            prefix_path('assets/javascripts/batman.jquery.js'),

            prefix_path('assets/javascripts/jquery.gridster.js'),
            prefix_path('assets/javascripts/jquery.leanModal.min.js'),

            #prefix_path('assets/javascripts/dashing.coffee'),
            prefix_path('assets/javascripts/dashing.gridster.coffee'),

            prefix_path('assets/javascripts/jquery.knob.js'),
            prefix_path('assets/javascripts/rickshaw.min.js'),

            #prefix_path('assets/javascripts/application.coffee'),
            #prefix_path('assets/javascripts/app.js'),
            'assets/app.js',
            #prefix_path('widgets/clock/clock.coffee'),

            prefix_path('widgets/number/number.coffee'),
        ]

        nizzle = True
        if not nizzle:
            scripts = [prefix_path('assets/javascripts/application.js')]

        output = []
        for path in scripts:
            output.append('// JS: %s\n' % path)
            if '.coffee' in path:
                log.info('Compiling Coffee for %s ' % path)
                contents = coffeescript.compile_file(path)
            else:
                f = open(path)
                contents = f.read()
                f.close()

            output.append(contents)

        if nizzle:
            f = open('/tmp/foo.js', 'w')
            for o in output:
                print >> f, o
            f.close()

            f = open('/tmp/foo.js', 'rb')
            output = f.read()
            f.close()
            current_app.javascripts = output
        else:
            current_app.javascripts = ''.join(output)


    return Response(current_app.javascripts, mimetype='application/javascript')
Пример #3
0
def compile_assets():
    static = app.static_folder

    with open("{}/javascript/index.js".format(static), 'w') as f:
        infile = "{}/coffeescript/index.coffee".format(static)
        js = coffeescript.compile_file(infile)
        f.write(js)
Пример #4
0
def run_coffee_query(coffee_query_file,
                     index,
                     doc_type,
                     replacements_dict=None,
                     show_only=None):
    """

    :param coffee_query_file: WARNING: this file must use JSON format
    e.g. {a:0,b:"text"} will not work, but {"a":0,"b":"text"}.
    :param index:
    :param doc_type:
    :param replacements_dict:
    :return:
    """
    global CUR_SCRIPT_PATH
    if not os.path.isabs(coffee_query_file):
        coffee_query_file = os.path.join(CUR_SCRIPT_PATH, coffee_query_file)
    compiled = coffeescript.compile_file(coffee_query_file, bare=True)
    if replacements_dict:
        for key, val in replacements_dict.items():
            compiled = compiled.replace(key, val)
    # removes unnecessary prefix and suffix added by the compiler ['(', ');']
    compiled = compiled[1:-3]
    # log.info("QUERY_JSON:\n{0}".format(compiled))
    result = es_util.es_conn.search(index=index,
                                    doc_type=doc_type,
                                    body=compiled)

    for hits_idx, hit_i in enumerate(result['hits']['hits']):
        log.info("QUERY_RESULT: SCORE:{0}".format(hit_i['_score']))
        source = hit_i['_source']
        if type(show_only) == list:
            source = filter_dict(source, show_only)
        log.info("SOURCE_{0}:\n{1}".format(hits_idx, pprint.pformat(source)))
Пример #5
0
def javascripts():
    if not hasattr(current_app, 'javascripts'):
        import coffeescript
        scripts = [
            'assets/javascripts/jquery.js',
            'assets/javascripts/es5-shim.js',
            'assets/javascripts/d3.v2.min.js',

            'assets/javascripts/batman.js',
            'assets/javascripts/batman.jquery.js',

            'assets/javascripts/jquery.gridster.js',
            'assets/javascripts/jquery.leanModal.min.js',

            'assets/javascripts/dashing.coffee',
            'assets/javascripts/dashing.gridster.coffee',
            'assets/javascripts/clickablewidget.coffee',
            'assets/javascripts/cycleDashboards.coffee',

            'assets/javascripts/jquery.knob.js',
            'assets/javascripts/rickshaw-1.4.3.min.js',
            'assets/javascripts/application.coffee',
            'widgets/clock/clock.coffee',
            'widgets/number/number.coffee',
            'widgets/text/text.coffee',
            'widgets/changepage/changepage.coffee',
            'widgets/mytemp/mytemp.coffee',
            'widgets/weather/weather.coffee',
        ]
        nizzle = True
        if not nizzle:
            scripts = ['assets/javascripts/application.js']

        output = []
        for path in scripts:
            output.append('// JS: %s\n' % path)
            if '.coffee' in path:
                log.info('Compiling Coffee for %s ' % path)
                contents = coffeescript.compile_file(path)
            else:
                f = open(path)
                contents = f.read()
                f.close()

            output.append(contents)

        if nizzle:
            f = open('/tmp/foo.js', 'w')
            for o in output:
                print >> f, o
            f.close()

            f = open('/tmp/foo.js', 'rb')
            output = f.read()
            f.close()
            current_app.javascripts = output
        else:
            current_app.javascripts = ''.join(output)

    return Response(current_app.javascripts, mimetype='application/javascript')
Пример #6
0
def compile_assets():
    static = app.static_folder

    with open("{}/javascript/index.js".format(static), 'w') as f:
        infile = "{}/coffeescript/index.coffee".format(static)
        js = coffeescript.compile_file(infile)
        f.write(js)
Пример #7
0
def javascripts():

    # TODO: refactor - this is a mess
    # should just build and cache js.

    if not hasattr(current_app, 'javascripts'):
        import coffeescript
        scripts = [
            'assets/javascripts/jquery.js',
            'assets/javascripts/es5-shim.js',
            'assets/javascripts/d3.v2.min.js',
            'assets/javascripts/batman.js',
            'assets/javascripts/batman.jquery.js',
            'assets/javascripts/jquery.gridster.js',
            'assets/javascripts/jquery.leanModal.min.js',

            #'assets/javascripts/dashing.coffee',
            'assets/javascripts/dashing.gridster.coffee',
            'assets/javascripts/jquery.knob.js',
            'assets/javascripts/rickshaw.min.js',
            #'assets/javascripts/application.coffee',
            'assets/javascripts/app.js',
            #'widgets/clock/clock.coffee',
            'widgets/number/number.coffee',
            'widgets/priority_list/priority_list.coffee',
            #if making new templates input coffee files here
            'widgets/jira/jira.coffee',
        ]
        nizzle = True
        if not nizzle:
            scripts = ['assets/javascripts/application.js']

        output = []
        for path in scripts:
            output.append('// JS: %s\n' % path)
            if '.coffee' in path:
                log.info('Compiling Coffee for %s ' % path)
                contents = coffeescript.compile_file(path)
            else:
                f = open(path)
                contents = f.read()
                f.close()

            output.append(contents)

        if nizzle:
            f = open('/tmp/foo.js', 'w')
            for o in output:
                print >> f, o
            f.close()

            f = open('/tmp/foo.js', 'rb')
            output = f.read()
            f.close()
            current_app.javascripts = output
        else:
            current_app.javascripts = ''.join(output)

    return Response(current_app.javascripts, mimetype='application/javascript')
Пример #8
0
def javascripts():
    if not hasattr(current_app, "javascripts"):
        import coffeescript

        scripts = [
            "assets/javascripts/jquery.js",
            "assets/javascripts/es5-shim.js",
            "assets/javascripts/d3.v2.min.js",
            "assets/javascripts/batman.js",
            "assets/javascripts/batman.jquery.js",
            "assets/javascripts/jquery.gridster.js",
            "assets/javascripts/jquery.leanModal.min.js",
            # 'assets/javascripts/dashing.coffee',
            "assets/javascripts/dashing.gridster.coffee",
            "assets/javascripts/jquery.knob.js",
            "assets/javascripts/rickshaw.min.js",
            # 'assets/javascripts/application.coffee',
            "assets/javascripts/app.js",
            # 'widgets/clock/clock.coffee',
            "widgets/number/number.coffee",
            "widgets/hotness/hotness.coffee",
            "widgets/progress_bars/progress_bars.coffee",
            "widgets/usage_gauge/usage_gauge.coffee",
            "widgets/nagios/nagios.coffee",
            "widgets/nagios_list/nagios_list.coffee",
            "widgets/rickshawgraph/rickshawgraph.coffee",
        ]
        nizzle = True
        if not nizzle:
            scripts = ["assets/javascripts/application.js"]

        output = []
        for path in scripts:
            path = "{1}/{0}".format(path, os.path.dirname(os.path.realpath(__file__)))
            output.append("// JS: %s\n" % path)
            if ".coffee" in path:
                log.info("Compiling Coffee for %s " % path)
                contents = coffeescript.compile_file(path)
            else:
                f = open(path)
                contents = f.read()
                f.close()

            output.append(contents)

        if nizzle:
            f = open("/tmp/foo.js", "w")
            for o in output:
                print >> f, o
            f.close()

            f = open("/tmp/foo.js", "rb")
            output = f.read()
            f.close()
            current_app.javascripts = output
        else:
            current_app.javascripts = "".join(output)

    return Response(current_app.javascripts, mimetype="application/javascript")
Пример #9
0
def coffee(name=None):
    try:
        return coffeescript.compile_file(basepath + 'live/%s.coffee' % name,
                                         bare=True)
    except Exception, e:
        print e.message
        return "$(document).ready(function() { $('#errors').text('Compilation error in \"' + %r + '\": ' + %r) })" % (
            str(name), str(e.message))
Пример #10
0
def compile_coffeescript(exclusions=list()):
    matches = utils.locate_files_to_compile('*.coffee', exclusions)

    for path, f, name in matches:
        js = coffeescript.compile_file(os.path.join(sassy_coffee.DJANGO_PATH, f), bare=True)
        from jsmin import jsmin
        compressed_js = jsmin(js)
        utils.write_to_file('js', name, path, compressed_js)
Пример #11
0
 def include_modules(self):
     for i, line in enumerate(self.text):
         if '/* include' in line:
             module_name = line.split()[2].strip()
             if '.js' in line:
                 with open(module_name, 'r') as f:
                     self.text[i] = f.read()
             elif '.coffee' in line:
                 self.text[i] = coffeescript.compile_file(module_name).split('\n')[1:-2]
                 self.text[i] = '\n'.join(self.text[i])
Пример #12
0
def compile_coffeescript(filename):
  try:
    return coffeescript.compile_file(filename)
  except execjs.RuntimeError as e:
    print "{0}: {1}".format(filename, e.message)
    sys.exit(12)
  except execjs.RuntimeError as e:
    print "{0}: {1}".format(filename, e.message)
    print "Did you remember to leave an empty line at the end of a source file?"
    sys.exit(12)
Пример #13
0
def compile_assets():
    static = app.static_folder

    with open("{}/javascript/index.js".format(static), 'w') as f:
        infile = "{}/coffeescript/index.coffee".format(static)
        js = coffeescript.compile_file(infile)
        f.write(js)

    with open('{}/css/tagged-text.css'.format(app.static_folder), 'w') as f:
        infile = "{}/scss/tagged-text.scss".format(static)
        css = sass.compile(filename=infile)
        f.write(css)
Пример #14
0
def compile_assets():
    static = app.static_folder

    with open("{}/javascript/index.js".format(static), 'w') as f:
        infile = "{}/coffeescript/index.coffee".format(static)
        js = coffeescript.compile_file(infile)
        f.write(js)

    with open('{}/css/tagged-text.css'.format(app.static_folder), 'w') as f:
        infile = "{}/scss/tagged-text.scss".format(static)
        css = sass.compile(filename=infile)
        f.write(css)
Пример #15
0
def compile_coffeescript(filename):
  """
  Compiles the specified pathed filename into javascript and warns of errors gracefully
  """
  try:
    return coffeescript.compile_file(filename)
  except execjs.RuntimeError as e:
    print "{0}: {1}".format(filename, e.message)
    sys.exit(12)
  except execjs.ProgramError as e:
    print "{0}: {1}".format(filename, e.message)
    print "Did you remember to leave an empty line at the end of a source file?"
    sys.exit(12)
Пример #16
0
        def javascripts():
            scripts = [
                "javascripts/application.coffee",
            ]

            output = []
            for path in [os.path.join(mod.root_path, "static", s)
                         for s in scripts]:
                output.append("// JS: %s\n" % path)
                if ".coffee" in path:
                    logger.debug("Compiling Coffee for %s " % path)
                    contents = coffeescript.compile_file(path)
                else:
                    with open(path) as f:
                        contents = f.read()

                output.append(contents)

            return Response("".join(output), mimetype="application/javascript")
Пример #17
0
        def javascripts():
            scripts = [
                "javascripts/application.coffee",
            ]

            output = []
            for path in [
                    os.path.join(mod.root_path, "static", s) for s in scripts
            ]:
                output.append("// JS: %s\n" % path)
                if ".coffee" in path:
                    logger.debug("Compiling Coffee for %s " % path)
                    contents = coffeescript.compile_file(path)
                else:
                    with open(path) as f:
                        contents = f.read()

                output.append(contents)

            return Response("".join(output), mimetype="application/javascript")
Пример #18
0
def javascripts():
    if not hasattr(current_app, 'javascripts'):
        import coffeescript

        ordered_script_names = [
            'jquery.js', 'es5-shim.js', 'd3.v2.min.js', 'batman.js',
            'batman.jquery.js', 'jquery.gridster.js',
            'jquery.leanModal.min.js', 'dashing.gridster.coffee',
            'jquery.knob.js', 'rickshaw.min.js'
        ]

        scripts = [
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         'javascripts', js) for js in ordered_script_names
        ]
        for ext in ['js', 'coffee']:
            scripts.extend(
                glob.glob(os.path.join(os.getcwd(), "assets/**/*.%s") % ext))
        for ext in ['js', 'coffee']:
            scripts.extend(
                glob.glob(os.path.join(os.getcwd(), "widgets/**/*.%s") % ext))

        output = []
        for path in scripts:
            output.append('// JS: %s\n' % path)
            if '.coffee' in path:
                print('Compiling Coffee for %s ' % path)
                contents = coffeescript.compile_file(path).encode(
                    'ascii', 'ignore')
            else:
                print('Reading JS for %s ' % path)
                f = open(path)
                contents = f.read()
                f.close()

            output.append(contents)

        current_app.javascripts = "\n".join(output)

    return Response(current_app.javascripts, mimetype='application/javascript')
Пример #19
0
    def _collect_quiz_static(self, quiz_directory, tarball):
        log = logger.bind()
        log.info("Start to collect static from quiz directory",
                 quiz_directory=quiz_directory)
        quiz_basedir = os.path.basename(quiz_directory)
        tarball_quiz_dir = os.path.join('stepic_plugins', quiz_basedir)

        coffee_pattern = '*.coffee'
        patterns = ['*.js', '*.css', '*.hbs', coffee_pattern]

        for file in os.listdir(quiz_directory):
            if all(not fnmatch.fnmatch(file, p) for p in patterns):
                continue
            source_file = os.path.join(quiz_directory, file)
            tar_file = os.path.join(tarball_quiz_dir, file)
            if fnmatch.fnmatch(file, coffee_pattern):
                log = log.bind(file=source_file)
                try:
                    import coffeescript
                except ImportError:
                    log.error("Package 'CoffeeScript' is required to compile "
                              "static file, it will be skipped")
                    continue

                tar_file = os.path.splitext(tar_file)[0] + '.js'
                try:
                    source_compiled = (coffeescript.compile_file(source_file)
                                       .encode())
                except (coffeescript.EngineError,
                        coffeescript.CompilationError):
                    log.exception("Failed to compile coffeescript file, "
                                  "it will be skipped")
                    continue
                log.info("Successfully compiled coffeescript file")
                tar_info = tarfile.TarInfo(name=tar_file)
                tar_info.size = len(source_compiled)
                tar_info.mtime = os.path.getmtime(source_file)
                tarball.addfile(tar_info, fileobj=io.BytesIO(source_compiled))
            else:
                tarball.add(source_file, arcname=tar_file)
Пример #20
0
    def _collect_quiz_static(self, quiz_directory, tarball):
        log = logger.bind()
        log.info("Start to collect static from quiz directory",
                 quiz_directory=quiz_directory)
        quiz_basedir = os.path.basename(quiz_directory)
        tarball_quiz_dir = os.path.join('stepic_plugins', quiz_basedir)

        coffee_pattern = '*.coffee'
        patterns = ['*.js', '*.css', '*.hbs', coffee_pattern]

        for file in os.listdir(quiz_directory):
            if all(not fnmatch.fnmatch(file, p) for p in patterns):
                continue
            source_file = os.path.join(quiz_directory, file)
            tar_file = os.path.join(tarball_quiz_dir, file)
            if fnmatch.fnmatch(file, coffee_pattern):
                log = log.bind(file=source_file)
                try:
                    import coffeescript
                except ImportError:
                    log.error("Package 'CoffeeScript' is required to compile "
                              "static file, it will be skipped")
                    continue

                tar_file = os.path.splitext(tar_file)[0] + '.js'
                try:
                    source_compiled = (
                        coffeescript.compile_file(source_file).encode())
                except (coffeescript.EngineError,
                        coffeescript.CompilationError):
                    log.exception("Failed to compile coffeescript file, "
                                  "it will be skipped")
                    continue
                log.info("Successfully compiled coffeescript file")
                tar_info = tarfile.TarInfo(name=tar_file)
                tar_info.size = len(source_compiled)
                tar_info.mtime = os.path.getmtime(source_file)
                tarball.addfile(tar_info, fileobj=io.BytesIO(source_compiled))
            else:
                tarball.add(source_file, arcname=tar_file)
Пример #21
0
    def test_compile_files(self):
        encodings = "shift-jis utf-8 euc-jp".split()
        combinations_of_configs = product(
            self.compilers,
            encodings,
            self.runtimes
        )
        for compiler, encoding, runtime in combinations_of_configs:
            compile_file = compiler.compile_file

            filenames = []
            for i, _ in enumerate(coffee_codes):
                (fd, fn) = tempfile.mkstemp()
                filenames.append(fn)
                os.close(fd)

            try:
                for coffee_code, filename in zip(coffee_codes, filenames):
                    with io.open(filename, "w", encoding=encoding) as fp:
                        fp.write(coffee_code)

                jscode = coffeescript.compile_file(
                    filenames, encoding=encoding, bare=True)
                ctx = runtime.compile(jscode)
                self.assertEqual(ctx.call("add", 1, 2), 3)
                self.assertEqual(ctx.call("add", hello, world), helloworld)
                self.assertEqual(ctx.eval("helloworld"), helloworld)

                jscode = coffeescript.compile_file(
                    filenames, encoding=encoding, bare=False)
                ctx = runtime.compile(jscode)
                with self.assertRaises(execjs.ProgramError):
                    self.assertEqual(ctx.call("add", 1, 2), 3)
                with self.assertRaises(execjs.ProgramError):
                    self.assertEqual(ctx.call("add", hello, world), helloworld)
                with self.assertRaises(execjs.ProgramError):
                    self.assertEqual(ctx.eval("helloworld"), helloworld)

                for wrong_encoding in set(encodings) - set([encoding]):
                    with self.assertRaises(UnicodeDecodeError):
                        coffeescript.compile_file(
                            filename, encoding=wrong_encoding, bare=True)
                    with self.assertRaises(UnicodeDecodeError):
                        coffeescript.compile_file(
                            filename, encoding=wrong_encoding, bare=False)
            finally:
                os.remove(filename)
Пример #22
0
def javascripts():
    if not hasattr(current_app, 'javascripts'):
        import coffeescript

        ordered_script_names = [
            'jquery.js',
            'es5-shim.js',
            'd3.v2.min.js',
            'batman.js',
            'batman.jquery.js',
            'jquery.gridster.js',
            'jquery.leanModal.min.js',
            'dashing.gridster.coffee',
            'jquery.knob.js',
            'rickshaw.min.js'
        ]

        scripts = [os.path.join(os.path.dirname(os.path.abspath(__file__)), 'javascripts', js) for js in ordered_script_names]
        for ext in ['js', 'coffee']: scripts.extend(glob.glob(os.path.join(os.getcwd(), "assets/**/*.%s") % ext))
        for ext in ['js', 'coffee']: scripts.extend(glob.glob(os.path.join(os.getcwd(), "widgets/**/*.%s") % ext))

        output = []
        for path in scripts:
            output.append('// JS: %s\n' % path)
            if '.coffee' in path:
                print('Compiling Coffee for %s ' % path)
                contents = coffeescript.compile_file(path).encode('ascii','ignore')
            else:
                print('Reading JS for %s ' % path)
                f = open(path)
                contents = f.read()
                f.close()

            output.append(contents)

        current_app.javascripts = "\n".join(output)

    return Response(current_app.javascripts, mimetype='application/javascript')
Пример #23
0
def compile_coffee_bare(file_path):
    return coffeescript.compile_file(file_path, bare=True)
Пример #24
0
def javascripts():
    if not hasattr(current_app, 'javascripts'):
        import coffeescript
        scripts = [
            'assets/javascripts/jquery.js',
            'assets/javascripts/es5-shim.js',
            'assets/javascripts/d3.v2.min.js',
            'assets/javascripts/batman.js',
            'assets/javascripts/batman.jquery.js',
            'assets/javascripts/jquery.gridster.js',
            'assets/javascripts/jquery.leanModal.min.js',
            'assets/javascripts/dashing.coffee',
            'assets/javascripts/dashing.gridster.coffee',
            'assets/javascripts/cycleDashboards.coffee',
            'assets/javascripts/jquery.knob.js',
            'assets/javascripts/rickshaw.min.js',
            'assets/javascripts/application.coffee',
            #'assets/javascripts/app.js',
            'widgets/clock/clock.coffee',
            'assets/javascripts/clickablewidget.coffee',
            'widgets/stswitch/stswitch.coffee',
            'widgets/stmode/stmode.coffee',
            'widgets/stselectcolor/stselectcolor.coffee',
            'widgets/stselecthue/stselecthue.coffee',
            'widgets/stmodechange/stmodechange.coffee',
            'widgets/stdimmer/stdimmer.coffee',
            'widgets/stpresence/stpresence.coffee',
            'widgets/stweather/stweather.coffee',
            'widgets/sthumidity/sthumidity.coffee',
            'widgets/sttemp/sttemp.coffee',
            'widgets/stsetlevel/stsetlevel.coffee',
            'widgets/stselectdimmer/stselectdimmer.coffee',
            'widgets/stcontact/stcontact.coffee',
            'widgets/stmotion/stmotion.coffee',
            'widgets/stmeter/stmeter.coffee',
            'widgets/changepage/changepage.coffee',
            'widgets/number/number.coffee',
        ]
        nizzle = True
        if not nizzle:
            scripts = ['assets/javascripts/application.js']

        output = []
        for path in scripts:
            output.append('// JS: %s\n' % path)
            if '.coffee' in path:
                log.info('Compiling Coffee for %s ' % path)
                contents = coffeescript.compile_file(path)
            else:
                f = open(path)
                contents = f.read()
                f.close()

            output.append(contents)

        if nizzle:
            f = open('/tmp/foo.js', 'w')
            for o in output:
                print >> f, o
            f.close()

            f = open('/tmp/foo.js', 'rb')
            output = f.read()
            f.close()
            current_app.javascripts = output
        else:
            current_app.javascripts = ''.join(output)

    return Response(current_app.javascripts, mimetype='application/javascript')
Пример #25
0
    import stepic_plugins
    __package__ = str("stepic_plugins")

from .server import load_by_name

if __name__ == "__main__":
    name = sys.argv[1]
    quiz = load_by_name(name)
    quiz_directory = os.path.dirname(getsourcefile(quiz.wrapped_class))
    static_directory = os.path.join(os.path.dirname(__file__), 'static', 'stepic_plugins', name)

    if os.path.exists(static_directory):
        shutil.rmtree(static_directory)
    os.mkdir(static_directory)
    coffee = '*.coffee'
    patterns = ['*.js', '*.css', '*.hbs', coffee]
    for file in os.listdir(quiz_directory):
        if any(fnmatch.fnmatch(file, p) for p in patterns):
            source = os.path.join(quiz_directory, file)
            target = os.path.join(static_directory, file)

            if fnmatch.fnmatch(file, coffee):
                if coffeescript is None:
                    print('package `CoffeeScript` required', file=sys.stderr)
                target = os.path.splitext(target)[0] + '.js'
                with open(target, 'w') as f:
                    f.write(coffeescript.compile_file(source))
            else:
                relative_source = os.path.relpath(source, static_directory)
                os.symlink(relative_source, target)
Пример #26
0
import coffeescript as coffee
import os

for root, dirs, files in os.walk(os.sep.join([os.getcwd(), "Scripts"])):
    for file in files:
        _, extension = os.path.splitext(file)

        if extension != ".coffee":
            continue

        print "Compiling %s..." % file
        fullPath = os.sep.join([root, file])
        jsFile = os.sep.join([root, _ + ".js"])
        compiled = coffee.compile_file(fullPath, bare=True)

        with open(jsFile, "w") as js:
            js.write(compiled)
            js.flush()
Пример #27
0
 def __init__(self, filename):
     self.text = coffeescript.compile_file(filename).split('\n')
Пример #28
0
def js():
	import coffeescript
	nizzle = True
	if not nizzle:
		scripts = ['assets/javascripts/application.js']
	scripts = [
		'javascript/jquery.js',
		'dashing/javascripts/es5-shim.js',
		'dashing/templates/project/assets/javascripts/d3-3.2.8.js',

		'dashing/javascripts/batman.js',
		'dashing/javascripts/batman.jquery.js',

		'dashing/templates/project/assets/javascripts/gridster/jquery.gridster.js',
		'dashing/templates/project/assets/javascripts/gridster/jquery.leanModal.min.js',

		'javascript/jquery-ui.js',
		'javascript/jquery.ui.touch-punch.js',

		'javascript/dashicz.coffee',
		'dashing/templates/project/assets/javascripts/dashing.gridster.coffee',

		'dashing/templates/project/assets/javascripts/jquery.knob.js',
		'dashing/templates/project/assets/javascripts/rickshaw-1.4.3.min.js',
		'dashing/templates/project/assets/javascripts/application.coffee',

		'javascript/application_dashicz.coffee',
		'jquery-timeago/jquery.timeago.js',
		'jquery-timeago/locales/jquery.timeago.nl.js', # change to your language
		]

	for name in widgets:
		scripts.append(os.path.join("widgets", name, name+".coffee"))
	output = []
	for path in scripts:
		output.append('// JS: %s\n' % path)
		if '.coffee' in path:
			log.info('Compiling Coffee for %s ' % path)
			contents = coffeescript.compile_file(path)
		else:
			f = open(path)
			contents = f.read()
			f.close()

		output.append(contents)

	if nizzle:
		f = open('/tmp/foo.js', 'w')
		for o in output:
			print >> f, o
		f.close()

		f = open('/tmp/foo.js', 'rb')
		output = f.read()
		f.close()
		#current_app.javascripts = output
	#else:
	#	current_app.javascripts = ''.join(output)
		
	fn = os.path.join(os.path.dirname(__file__), "all.js")
	print "writing", fn
	file(fn, "w").write("".join(output))
Пример #29
0
        '--compile',
        default=False,
        action='store_true',
        help=
        'Ignored. Exists only for compatibility with the native CoffeeScript compiler.'
    )
    parser.add_argument('filename',
                        metavar='<CoffeeScript file>',
                        nargs='+',
                        help='CoffeeScript file to compile.')
    args = parser.parse_args()

    for filename in args.filename:
        if args.output:
            path_pair = os.path.split(filename)
            ext_pair = os.path.splitext(path_pair[1])
            coffee_file = ext_pair[0] + '.js' if ext_pair[1].lower(
            ) == '.coffee' else path_pair[1] + '.js'
            # The native CoffeeScript compiler appears to do the equivalent of os.path.normpath()
            coffee_path = os.path.normpath(
                os.path.join(args.output, coffee_file))
        else:
            ext_pair = os.path.splitext(filename)
            coffee_path = ext_pair[0] + '.js' if ext_pair[1].lower(
            ) == '.coffee' else filename + '.js'
        if args.verbose:
            print 'Compiling %s into %s' % (filename, coffee_path)
        out = coffeescript.compile_file(filename, bare=args.bare)
        with open(coffee_path, 'w') as fout:
            fout.write(out)
 def assert_compile_file_decode_error(self, filename, encoding, bare):
     with self.assertRaises(UnicodeDecodeError):
         coffeescript.compile_file(filename, encoding=encoding, bare=bare)
Пример #31
0
def js(file):
    return coffeescript.compile_file('views/' + file + '.coffee')
Пример #32
0
def coffee(name=None):
	try:
		return coffeescript.compile_file('%s.coffee' % name, bare=True)
	except Exception, e:
		print e.message
		return "console.log('Compilation error in \"' + %r + '\": ' + %r)" % (str(name), str(e.message))
Пример #33
0
import coffeescript as coffee
import os, execjs

for root, dirs, files in os.walk( os.sep.join( [ os.getcwd(), "Scripts" ] ) ):
    for file in files:
        _, extension = os.path.splitext( file )
        
        if extension != ".coffee":
            continue
        
        print "Compiling %s..." % file
        fullPath = os.sep.join( [ root, file ] )
        jsFile = os.sep.join( [ root, _ + ".js" ] )
        
        compiled = None
        
        try:
            compiled = coffee.compile_file( fullPath, bare = True )
        except execjs.ProgramError as e:
            print
            print e.message.replace( "[stdin]", file )
        else:    
            with open( jsFile, "w" ) as js:
                js.write( compiled )
                js.flush()
Пример #34
0
 def compile_coffee_bare(file_path):
     return coffeescript.compile_file(file_path, bare=True)
Пример #35
0
def main():
    #Options
    refreshDashingCode=False
    
    #Check out dashing into temp directory
    current_directory = os.getcwd()
    
    tmp_dir = os.path.join(current_directory, 'tmp')
    if not os.path.exists(tmp_dir):
        log.info(' Creating tmp dir %s' % tmp_dir)
        os.mkdir(tmp_dir)
        
    tmp_build_dir = os.path.join(tmp_dir, 'bin')
    if not os.path.exists(tmp_build_dir):
        log.info(' Creating bin dir %s' % tmp_build_dir)
        os.mkdir(tmp_build_dir)
    
    dashing_dir = os.path.join(current_directory, 'tmp', 'dashing')

    if refreshDashingCode:
        if os.path.exists(dashing_dir):
            log.info(' Removing old Dashing Clone')
            shutil.rmtree(dashing_dir)
            
        log.info(' Creating dashing tmp dir %s' % dashing_dir)
        os.mkdir(dashing_dir)
    
    os.chdir(dashing_dir)
    if refreshDashingCode:
        log.info('Cloning Dashing Code')
        subprocess.call("git clone https://github.com/Shopify/dashing", shell=True)
    current_dashing_dir = os.path.join(current_directory, 'src')
    
    fileList = []
    for root, subFolders, files in os.walk(current_dashing_dir):
        for fileName in files:
            if 'scss' in fileName: 
                fileList.append(os.path.join(root, fileName))
                log.info(' Found SCSS to compile: %s' % fileName)

    import StringIO
    css_output = StringIO.StringIO()
    css = Scss()
    css_output.write('\n'.join([css.compile(open(filePath).read()) for filePath in fileList]))
    

    fileList = []
    for root, subFolders, files in os.walk(dashing_dir):
        for fileName in files:
            if 'css' in fileName and 'scss' not in fileName: 
                fileList.append(os.path.join(root, fileName))
                log.info(' Found CSS to append: %s' % fileName)
    css_output.write('\n'.join([open(filePath).read() for filePath in fileList]))
    
    with open(os.path.join(tmp_build_dir, 'application.css'), 'w') as outfile:
        outfile.write(css_output.getvalue())
        log.info(' Wrote tmp CSS out')

    dashing_css_dir = os.path.join(current_directory, 'dashboard', 'assets', 'stylesheets')
    try:
        os.rename(dashing_css_dir+'/application.css', dashing_css_dir+'/application.css_backup')
        log.info(' Wrote backup CSS out')
    except:
        log.info(' No backup made.')

    with open(os.path.join(dashing_css_dir, 'application.css'), 'w') as outfile:
        outfile.write(css_output.getvalue())
        log.info(' Wrote perm CSS out')

    import coffeescript
    src_dir = os.path.join(current_directory, 'dashboard')
    os.chdir(src_dir)
    # add your js and coffee scripts to be compiled
    scripts = [
        'assets/javascripts/jquery.js',
        'assets/javascripts/es5-shim.js',
        'assets/javascripts/d3.v2.min.js',

        'assets/javascripts/batman.js',
        'assets/javascripts/batman.jquery.js',

        'assets/javascripts/jquery.gridster.js',
        'assets/javascripts/jquery.leanModal.min.js',

        #'assets/javascripts/dashing.coffee',
        'assets/javascripts/dashing.gridster.coffee',

        'assets/javascripts/jquery.knob.js',
        'assets/javascripts/rickshaw.min.js',
        #'assets/javascripts/application.coffee',
        'assets/javascripts/app.js',
        #'widgets/clock/clock.coffee',
        'widgets/number/number.coffee',
        'widgets/rickshawgraph/rickshawgraph.coffee',
    ]

    import codecs
    output = []
    for path in scripts:
        output.append('// JS: %s\n' % path)
        if '.coffee' in path:
            log.info(' Compiling Coffee for %s ' % path)
            contents = coffeescript.compile_file(path)
        else:
            f = codecs.open(path, 'r', encoding='utf-8')
            contents = f.read()
            f.close()

        output.append(contents)
    try:
        os.rename('assets/javascripts/application.js', 'assets/javascripts/application.js_backup')
        log.info(' Backed up application.js_backup')
    except:
        log.info(' No backup for application.js')

    f = codecs.open('assets/javascripts/application.js', 'w', encoding='utf-8')
    for o in output:
        print >> f, o
    f.close()
    log.info(' Wrote application.js out')
Пример #36
0
    __package__ = str("stepic_plugins")

from .server import load_by_name

if __name__ == "__main__":
    name = sys.argv[1]
    quiz = load_by_name(name)
    quiz_directory = os.path.dirname(getsourcefile(quiz.wrapped_class))
    static_directory = os.path.join(os.path.dirname(__file__), "static", "stepic_plugins", name)

    if os.path.exists(static_directory):
        shutil.rmtree(static_directory)
    os.mkdir(static_directory)
    coffee = "*.coffee"
    patterns = ["*.js", "*.css", "*.hbs", coffee]
    for file in os.listdir(quiz_directory):
        if any(fnmatch.fnmatch(file, p) for p in patterns):
            source = os.path.join(quiz_directory, file)
            target = os.path.join(static_directory, file)

            if fnmatch.fnmatch(file, coffee):
                if coffeescript is None:
                    print("package `CoffeeScript` required", file=sys.stderr)
                target = os.path.splitext(target)[0] + ".js"
                with open(target, "w") as f:
                    f.write(coffeescript.compile_file(source))
            else:
                relative_source = os.path.relpath(source, static_directory)
                os.symlink(relative_source, target)
Пример #37
0
def coffee(name=None):
	try:
		return coffeescript.compile_file(basepath + 'live/%s.coffee' % name, bare=True)
	except Exception, e:
		print e.message
		return "$(document).ready(function() { $('#errors').text('Compilation error in \"' + %r + '\": ' + %r) })" % (str(name), str(e.message))
 def assert_compile_file_fail(self, filename, encoding, bare):
     jscode = coffeescript.compile_file(filename,
                                        encoding=encoding,
                                        bare=bare)
     ctx = execjs.compile(jscode)
     self.assertExprsFail(ctx)
Пример #39
0
def coffee(file):
    return coffeescript.compile_file('coffee/' + file)