You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problems with this use case: all sprites have to be known as pipeline load time.
Load time is not the same as build time (using the preview server).
Here's another solution: use a directory matcher to iterate over directories
and provide their contents as inputs to a filter.
directory"images/sprites"dospriteend
I think this is a valid use case. The use case itself is abstract and useful in other scenarios.
I've included my rough implementation of this in the issue to see if there is interest in this
functionality.
I'd change this so that the DirectoryFilter can also be used in other pipelines. If the parent
pipeline is a DirectoryMatcher then do the custom behavior. Else call super.
moduleRake::Pipeline::Web::FiltersclassDirectoryMatcher < Rake::Pipeline::Matcher# Take files matching the directory glob from the set of all files.# Return an array of array where each element in the array is# the contents of an input directorydefeligible_input_filesdirectory_files=input_files.selectdo |file|
file.path.include?@globenddirectory_files.inject({})do |memo,input|
directory_name=File.dirname(input.path)memo[directory_name] ||= []memo[directory_name] << inputmemoend.valuesendendclassDirectoryFilter < Rake::Pipeline::Filterdefinitialize(*args, &block)block ||= proc{ |input| File.basenameinput}super &blockend# We are working with an array of arrays to act accordinglydefinput_files=(files)@input_files=files.mapdo |directory|
directory.map{ |f| f.with_encoding(encoding)}endend# Outputs look like this:# # {# generated_output_name => directory_contents,# generated_output_name => directory_contents.# }## This ensures the filter's `generate_output` method is called# once for each directorydefoutputshash={}input_files.eachdo |directory|
directory_name=File.dirnamedirectory.first.pathpath=output_name_generator.call(*directory_name)output_file=file_wrapper_class.new(output_root,path,encoding)hash[output_file]=directoryendhashenddefoutput_filesoutputs.keysend# Just like normaldefgenerate_output(inputs,output)endendmodulePipelineHelpersdefdirectory(pattern, &block)matcher=pipeline.copy(DirectoryMatcher, &block)matcher.glob=patternpipeline.add_filtermatchermatcherenddefdirectory_filter(*args, &block)filterRake::Pipeline::Web::Filters::DirectoryFilter, *args, &blockendendend
The text was updated successfully, but these errors were encountered:
Here's a use case:
/sprites contains many directories. Each directory represents one sprite.
How can we do this? Here's one possible solution:
Problems with this use case: all sprites have to be known as pipeline load time.
Load time is not the same as build time (using the preview server).
Here's another solution: use a directory matcher to iterate over directories
and provide their contents as inputs to a filter.
I think this is a valid use case. The use case itself is abstract and useful in other scenarios.
I've included my rough implementation of this in the issue to see if there is interest in this
functionality.
I'd change this so that the DirectoryFilter can also be used in other pipelines. If the parent
pipeline is a
DirectoryMatcher
then do the custom behavior. Else callsuper
.The text was updated successfully, but these errors were encountered: