ob-sass.el 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ;;; ob-sass.el --- Babel Functions for the Sass CSS generation language -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2009-2018 Free Software Foundation, Inc.
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; For more information on sass see http://sass-lang.com/
  19. ;;
  20. ;; This accepts a 'file' header argument which is the target of the
  21. ;; compiled sass. The default output type for sass evaluation is
  22. ;; either file (if a 'file' header argument was given) or scalar if no
  23. ;; such header argument was supplied.
  24. ;;
  25. ;; A 'cmdline' header argument can be supplied to pass arguments to
  26. ;; the sass command line.
  27. ;;; Requirements:
  28. ;; - sass-mode :: http://github.com/nex3/haml/blob/master/extra/sass-mode.el
  29. ;;; Code:
  30. (require 'ob)
  31. (defvar org-babel-default-header-args:sass '())
  32. (defun org-babel-execute:sass (body params)
  33. "Execute a block of Sass code with Babel.
  34. This function is called by `org-babel-execute-src-block'."
  35. (let* ((file (cdr (assq :file params)))
  36. (out-file (or file (org-babel-temp-file "sass-out-")))
  37. (cmdline (cdr (assq :cmdline params)))
  38. (in-file (org-babel-temp-file "sass-in-"))
  39. (cmd (concat "sass " (or cmdline "")
  40. " " (org-babel-process-file-name in-file)
  41. " " (org-babel-process-file-name out-file))))
  42. (with-temp-file in-file
  43. (insert (org-babel-expand-body:generic body params)))
  44. (org-babel-eval cmd "")
  45. (if file
  46. nil ;; signal that output has already been written to file
  47. (with-temp-buffer (insert-file-contents out-file) (buffer-string)))))
  48. (defun org-babel-prep-session:sass (_session _params)
  49. "Raise an error because sass does not support sessions."
  50. (error "Sass does not support sessions"))
  51. (provide 'ob-sass)
  52. ;;; ob-sass.el ends here