Guest User

Untitled

a guest
Jun 2nd, 2012
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. Rails 3.1 Sprockets require directives - is there a way to exclude particular files?
  2. //= require jquery
  3. //= require_tree .
  4. //= stub unwanted_js
  5.  
  6. module Sprockets
  7. class DirectiveProcessor
  8. # support for: require_tree . exclude: "", "some_other"
  9. def process_require_tree_directive(path = ".", *args)
  10. if relative?(path)
  11. root = pathname.dirname.join(path).expand_path
  12.  
  13. unless (stats = stat(root)) && stats.directory?
  14. raise ArgumentError, "require_tree argument must be a directory"
  15. end
  16.  
  17. exclude = args.shift == 'exclude:' ? args.map {|arg| arg[/['"]?([^'"]+)['"]?,?/, 1]} : []
  18.  
  19. context.depend_on(root)
  20.  
  21. each_entry(root) do |pathname|
  22. if pathname.to_s == self.file or pathname.basename(pathname.extname).to_s.in?(exclude)
  23. next
  24. elsif stat(pathname).directory?
  25. context.depend_on(pathname)
  26. elsif context.asset_requirable?(pathname)
  27. context.require_asset(pathname)
  28. end
  29. end
  30. else
  31. # The path must be relative and start with a `./`.
  32. raise ArgumentError, "require_tree argument must be a relative path"
  33. end
  34. end
  35. end
  36.  
  37. end
Advertisement
Add Comment
Please, Sign In to add comment