Example #1
0
    def _do_compilation(self, dest_path):
        if not os.path.isabs(dest_path):
            dest_path = os.path.join(os.getcwd(), dest_path)

        if not os.path.exists(dest_path):
            os.makedirs(dest_path)

        assets = self.gears.get_public_assets(app)
        environment = self.gears.get_environment(app)
        environment.root = dest_path

        for path in assets:
            try:
                asset = build_asset(environment, path)
            except FileNotFound:
                continue
            except TypeError:
                continue

            dest_filename = os.path.split(path)[1]
            asset_source = bytes(str(asset), 'utf-8')
            environment.save_file(dest_filename, asset_source)
            src_path = os.path.relpath(asset.absolute_path)
            dest_path = os.path.relpath(os.path.join(environment.root, path))
            puts(colored.green('- compiled %s to %s' % (src_path, dest_path)))
Example #2
0
    def _do_compilation(self, dest_path):
        if not os.path.isabs(dest_path):
            dest_path = os.path.join(os.getcwd(), dest_path)

        if not os.path.exists(dest_path):
            os.makedirs(dest_path)

        assets = self.gears.get_public_assets(app)
        environment = self.gears.get_environment(app)
        environment.root = dest_path

        for path in assets:
            try:
                asset = build_asset(environment, path)
            except FileNotFound:
                continue
            except TypeError:
                continue

            dest_filename = os.path.split(path)[1]
            asset_source = bytes(str(asset), 'utf-8')
            environment.save_file(dest_filename, asset_source)
            src_path = os.path.relpath(asset.absolute_path)
            dest_path = os.path.relpath(os.path.join(environment.root, path))
            puts(colored.green('- compiled %s to %s' % (src_path, dest_path)))
Example #3
0
def serve(request, path, **kwargs):
    if not settings.DEBUG and not kwargs.get("insecure"):
        raise ImproperlyConfigured(
            "The gears view can only be used in debug mode or if the " "--insecure option of 'runserver' is used."
        )

    # It is only required check because we generate
    # version arg for each file
    if "HTTP_IF_MODIFIED_SINCE" in request.META:
        response = HttpResponse()
        response["Expires"] = http_date(time.time() + MAX_AGE)
        response.status_code = 304
        return response

    normalized_path = posixpath.normpath(parse.unquote(path)).lstrip("/")
    try:
        asset = build_asset(environment, normalized_path)
    except FileNotFound:
        return staticfiles_serve(request, path, **kwargs)

    last_modified = asset.mtime
    if request.GET.get("body"):
        asset = asset.processed_source
    mimetype, encoding = mimetypes.guess_type(normalized_path)
    mimetype = mimetype or "application/octet-stream"
    response = HttpResponse(asset, mimetype=mimetype)
    if encoding:
        response["Content-Encoding"] = encoding
    response["Last-Modified"] = http_date(last_modified)
    return response
Example #4
0
def serve(request, path, **kwargs):
    if not settings.DEBUG and not kwargs.get('insecure'):
        raise ImproperlyConfigured(
            "The gears view can only be used in debug mode or if the "
            "--insecure option of 'runserver' is used.")

    # It is only required check because we generate
    # version arg for each file
    if 'HTTP_IF_MODIFIED_SINCE' in request.META:
        response = HttpResponse()
        response['Expires'] = http_date(time.time() + MAX_AGE)
        response.status_code = 304
        return response

    normalized_path = posixpath.normpath(urllib.unquote(path)).lstrip('/')
    try:
        asset = build_asset(environment, normalized_path)
    except FileNotFound:
        return staticfiles_serve(request, path, **kwargs)

    last_modified = asset.mtime
    if request.GET.get('body'):
        asset = asset.processed_source
    mimetype, encoding = mimetypes.guess_type(normalized_path)
    mimetype = mimetype or 'application/octet-stream'
    response = HttpResponse(bytes(asset), mimetype=mimetype)
    if encoding:
        response['Content-Encoding'] = encoding
    response['Last-Modified'] = http_date(last_modified)
    return response
Example #5
0
 def render(self, context):
     logical_path = self.logical_path.resolve(context)
     if self.debug or GEARS_DEBUG:
         asset = build_asset(environment, logical_path)
         paths = (('%s?body=1' % r.attributes.logical_path) for r in asset.requirements)
     else:
         paths = (logical_path,)
     return '\n'.join((self.template % path) for path in paths)
Example #6
0
 def render(self, context):
     logical_path = self.logical_path.resolve(context)
     if self.debug or GEARS_DEBUG:
         asset = build_asset(environment, logical_path)
         paths = (('%s?body=1' % r.attributes.logical_path)
                  for r in asset.requirements)
     else:
         paths = (logical_path, )
     return '\n'.join((self.template % path) for path in paths)
Example #7
0
 def asset_view(self, filename):
     environment = current_app.extensions['gears']['environment']
     static_view = current_app.extensions['gears']['static_view']
     try:
         asset = build_asset(environment, filename)
     except FileNotFound:
         return static_view(filename)
     mimetype, encoding = mimetypes.guess_type(filename)
     return send_file(StringIO(asset), mimetype=mimetype, conditional=True)
