Sha256: d05a72f215d0540fd5063ab2235d29d0b52e3a4a7bbf37228502a16b9a062b99

Contents?: true

Size: 1.69 KB

Versions: 6

Compression:

Stored size: 1.69 KB

Contents

require 'sprockets'

module Jax
  class DirectiveProcessor < Sprockets::DirectiveProcessor
    def evaluate(context, locals, &block)
      # this is necessary because we don't *want* to handle shaders here,
      # we want to handle them in Jax::Shader instead.
      begin
        path = context.resolve(context.logical_path).to_s
        if path =~ /\.glsl$/
          data
        else
          super
        end
      rescue Sprockets::FileNotFound # not sure why this can happen
        super
      end
    end
    
    def depend_on_all_files_in(path)
      context.depend_on path
      Dir.glob(File.join path, "**/*") do |full_path|
        context.depend_on full_path
      end
    end
    
    def process_require_everything_matching_directive(subpath)
      # depend on any base subpath directories that may exist
      # this should pick up any new shaders as they are added to app
      context.environment.paths.each do |base_path|
        path = File.join base_path, subpath
        depend_on_all_files_in path if File.directory? path
      end
      
      files = []
      # context.environment.each_logical_path do |path|
      context.environment.each_file do |path|
        # skip all.js and skip manifest.yml
        path = path.to_s
        next if path == self.file || path =~ /\.yml$/
        attrs = context.environment.attributes_for(path)
        logical_path = attrs.logical_path
        if logical_path[/^#{Regexp::escape subpath}/]
          # skip if logical path has already been processed
          next if files.include?(logical_path)
          files << logical_path
          path = context.resolve(logical_path).to_s
          process_require_directive path
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jax-2.0.5 lib/jax/directive_processor.rb
jax-2.0.4 lib/jax/directive_processor.rb
jax-2.0.3 lib/jax/directive_processor.rb
jax-2.0.2 lib/jax/directive_processor.rb
jax-2.0.1 lib/jax/directive_processor.rb
jax-2.0.0 lib/jax/directive_processor.rb