1. Exaos Lee
  2. o-blog


o-blog / o-blog-grid.el

;;; o-blog-grid.el --- Publish grid in o-blog

;; Copyright © 2012 Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>

;; Author: Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
;; Keywords: emacs, 
;; Created: 2012-01-23
;; Last changed: 2012-02-10 23:38:16
;; Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/

;; This file is NOT part of GNU Emacs.

;;; Commentary:

;;; Code:

  (require 'org nil t))

(defcustom o-blog-grid-header
  "<div class=\"row %s\"><div class=\"%s\">"
  "HTML fragment header to be used when publishing a grid using
`o-blog-publish-grid' using `format' with grid options as
parameter. The grid should be closed with `o-blog-grid-footer'."
  :type 'string
  :group 'o-blog)

(defcustom o-blog-grid-footer
  "HTML fragment footer to be used when publishing a grid using
`o-blog-publish-grid' as it. This closes `o-blog-grid-header'."
  :type 'string
  :group 'o-blog)

(defcustom o-blog-grid-column
  "</div><div class=\"%s\">"
  "HTML middle fragment to be used when publishing a grid. This
string is used for next column in `o-blog-publish-grid' using
`format' with column configuration as parameter."
  :type 'string
  :group 'o-blog)

(defun o-blog-grig-compute-args (a1 a2)
  "Compute A1 and A2."
  (let* ((i2c (lambda (x)
		(let ((x (if x (string-to-int x) 0)))
		   ((= 0 x) "")
		   ((< 0 x) (format "span%d" x))
		   ((> 0 x) (format "offset%d" (- x))))))))
    (format "%s %s"
	    (funcall i2c a1)
	    (funcall i2c a2))))

(defun o-blog-publish-grid ()
  "Publish a grid in HTML mode.

The default replacement text could be changed using variables
`o-blog-grid-header', `o-blog-grid-footer' and
	(goto-char (point-min))
	(let ((case-fold-search t))
	  (while (re-search-forward
		  "^#\\+BEGIN_O_BLOG_ROW:?[ \t]+\\(.*\\)"
		  nil t)
	    (goto-char (point-at-bol))
	    (let* ((args (when (stringp (match-string 1))
			   (split-string (match-string-no-properties 1)))))
	       (format o-blog-grid-header
		       (or (nth 2 args) "")
			      (nth 0 args)
			      (nth 1 args)))
	      (delete-region (point) (point-at-eol))

		    (re-search-forward "^#\\+END_O_BLOG_ROW" nil t)
		  (error "#+END_O_BLOG_ROW not found in %s@%s." (buffer-file-name)
		(delete-region (point) (point-at-eol))
		(setq end (point)))

		(while (re-search-forward
			"^#\\+O_BLOG_ROW_COLUMN:?[ \t]+\\(-?[0-9]+\\)\\([ \t]+\\(-?[0-9]+\\)\\)?"
			nil t)

		  (goto-char (point-at-bol))

		   (format o-blog-grid-column
			    (match-string 1)
			    (match-string 2)))

		  (delete-region (point) (point-at-eol)))))


 '("og" "#+begin_o_blog_row ?\n\n#+end_o_blog_row"))
 '("ogr" "#+o_blog_row_column ?\n\n"))

(add-hook 'o-blog-html-plugins-hook 'o-blog-publish-grid)

(provide 'o-blog-grid)