Guest User

Untitled

a guest
Jan 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. namespace 'net.hashnote.path', (exports) ->
  2. exports.root = root = (pattern) ->
  3. ###
  4. Get root path of script
  5.  
  6. Args:
  7. pattern - a pattern of script name written in <script> src tag
  8.  
  9. Example:
  10. alert(net.hashnote.path.root('jquery(\.min)?\.js'));
  11. ###
  12. pattern = new RegExp "(.*)#{pattern}$"
  13. root = undefined
  14. $('script').each (a, tag) ->
  15. match = $(tag).get(0).src.match pattern
  16. if match?
  17. root = match[1]
  18. # remove trailing slush
  19. return root[0..root.length-1]
  20. return root
  21. exports.abspath = abspath = (path, root, prefix='~/') ->
  22. ###
  23. Convert relativepath to absolutepath
  24.  
  25. Args:
  26. path - a relativepath
  27. root - script root path, use ``net.hashnote.path.root`` for find it
  28. prefix - a prefix string. default is '~/'
  29. ###
  30. if path.lastIndexOf('~/', 0) is 0
  31. path = "#{root}/#{path[2..path.length]}"
  32. return path
Add Comment
Please, Sign In to add comment