ob-sass.el 2.5 KB

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