Created
January 18, 2017 06:47
-
-
Save FrancisMurillo/3fcc4452ce9714f2d3a6f81ac0cd7ccd to your computer and use it in GitHub Desktop.
OrgTbl YAML Export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun fn/orgtbl-to-yaml (table params) | |
"Convert an org table to yaml." | |
(lexical-let ((headers | |
(mapcar | |
(lambda (header) | |
(replace-regexp-in-string | |
" " "-" | |
(downcase header))) | |
(car table))) | |
(zip | |
(lambda (xs ys) | |
(lexical-let ((ms xs) | |
(ns ys) | |
(zs nil)) | |
(while (or (car ms) (car ns)) | |
(push (cons (car ms) (car ns)) zs) | |
(setq ms (cdr ms) | |
ns (cdr ns))) | |
(reverse zs))))) | |
(orgtbl-to-generic | |
table | |
(org-combine-plists | |
(list | |
:skip 1 ;; Skip header | |
:lfmt | |
(lambda (values) | |
(concat | |
"- " | |
(string-join | |
(mapcar | |
(lambda (pair) | |
(lexical-let ((header (car pair)) | |
(value (cdr pair))) | |
(format "%s: \"%s\"" header value))) | |
(funcall zip headers values)) | |
"\n ")))) | |
params)))) | |
(defun fn/org-jekyll-blogger-export-and-publish-table () | |
"Export a table and publish the file accordingly." | |
(interactive) | |
(if (not (org-at-table-p)) | |
(if (not (called-interactively-p 'interactive)) | |
(message "No table at point to publish.") | |
(error "Point is not at a table")) | |
(org-table-export) | |
(lexical-let ((export-file (org-entry-get (point) "TABLE_EXPORT_FILE" t))) | |
(if (not export-file) | |
(message "No TABLE_EXPORT_FILE property") | |
(lexical-let ((export-buffer (find-file-noselect export-file))) | |
(with-current-buffer export-buffer | |
(org-publish-current-file)) | |
(message "Table published.")))))) | |
(defun fn/org-jekyll-blogger-auto-publish-table-on-save () | |
"Auto export and publish table on save." | |
(interactive) | |
(add-hook 'after-save-hook #'fn/org-jekyll-blogger-export-and-publish-table t t)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment