Example #1
0
 def resolve_source(self, ctx, item):
     """Return the absolute path of the resource."""
     if not isinstance(item, six.string_types) or is_url(item):
         return item
     if item.startswith(ctx.url):
         item = item[len(ctx.url) :]
     return self.search_for_source(ctx, item)
Example #2
0
 def resolve_source(self, ctx, item):
     """Return the absolute path of the resource."""
     if not isinstance(item, six.string_types) or is_url(item):
         return item
     if item.startswith(ctx.url):
         item = item[len(ctx.url):]
     return self.search_for_source(ctx, item)
    def _merge_and_apply(self, env, output_path, force, parent_debug=None,
                         parent_filters=[], extra_filters=[],
                         disable_cache=False):

        debug = reduce(lambda x, y: x if not x is None else y,
            [self.debug, parent_debug, env.debug])
        if debug == 'merge':
            no_filters = True
        elif debug is True:
            no_filters = False
        elif debug is False:
            no_filters = False
        else:
            raise BundleError('Invalid debug value: %s' % debug)

        # Prepare contents
        resolved_contents = self.resolve_contents(env, force=True)

        if not resolved_contents:
            raise BuildError('empty bundle cannot be built')

        # Prepare filters
        filters = merge_filters(self.filters, extra_filters)
        for filter in filters:
            if isinstance(filter, LoaderBrowserFilter):
                filter.set_environment(env, bundle=self)
            else:
                filter.set_environment(env)

        # Apply input filters to all the contents. Note that we use
        # both this bundle's filters as well as those given to us by
        # the parent. We ONLY do those this for the input filters,
        # because we need them to be applied before the apply our own
        # output filters.
        combined_filters = merge_filters(filters, parent_filters)
        hunks = []
        for _, c in resolved_contents:
            if isinstance(c, Bundle):
                hunk = c._merge_and_apply(
                    env, output_path, force, debug,
                    combined_filters, disable_cache=disable_cache)
                hunks.append(hunk)
            else:
                if is_url(c):
                    hunk = UrlHunk(c)
                else:
                    hunk = FileHunk(c)
                if no_filters:
                    hunks.append(hunk)
                else:
                    hunks.append(apply_filters(
                        hunk, combined_filters, 'input',
                        env.cache, disable_cache,
                        output_path=output_path))

        # Return all source hunks as one, with output filters applied
        try:
            final = merge(hunks)
        except IOError, e:
            raise TypeError(e)
Example #4
0
    def resolve_source(self, item):
        """Return the absolute path of the resource.

        .. seealso:: :py:function:`webassets.env.Resolver:resolve_source`
        """
        if not isinstance(item, six.string_types) or is_url(item):
            return item
        if item.startswith(self.env.url):
            item = item[len(self.env.url):]
        return self.search_for_source(item)
Example #5
0
 def find_recent_most_timestamp(cls, bundle, env):
     # Recurse through the bundle hierarchy. Check the timestamp of all
     # the bundle source files, as well as any additional
     # dependencies that we are supposed to watch.
     most_recent = None
     for filename in get_all_bundle_files(bundle, env):
         if is_url(filename):
             continue
         timestamp = cls.get_timestamp(filename)
         if most_recent is None or timestamp > most_recent:
             most_recent = timestamp
     return most_recent
Example #6
0
 def find_recent_most_timestamp(cls, bundle, env):
     # Recurse through the bundle hierarchy. Check the timestamp of all
     # the bundle source files, as well as any additional
     # dependencies that we are supposed to watch.
     most_recent = None
     for filename in get_all_bundle_files(bundle, env):
         if is_url(filename):
             continue
         timestamp = cls.get_timestamp(filename)
         if most_recent is None or timestamp > most_recent:
             most_recent = timestamp
     return most_recent