template.esl 1.0 KB

123456789101112131415161718192021222324252627282930
  1. (lambda (s)
  2. (var path (require "path"))
  3. (var results (s.results.reduce group (object)))
  4. (return (./h ".device.library" (array
  5. (?: s.target (./h "div" (array "picking sample for " (./h "strong" s.target))) null)
  6. (./h "input" (object "oninput" oninput))
  7. (./h ".results" (.map (Object.keys results) render-group)))))
  8. (function oninput (evt) ;; WTF ?!
  9. ((./emit "library.input" s.id) evt))
  10. (function render-group (dir)
  11. (var items (get results dir))
  12. (return (./h ".result-group" (array
  13. (./h ".result-group-header" dir)
  14. (./h "ul.result-group-items"
  15. (items.map (lambda (result) (return
  16. (./h "li.result"
  17. (object "onclick" (./emit "library.pick" s.id (path.join dir result)))
  18. (./h ".result-title" (path.basename result)))))))))))
  19. (function group (groups fullpath)
  20. (var name (path.basename fullpath))
  21. (var dir (path.dirname fullpath))
  22. (if (get groups dir)
  23. ((. (get groups dir) push) name)
  24. (= (get groups dir) (array name)))
  25. (return groups)))