ob-sass.el 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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: 0.01
  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-expand-body:sass (body params &optional processed-params)
  34. "Expand BODY according to PARAMS, return the expanded body." body)
  35. (defun org-babel-execute:sass (body params)
  36. "Execute a block of Sass code with org-babel. This function is
  37. called by `org-babel-execute-src-block'."
  38. (message "executing Sass source code block")
  39. (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
  40. (file (cdr (assoc :file params)))
  41. (out-file (or file (make-temp-file "org-babel-sass-out")))
  42. (cmdline (cdr (assoc :cmdline params)))
  43. (in-file (make-temp-file "org-babel-sass-in"))
  44. (cmd (concat "sass " (or cmdline "") in-file " " out-file)))
  45. (with-temp-file in-file
  46. (insert (org-babel-expand-body:sass body params))) (shell-command cmd)
  47. (or file (with-temp-buffer (insert-file-contents out-file) (buffer-string)))))
  48. (defun org-babel-prep-session:sass (session params)
  49. "This function does nothing as sass does not support sessions."
  50. (error "Sass does not support sessions"))
  51. (provide 'ob-sass)
  52. ;; arch-tag: 2954b169-eef4-45ce-a8e5-3e619f0f07ac
  53. ;;; ob-sass.el ends here