Guest User

Untitled

a guest
Dec 14th, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. module Rake::Pipeline::Web::Filters
  2. class InjectionMatcher < Rake::Pipeline::Matcher
  3. def target=(value)
  4. @target = value
  5. end
  6.  
  7. def output_files
  8. super.select { |f| f.path == @target }
  9. end
  10.  
  11. def eligible_input_files
  12. input_files.select do |file|
  13. file.path =~ @pattern || file.path == @target
  14. end
  15. end
  16. end
  17.  
  18. class InsertScriptTagFilter < Rake::Pipeline::Filter
  19. def initialize(target, &block)
  20. block = proc { target }
  21. super &block
  22. end
  23.  
  24. def generate_output(inputs, output)
  25. inputs.each do |input|
  26. output.write input.read
  27. end
  28. end
  29. end
  30.  
  31. module PipelineHelpers
  32. def insert_script_tag(glob, target)
  33. matcher = pipeline.copy Rake::Pipeline::Web::Filters::InjectionMatcher do
  34. filter Rake::Pipeline::Web::Filters::InsertScriptTagFilter, target
  35. end
  36.  
  37. matcher.glob = glob
  38. matcher.target = target
  39. pipeline.add_filter matcher
  40. matcher
  41. end
  42. end
  43. end
Add Comment
Please, Sign In to add comment