ob-sass.el 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.5
  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. (require 'ob-eval)
  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* ((result-params (split-string (or (cdr (assoc :results params)) "")))
  38. (file (cdr (assoc :file params)))
  39. (out-file (or file (org-babel-temp-file "sass-out-")))
  40. (cmdline (cdr (assoc :cmdline params)))
  41. (in-file (org-babel-temp-file "sass-in-"))
  42. (cmd (concat "sass " (or cmdline "")
  43. " " (org-babel-process-file-name in-file)
  44. " " (org-babel-process-file-name out-file))))
  45. (with-temp-file in-file
  46. (insert (org-babel-expand-body:generic body params)))
  47. (org-babel-eval cmd "")
  48. (if file
  49. nil ;; signal that output has already been written to file
  50. (with-temp-buffer (insert-file-contents out-file) (buffer-string)))))
  51. (defun org-babel-prep-session:sass (session params)
  52. "Raise an error because sass does not support sessions."
  53. (error "Sass does not support sessions"))
  54. (provide 'ob-sass)
  55. ;; arch-tag: 2954b169-eef4-45ce-a8e5-3e619f0f07ac
  56. ;;; ob-sass.el ends here