ob-sass.el 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ;;; ob-sass.el --- Babel Functions for the Sass CSS generation language -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2009-2022 Free Software Foundation, Inc.
  3. ;; Author: Eric Schulte
  4. ;; Keywords: literate programming, reproducible research
  5. ;; URL: https://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 https://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 :: https://github.com/nex3/haml/blob/master/extra/sass-mode.el
  29. ;;; Code:
  30. (require 'org-macs)
  31. (org-assert-version)
  32. (require 'ob)
  33. (defvar org-babel-default-header-args:sass '())
  34. (defun org-babel-execute:sass (body params)
  35. "Execute a block of Sass code with Babel.
  36. This function is called by `org-babel-execute-src-block'."
  37. (let* ((file (cdr (assq :file params)))
  38. (out-file (or file (org-babel-temp-file "sass-out-")))
  39. (cmdline (cdr (assq :cmdline params)))
  40. (in-file (org-babel-temp-file "sass-in-"))
  41. (cmd (concat "sass " (or cmdline "")
  42. " " (org-babel-process-file-name in-file)
  43. " " (org-babel-process-file-name out-file))))
  44. (with-temp-file in-file
  45. (insert (org-babel-expand-body:generic body params)))
  46. (org-babel-eval cmd "")
  47. (if file
  48. nil ;; signal that output has already been written to file
  49. (with-temp-buffer (insert-file-contents out-file) (buffer-string)))))
  50. (defun org-babel-prep-session:sass (_session _params)
  51. "Raise an error because sass does not support sessions."
  52. (error "Sass does not support sessions"))
  53. (provide 'ob-sass)
  54. ;;; ob-sass.el ends here