Sha256: e2fe7214c92ed1e12ce85dcc79a6d70a82597e262b732b2af15ae96fb6d64340

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

module Assette
  module PostProcessor
    extend self
    POST_PROCESSORS = Hash.new {|h,k| h[k] = []}
    
    def s
      POST_PROCESSORS
    end
    
    class Base
      
      def initialize(file, args={})
        @file = file
        @str = file.code; @args = args
      end
      
      def should_process?
        true
      end
      
      def processor
        raise Exception, "You must implement the processor method for #{self.class.inspect} (you can use the @str)"
      end
      
      def process
        return @str unless should_process?
        
        processor
      end
      
      class << self
        def inherited subclass
          return if subclass == Assette::PostProcessor::Base || subclass.inspect =~ /#<Class/
          
          if outputs
            Assette::PostProcessor::POST_PROCESSORS[outputs] |= [subclass]
          end
        end
        
        def outputs
          
        end
        
        def set_outputs val
          raise ArgumentError, 'must set outputs to a symbol' unless val.is_a?(Symbol)
          
          instance_eval <<-RUBY
          def outputs
            #{val.inspect}
          end
          RUBY
          val
        end
      end
    end
    
  end
  
  
  
  def self.PostProcessor(type)
    c = Class.new(PostProcessor::Base)
    c.set_outputs(type)
    c
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
assette-0.1.4 lib/assette/post_processor.rb
assette-0.1.3 lib/assette/post_processor.rb
assette-0.1.2 lib/assette/post_processor.rb
assette-0.1.1 lib/assette/post_processor.rb
assette-0.1.0 lib/assette/post_processor.rb