diff --git a/org-cv-utils.el b/org-cv-utils.el new file mode 100644 index 0000000..7a972a6 --- /dev/null +++ b/org-cv-utils.el @@ -0,0 +1,58 @@ +;;; org-cv-utils.el --- Common utility functions for CV exporters -*- lexical-binding: t; -*- + +;; Copyright (C) 2018 Free Software Foundation, Inc. + +;; Author: Oscar Najera +;; Keywords: org, wp, tex + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: +;; +;; This library implements some utility functions + +;;; Code: +(require 'org) + +(defun org-cv-utils-org-timestamp-to-shortdate (date_str) +"Format orgmode timestamp DATE_STR into a short form date. +Other strings are just returned unmodified + +e.g. <2002-08-12 Mon> => Aug 2012 +today => today" + (if (string-match (org-re-timestamp 'active) date_str) + (let* ((abbreviate 't) + (dte (org-parse-time-string date_str)) + (month (nth 4 dte)) + (year (nth 5 dte))) ;;'(02 07 2015))) + (concat + (calendar-month-name month abbreviate) " " (number-to-string year))) + date_str)) + +(defun org-cv-utils--format-time-window (from-date to-date) +"Join date strings in a time window. +FROM-DATE -- TO-DATE +in case TO-DATE is nil return Present" + (concat + (org-cv-utils-org-timestamp-to-shortdate from-date) + " -- " + (if (not to-date) "Present" + (org-cv-utils-org-timestamp-to-shortdate to-date)))) + +(provide 'org-cv-utils) +;;; org-cv-utils ends here diff --git a/ox-altacv.el b/ox-altacv.el index 59653e7..4d890ba 100644 --- a/ox-altacv.el +++ b/ox-altacv.el @@ -30,6 +30,7 @@ ;;; Code: (require 'cl-lib) (require 'ox-latex) +(require 'org-cv-utils) ;; Install a default set-up for altacv export. (unless (assoc "altacv" org-latex-classes) @@ -188,18 +189,6 @@ holding export options." "\\end{document}"))) -(defun org-altacv-timestamp-to-shortdate (date_str) - "Format orgmode timestamp DATE_STR into a short form date. - -e.g. <2002-08-12 Mon> => Aug 2012" - (let* ((abbreviate 't) - (dte (org-parse-time-string date_str)) - (month (nth 4 dte)) - (year (nth 5 dte)));;'(02 07 2015))) - (concat (calendar-month-name month abbreviate) - " " - (number-to-string year)))) - (defun org-altacv--format-cventry (headline contents info) "Format HEADLINE as as cventry. CONTENTS holds the contents of the headline. INFO is a plist used @@ -209,15 +198,11 @@ as a communication channel." (to-date (org-element-property :TO headline)) (employer (org-element-property :EMPLOYER headline)) (location (or (org-element-property :LOCATION headline) "")) - (divider (if (org-export-last-sibling-p headline info) "" "\\divider"))) + (divider (if (org-export-last-sibling-p headline info) "\n" "\\divider"))) (format "\n\\cvevent{%s}{%s}{%s}{%s}%s\n%s" title employer - (concat (org-altacv-timestamp-to-shortdate from-date) - " -- " - (if (not to-date) - "Present" - (org-moderncv-timestamp-to-shortdate to-date))) + (org-cv-utils--format-time-window from-date to-date) location contents divider))) diff --git a/ox-hugocv.el b/ox-hugocv.el index 11d47d9..492c5d9 100644 --- a/ox-hugocv.el +++ b/ox-hugocv.el @@ -29,6 +29,7 @@ ;;; Code: (require 'ox-hugo) +(require 'org-cv-utils) ;;; User-Configurable Variables @@ -54,17 +55,6 @@ :translate-alist '((headline . org-hugocv-headline) (inner-template . org-hugocv-inner-template))) -(defun org-hugocv-timestamp-to-shortdate (date_str) - "Format orgmode timestamp DATE_STR into a short form date. - -e.g. <2002-08-12 Mon> => Aug 2012" - (let* ((abbreviate 't) - (dte (org-parse-time-string date_str)) - (month (nth 4 dte)) - (year (nth 5 dte)));;'(02 07 2015))) - (concat (calendar-month-name month abbreviate) - " " -(number-to-string year)))) (defun org-hugocv--format-cventry (headline contents info) "Format HEADLINE as as cventry. @@ -90,11 +80,7 @@ as a communication channel." (concat (make-string (+ loffset level) ?#) " " title) employer location - (concat (org-hugocv-timestamp-to-shortdate from-date) - " -- " - (if (not to-date) - "Present" - (org-moderncv-timestamp-to-shortdate to-date))) + (org-cv-utils--format-time-window from-date to-date) contents))) diff --git a/ox-moderncv.el b/ox-moderncv.el index 43533b4..9115beb 100644 --- a/ox-moderncv.el +++ b/ox-moderncv.el @@ -30,6 +30,7 @@ ;;; Code: (require 'cl-lib) (require 'ox-latex) +(require 'org-cv-utils) ;; Install a default set-up for moderncv export. (unless (assoc "moderncv" org-latex-classes) @@ -178,18 +179,6 @@ holding export options." "\\end{document}"))) -(defun org-moderncv-timestamp-to-shortdate (date_str) - "Format orgmode timestamp DATE_STR into a short form date. - -e.g. <2002-08-12 Mon> => Aug 2012" - (let* ((abbreviate 't) - (dte (org-parse-time-string date_str)) - (month (nth 4 dte)) - (year (nth 5 dte))) ;;'(02 07 2015))) - (concat (calendar-month-name month abbreviate) - " " - (number-to-string year)))) - (defun org-moderncv--format-cventry (headline contents info) "Format HEADLINE as as cventry. CONTENTS holds the contents of the headline. INFO is a plist used @@ -201,11 +190,7 @@ as a communication channel." (location (or (org-element-property :LOCATION headline) "")) (note (or (org-element-property :NOTE headline) ""))) (format "\\cventry{\\textbf{%s}}{%s}{%s}{%s}{%s}{%s}\n" - (concat (org-moderncv-timestamp-to-shortdate from-date) - " -- " - (if (not to-date) - "Present" - (org-moderncv-timestamp-to-shortdate to-date))) + (org-cv-utils--format-time-window from-date to-date) title employer location note contents)))