Example #8
0
 def asset_view(self, filename):
     environment = current_app.extensions['gears']['environment']
     static_view = current_app.extensions['gears']['static_view']
     try:
         asset = build_asset(environment, filename)
     except FileNotFound:
         return static_view(filename)
     if request.args.get('body'):
         asset = asset.processed_source.encode('utf-8')
     mimetype, encoding = mimetypes.guess_type(filename)
     return send_file(BytesIO(bytes(asset)), mimetype=mimetype, conditional=True)
Example #9
0
 def render(self, context):
     logical_path = self.logical_path.resolve(context)
     if self.debug or GEARS_DEBUG:
         asset = build_asset(environment, logical_path)
         paths = (('%s?body=1&v=%s' % (r.attributes.logical_path, r.mtime))\
             for r in asset.requirements)
     else:
         if logical_path in environment.manifest.files:
             logical_path = environment.manifest.files[logical_path]
         paths = (logical_path,)
     return '\n'.join((self.template % path) for path in paths)
Example #10
0
 def render(self, context):
     logical_path = self.logical_path.resolve(context)
     if self.debug or GEARS_DEBUG:
         asset = build_asset(environment, logical_path)
         paths = (('%s?body=1&v=%s' % (r.attributes.logical_path, r.mtime))\
             for r in asset.requirements)
     else:
         if logical_path in environment.manifest.files:
             logical_path = environment.manifest.files[logical_path]
         paths = (logical_path, )
     return '\n'.join((self.template % path) for path in paths)
Example #11
0
 def asset_view(self, filename):
     environment = current_app.extensions['gears']['environment']
     static_view = current_app.extensions['gears']['static_view']
     try:
         asset = build_asset(environment, filename)
     except FileNotFound:
         return static_view(filename)
     if request.args.get('body'):
         asset = asset.processed_source.encode('utf-8')
     mimetype, encoding = mimetypes.guess_type(filename)
     source = bytes(asset)
     return send_file(StringIO(source), mimetype=mimetype, conditional=True)
Example #12
0
 def html_tag(self, template, logical_path, debug=False):
     environment = self.get_environment(current_app)
     if debug or self.debug(current_app):
         asset = build_asset(environment, logical_path)
         urls = []
         for requirement in asset.requirements:
             logical_path = requirement.attributes.logical_path
             url = url_for('static', filename=logical_path, body=1)
             urls.append(url)
     else:
         if logical_path in environment.manifest.files:
             logical_path = environment.manifest.files[logical_path]
         urls = (url_for('static', filename=logical_path),)
     return Markup('\n'.join(template.format(url=url) for url in urls))
Example #13
0
 def html_tag(self, template, logical_path, debug=False):
     environment = self.get_environment(current_app)
     if debug or self.debug(current_app):
         asset = build_asset(environment, logical_path)
         urls = []
         for requirement in asset.requirements:
             logical_path = requirement.attributes.logical_path
             url = url_for('static', filename=logical_path, body=1)
             urls.append(url)
     else:
         if logical_path in environment.manifest.files:
             logical_path = environment.manifest.files[logical_path]
         urls = (url_for('static', filename=logical_path), )
     return Markup('\n'.join(template.format(url=url) for url in urls))
Example #14
0
def serve(request, path, **kwargs):
    if not settings.DEBUG and not kwargs.get('insecure'):
        raise ImproperlyConfigured(
            "The gears view can only be used in debug mode or if the "
            "--insecure option of 'runserver' is used.")
    normalized_path = posixpath.normpath(urllib.unquote(path)).lstrip('/')
    try:
        asset = build_asset(environment, normalized_path)
    except FileNotFound:
        return staticfiles_serve(request, path, **kwargs)
    if request.GET.get('body'):
        asset = asset.processed_source
    mimetype, encoding = mimetypes.guess_type(normalized_path)
    mimetype = mimetype or 'application/octet-stream'
    response = HttpResponse(str(asset), mimetype=mimetype)
    if encoding:
        response['Content-Encoding'] = encoding
    return response
Example #15
0
 def test_has_processors(self):
     asset = build_asset(self.environment, 'source.js')
     self.assertIsInstance(asset, Asset)
Example #16
0
 def test_strips_fingerprint(self):
     path = 'source.38976434f000bf447d2dc6980894986aaf4e82d0.js'
     asset = build_asset(self.environment, path)
     self.assertEqual(asset.attributes.logical_path, 'source.js')
Example #17
0
 def test_has_no_processors(self):
     asset = build_asset(self.environment, 'source.md')
     self.assertIsInstance(asset, StaticAsset)
Example #18
0
 def test_strips_fingerprint(self):
     path = 'source.38976434f000bf447d2dc6980894986aaf4e82d0.js'
     asset = build_asset(self.environment, path)
     self.assertEqual(asset.attributes.logical_path, 'source.js')
Example #19
0
 def test_has_no_processors(self):
     asset = build_asset(self.environment, 'source.md')
     self.assertIsInstance(asset, StaticAsset)
Example #20
0
 def test_has_processors(self):
     asset = build_asset(self.environment, 'source.js')
     self.assertIsInstance(asset, Asset)