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