Browse Source

More renaming of files, as well as renaming of functions and variables
inside the files.

tj 8 years ago
parent
commit
9f828dd9eb

logic/bugpile-logic.el → db/bugpile-db.el


+ 0 - 29
iorg/lisp/iorg-controller.el

@@ -1,29 +0,0 @@
-;;; iorg-controller.el -- generic reusable and use case
-;;; independent controller functions for the iOrg framework
-
-(defun iorg-static-export-handler (httpcon file)
-  "Exports an Org file to static html"
-  (elnode-send-file httpcon (iorg--org-to-html file 'STATIC)))
-
-
-(defun iorg--org-to-html (org-file &optional STATIC)
-  "Export ORG-FILE to html and return the expanded filename. If STATIC is non nil, export to static html, otherwise use the iOrg exporter"
-  (if (not (file-exists-p (expand-file-name org-file simple-dir)))
-      (error "File doesn't exist")
-    (save-window-excursion
-      (with-current-buffer
-          (find-file (expand-file-name org-file simple-dir))
-        (and
-         (org-check-for-org-mode)
-         (org-export-to-file
-          (if STATIC 'e-html 'iorg) 
-          (expand-file-name
-           (concat
-            (file-name-sans-extension
-             (file-name-nondirectory org-file))
-            ".html") simple-dir )))))))
-
-
-
-
-(provide 'iorg-controller)

+ 6 - 0
iorg/lisp/iorg-db.el

@@ -0,0 +1,6 @@
+;;; iorg-db --- functions for abstracting the process of updating Org-mode files
+
+
+
+
+(provide 'iorg-db)

+ 37 - 37
iorg/lisp/iorg-html.el

@@ -1,44 +1,43 @@
-;;; org-iorg-b-export -- basic back-end for exporting Org files to interactive HTML
+;;; iorg-html -- basic back-end for exporting Org files to interactive HTML
 
 (require 'org-export)
 (require 'org-element)
 (require 'org-e-html)
 (require 'util)
-;; (require 'org-iorg)
 
 ;;;; Define derived backend
 
-;; Enables e.g. (org-export-to-file 'iorg ...)
-(org-export-define-derived-backend iorg e-html
-  :translate-alist ((headline . org-iorg-b-headline)
-                    (section . org-iorg-b-section)
+;; Enables e.g. (org-export-to-file 'iorg-html ...)
+(org-export-define-derived-backend iorg-html e-html
+  :translate-alist ((headline . iorg-html-headline)
+                    (section . iorg-html-section)
                     (property-drawer . nil)
-                    ;;(item . org-iorg-b-item)
-                    ;; (paragraph . org-iorg-b-paragraph)
-                    ;; (plain-list . org-iorg-b-plain-list)
-                    ;; (property-drawer . org-iorg-b-property-drawer)
+                    ;;(item . iorg-html-item)
+                    ;; (paragraph . iorg-html-paragraph)
+                    ;; (plain-list . iorg-html-plain-list)
+                    ;; (property-drawer . iorg-html-property-drawer)
                     ))
 
 
 ;;;; Customisation group
 
-(defgroup org-iorg-b-export nil
+(defgroup iorg-html nil
   "Options for exporting Org files to dynamic html."
   :tag "Org iOrg Export"
   :group 'org-iorg)
 
 ;;;; Customisation variables
 
-(defcustom org-iorg-b-property-key-prefix-plist
+(defcustom iorg-html-property-key-prefix-plist
   '(:export ("html" "bugpile") :noexport  nil) 
   "Alist with a list of prefix strings in the cdr that are used to identify those headline properties that will be made editable by the iOrg exporter."
-  :group 'org-iorg-b-export
+  :group 'iorg-html
   :type 'plist)
  
 
 ;;;; Variables
 
-(defvar org-iorg-b-property-prefix-regexp "^[^-]+"
+(defvar iorg-html-property-prefix-regexp "^[^-]+"
   "Regexp that matches any prefix of an Org headline property key.")
 
 
@@ -46,7 +45,7 @@
 
 ;; OBLSOLETE not needed anymore
 ;; ;; Headline customization variables
-;; (defcustom org-iorg-b-format-headline-function nil
+;; (defcustom iorg-html-format-headline-function nil
 ;;   "Function to format headline text.
 
 ;; This function will be called with 5 arguments:
@@ -69,12 +68,12 @@
 ;;             \(format \"\\\\framebox{\\\\#%c} \" priority))
 ;; 	  text
 ;; 	  \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags))))"
-;;   :group 'org-iorg-b-export
+;;   :group 'iorg-html
 ;;   :type 'function)
 
 
 ;; Main headline export function
-(defun org-iorg-b-headline (headline contents info)
+(defun iorg-html-headline (headline contents info)
   "Transcode element HEADLINE into HTML syntax.
 CONTENTS is the contents of the headline.  INFO is a plist used
 as a communication channel."
@@ -99,11 +98,11 @@ as a communication channel."
                                  (mapconcat 'number-to-string section-number "-")))
            ;; text
            (text (org-export-data (org-element-property :title headline) info))
-           (text-formatted (org-iorg-b--headline-text text))
+           (text-formatted (iorg-html--headline-text text))
            ;; TODO's
-           (todo-formatted (org-iorg-b--headline-todo headline info))
+           (todo-formatted (iorg-html--headline-todo headline info))
            ;; TAG's
-           (tags-formatted (org-iorg-b--headline-tags headline info))
+           (tags-formatted (iorg-html--headline-tags headline info))
            ;; ID's
            (ids (remove 'nil
                         (list (org-element-property :custom-id headline)
@@ -172,7 +171,7 @@ as a communication channel."
 
 
 ;;; Helper Functions
-(defun org-iorg-b--read-from-input-file (file beg end)
+(defun iorg-html--read-from-input-file (file beg end)
   "Return buffer substring between characters BEG and END from Org input file FILE, given as absolute file-name."
   (if (not (and
             (file-exists-p file)
@@ -186,17 +185,17 @@ as a communication channel."
           (buffer-substring-no-properties beg end))))))
 
 
-(defun org-iorg-b--get-org-input (element info &optional property-drawer)
+(defun iorg-html--get-org-input (element info &optional property-drawer)
   "Return content of input Org file"
   (let* ((input-file (plist-get info :input-file))
          (beg (or (and property-drawer
                        (org-element-property :end property-drawer))
                   (org-element-property :begin element)))
          (end (org-element-property :end element)))
-    (org-iorg-b--read-from-input-file input-file beg end)))
+    (iorg-html--read-from-input-file input-file beg end)))
 
 
-(defun org-iorg-b--generate-property-key-regexp (prefix)
+(defun iorg-html--generate-property-key-regexp (prefix)
   "Generate a regexp that matches all Org headline properties whose keys begin with PREFIX followed by a dash '-'."
   (if (not (non-empty-string-p prefix))
       (error "PREFIX must be a non-empty string")
@@ -204,7 +203,7 @@ as a communication channel."
   
 
 ;;; Transcode Helpers
-(defun org-iorg-b--headline-todo (headline info)
+(defun iorg-html--headline-todo (headline info)
   "Wrap headline todo's in html select-box, reading values from the HEADLINE and INFO arguments"
   (let* ((todo (and (plist-get info :with-todo-keywords)
                     (let ((todo (org-element-property :todo-keyword headline)))
@@ -231,7 +230,7 @@ as a communication channel."
                       "</select>"
                       "</span>")))))
 
-(defun org-iorg-b--headline-tags (headline info)
+(defun iorg-html--headline-tags (headline info)
   "Wrap headline tags in html text-field, reading values from the HEADLINE and INFO arguments"
   (let* ((tags (and (plist-get info :with-tags)
                     (org-export-get-tags headline info))))
@@ -251,7 +250,7 @@ as a communication channel."
 
 
 
-(defun org-iorg-b--headline-text (text)
+(defun iorg-html--headline-text (text)
   "Wrap headline TEXT in html text-field."
   (when text
     (format "%s%s%s"
@@ -267,7 +266,7 @@ as a communication channel."
 
 ;;; Section
 
-(defun org-iorg-b-section (section contents info &optional key-prefix-list)
+(defun iorg-html-section (section contents info &optional key-prefix-list)
   "Transcode element HEADLINE into HTML syntax.
 CONTENTS is the contents of the headline.  INFO is a plist used
 as a communication channel.KEY-PREFIX-LIST
@@ -285,7 +284,7 @@ is an optional list of prefix strings.
          ;; Get the prefixes that flag a property for export
          (prefix-list
           (or key-prefix-list
-              (plist-get org-iorg-b-property-key-prefix-plist :export)))
+              (plist-get iorg-html-property-key-prefix-plist :export)))
          ;; Generate a set of all property-key prefixes in the drawer
          (prop-drawer-prefix-list
           (and
@@ -295,7 +294,7 @@ is an optional list of prefix strings.
              (lambda (x)
                (progn
                  (string-match
-                  org-iorg-b-property-prefix-regexp (car x))
+                  iorg-html-property-prefix-regexp (car x))
                  (match-string 0 (car x))))
              properties))))
          ;; Are there Org properties that need to be exported?
@@ -328,7 +327,7 @@ is an optional list of prefix strings.
                     (if (member
                          (progn
                            (string-match
-                            org-iorg-b-property-prefix-regexp
+                            iorg-html-property-prefix-regexp
                             (car x))
                            (match-string 0 (car x)))
                          prefix-list)
@@ -351,21 +350,21 @@ is an optional list of prefix strings.
                (concat
                 "<textarea class=\"textarea\" name=\"simple-section\""
                 "cols=\"80\" rows=\"35\">%s</textarea>")
-               (org-iorg-b--get-org-input
+               (iorg-html--get-org-input
                 section info prop-drawer))))))
 
 
 
 ;; ;;; Property drawer
 
-;; (defun org-iorg-b-property-drawer
+;; (defun iorg-html-property-drawer
 ;;   (property-drawer contents info)
 ;;   "Transcode element PROPERTY-DRAWER into HTML syntax. CONTENTS is the contents of the paragraph. INFO is a plist used as a communication channel."
 ;;     (format "%s" ""))
  
 ;; ;;; Paragraph
 
-;; (defun org-iorg-b-paragraph (paragraph contents info)
+;; (defun iorg-html-paragraph (paragraph contents info)
 ;;   "Transcode element PARAGRAPH into HTML syntax.
 ;; CONTENTS is the contents of the paragraph.  INFO is a plist used
 ;; as a communication channel."
@@ -417,7 +416,7 @@ is an optional list of prefix strings.
  
 ;; ;;; Plain List
 
-;; (defun org-iorg-b-plain-list (plain-list contents info)
+;; (defun iorg-html-plain-list (plain-list contents info)
 ;;   "Transcode element PLAIN-LIST into HTML syntax.
 ;; CONTENTS is the contents of the plain-list.  INFO is a plist used
 ;; as a communication channel."
@@ -441,7 +440,7 @@ is an optional list of prefix strings.
 ;;                     contents)
 ;;           contents)))))
 
-;; (defun org-iorg-b-item (item contents info)
+;; (defun iorg-html-item (item contents info)
 ;;   "Transcode element ITEM into HTML syntax.
 ;; CONTENTS is the contents of the ITEM.  INFO is a plist used as
 ;; a communication channel."
@@ -481,7 +480,7 @@ is an optional list of prefix strings.
  
 ;;; Exporting function
 
-(defun org-iorg-b-export-to-html
+(defun iorg-html-export-to-html
   (&optional subtreep visible-only body-only ext-plist pub-dir)
   "Export current buffer to a HTML file.
 
@@ -515,3 +514,4 @@ Return output file's name."
     (org-export-to-file 'iorg file subtreep visible-only body-only ext-plist)))
 
 
+(provide 'iorg-html)

+ 0 - 7
iorg/lisp/iorg-logic.el

@@ -1,7 +0,0 @@
-;;; iorg-logic.el -- generic, reusable and use case
-;;; independent logic functions for the iOrg framework
-
-
-
-
-(provide 'iorg-logic)

+ 69 - 69
iorg/lisp/iorg-projects.el

@@ -1,4 +1,4 @@
-;;; iorg.el --- A webframework based on Org-mode and Elnode
+;;; iorg-projects.el --- functions to create and manage iOrg projects
 
 ;; Programming interactive web-applications with Org-mode 
 ;; Copyright (C) 2012  Thorsten Jolitz 
@@ -80,7 +80,7 @@
 ;;;; Other stuff we need
 
 ;; remember this directory
-(setq iorg-dir
+(setq iorg-projects-dir
       (expand-file-name
        (file-name-directory
         (directory-file-name
@@ -95,7 +95,7 @@
 (declare-function org-get-todo-state "org" nil)
 
 ;;;; Variables 
-(defvar iorg-plantuml-diagram-type-repexp
+(defvar iorg-projects-plantuml-diagram-type-repexp
 (concat "<\\(soa\\|csa\\|dcm\\)>")
   "Regexp used to identify plantuml diagramtypes from the
   plantuml 'titel' line in the Org-mode source block")
@@ -114,18 +114,18 @@
 
 
 ;;;; Customization variables
-(defgroup org-iorg nil
+(defgroup iorg-projects nil
   "A webframework based on Org-mode, Elnode and dVCS."
   :tag "iOrg"
   :group 'org
   :group 'elnode)
 
-(defcustom iorg-mode-hook nil
-  "Mode hook for iOrg-mode, run after the mode was turned on."
+(defcustom iorg-projects-mode-hook nil
+  "Mode hook for iorg-projects-mode, run after the mode was turned on."
   :group 'org-iorg
   :type 'hook)
 
-(defcustom iorg-load-hook nil
+(defcustom iorg-projects-load-hook nil
   "Hook that is run after iorg.el has been loaded."
   :group 'org-iorg
   :type 'hook)
@@ -133,18 +133,18 @@
 
 ;;;; Private functions
 ;;; iOrg meta data
-(defun iorg--update-iorg-config (prop val)
+(defun iorg-projects--update-iorg-config (prop val)
   "Update property PROP with value VAL in the global iOrg configuration file."
   (org-entry-add-to-multivalued-property
-   (iorg--goto-first-entry
-    (expand-file-name "iorg-config.org" iorg-dir)) prop val))
+   (iorg-projects--goto-first-entry
+    (expand-file-name "iorg-projects-config.org" iorg-projects-dir)) prop val))
 
-(defun iorg--meta-data ()
+(defun iorg-projects--meta-data ()
   "Return a list with meta-data about the current iOrg projects,
-gathered from the iorg-config.org file."
-  (iorg--goto-first-entry (expand-file-name "iorg-config.org" iorg-dir))
+gathered from the iorg-projects-config.org file."
+  (iorg-projects--goto-first-entry (expand-file-name "iorg-projects-config.org" iorg-projects-dir))
   (let* ((proj (org-entry-get (point) "projects"))
-         (unnamed-proj (iorg--filter-multival-property proj "project[0-9]+$"))
+         (unnamed-proj (iorg-projects--filter-multival-property proj "project[0-9]+$"))
          (unnamed-max 0))
     ;; get the highest numbering of unnamed projects
     (mapc
@@ -156,7 +156,7 @@ gathered from the iorg-config.org file."
          (and (> proj-count unnamed-max)
               (setq unnamed-max proj-count))))
      unnamed-proj)
-    ;; kill iorg-config.org buffer
+    ;; kill iorg-projects-config.org buffer
     (kill-buffer (current-buffer))
     ;; build the retpurn list
     (list
@@ -164,47 +164,47 @@ gathered from the iorg-config.org file."
      (length unnamed-proj) ; number of unnamed projects
      unnamed-max))) ; highest numbering of unnamed project
        
-(defun iorg--number-of-projects ()
+(defun iorg-projects--number-of-projects ()
   "Return the total number of current iOrg projects."
-  (nth 0 (iorg--meta-data)))
+  (nth 0 (iorg-projects--meta-data)))
 
-(defun iorg--number-of-unnamed-projects ()
+(defun iorg-projects--number-of-unnamed-projects ()
   "Return the number of current unnamed iOrg projects."
-  (nth 1 (iorg--meta-data)))
+  (nth 1 (iorg-projects--meta-data)))
  
-(defun iorg--max-numbering-unnamed-projects ()
+(defun iorg-projects--max-numbering-unnamed-projects ()
   "Return the highest numbering of unnamed iOrg projects."
-  (nth 2 (iorg--meta-data)))
+  (nth 2 (iorg-projects--meta-data)))
 
 ;;; Project management
-(defun iorg--update-project-config (prop val &optional dir)
+(defun iorg-projects--update-project-config (prop val &optional dir)
   "Update the iOrg project configuration of project in present
 working directory or DIR."
   (org-entry-add-to-multivalued-property
-   (iorg--goto-first-entry
+   (iorg-projects--goto-first-entry
     (if dir
         (expand-file-name
          (concat
           (file-name-nondirectory
            (directory-file-name
-            (iorg--normalize-existing-dir-name dir))) "-config.org")
-         (iorg--normalize-existing-dir-name dir))
+            (iorg-projects--normalize-existing-dir-name dir))) "-config.org")
+         (iorg-projects--normalize-existing-dir-name dir))
       (expand-file-name
        (concat
         (file-name-nondirectory
          (directory-file-name
-          (iorg--pwd))) "-config.org")
-       (iorg--pwd)))
+          (iorg-projects--pwd))) "-config.org")
+       (iorg-projects--pwd)))
     prop val)))
 
-(defun iorg--rename-project-files (&optional name dir)
+(defun iorg-projects--rename-project-files (&optional name dir)
   "Rename all prefixed files in the present working directory or
 DIR, replacing the old prefix (taken from <<project>>-config.org)
 with `file-name-nondirectory' of the project directory."
   (let* ((proj
           (if dir
-              (iorg--normalize-existing-dir-name dir)
-            (iorg--pwd)))
+              (iorg-projects--normalize-existing-dir-name dir)
+            (iorg-projects--pwd)))
          (dir-files (directory-files proj))
          (new-prefix
           (if (and name (non-empty-string-p name))
@@ -221,26 +221,26 @@ with `file-name-nondirectory' of the project directory."
      dir-files)
     ;; replace old-prefix with new-prefix
     ;; project directory
-    (iorg--replace-filename-prefix old-prefix new-prefix proj)
+    (iorg-projects--replace-filename-prefix old-prefix new-prefix proj)
     ;; subdirectories (1st level)
     (mapc
      (lambda (x)
        (unless (string-match-p "^\\.+" x)
-         (let ((f (iorg--normalize-new-dir-name
+         (let ((f (iorg-projects--normalize-new-dir-name
                    (concat proj x))))
            (and
             (file-directory-p f)
-            (iorg--replace-filename-prefix
+            (iorg-projects--replace-filename-prefix
              old-prefix new-prefix f)))))
      dir-files)))
 
-(defun iorg--project-directory-structure-p (&optional dir)
+(defun iorg-projects--project-directory-structure-p (&optional dir)
   "Return t if present working directory or DIR confirms to the
 iOrg project directory structure, nil otherwise."
   (let* ((project-dir
           (if dir
-              (iorg--normalize-existing-dir-name dir)
-            (iorg--pwd)))
+              (iorg-projects--normalize-existing-dir-name dir)
+            (iorg-projects--pwd)))
          (dir-files (directory-files project-dir)))
     (not
      (cond
@@ -261,7 +261,7 @@ iOrg project directory structure, nil otherwise."
       ((not (member "view" dir-files)))))))
 
 ;;; Modified or new Emacs functionality
-(defmacro iorg-in-file (file &rest body)
+(defmacro iorg-projects-in-file (file &rest body)
   "Execute BODY in a buffer visiting FILE.
     If no buffer exists visiting FILE then open FILE in a new buffer."
   `(save-window-excursion
@@ -269,21 +269,21 @@ iOrg project directory structure, nil otherwise."
          (with-temp-buffer (find-file ,file) ,@body)
        (error (message "iorg: there has been an error")))))
 
-;; (iorg-in-file "/tmp/something.org" (message "in %s" (current-buffer)))
+;; (iorg-projects-in-file "/tmp/something.org" (message "in %s" (current-buffer)))
 
-(defun iorg--pwd ()
+(defun iorg-projects--pwd ()
   "Return the (normalized) directory part of the function `pwd'."
   (expand-file-name
    (file-name-as-directory
     (cadr (split-string (pwd) " ")))))
 
-(defun iorg--replace-filename-prefix (old-prefix new-prefix &optional dir)
+(defun iorg-projects--replace-filename-prefix (old-prefix new-prefix &optional dir)
   "Replace OLD-PREFIX with NEW-PREFIX in filename of
 all (non-directory) files in present working directory or DIR."
   (let ((proj
          (if dir
-             (iorg--normalize-existing-dir-name dir)
-           (iorg--pwd))))
+             (iorg-projects--normalize-existing-dir-name dir)
+           (iorg-projects--pwd))))
     (condition-case err
         (mapc
          (lambda (x)
@@ -305,20 +305,20 @@ all (non-directory) files in present working directory or DIR."
        "Error replacing the filename-prefix: %s" err))
      nil))))
 
-(defun iorg--normalize-existing-dir-name (dir)
+(defun iorg-projects--normalize-existing-dir-name (dir)
   "Return name of existing DIR in canonical form"
   (if (file-directory-p dir)
       (expand-file-name (file-name-as-directory dir))
     (message "Not a directory name")))
 
   
-(defun iorg--normalize-new-dir-name (name)
+(defun iorg-projects--normalize-new-dir-name (name)
   "Return NAME for a new directory in canonical form"
   (and (non-empty-string-p name)
        (expand-file-name (file-name-as-directory name))))
 
 ;;; Modified or new Org-mode functionality
-(defun iorg--goto-first-entry (&optional file)
+(defun iorg-projects--goto-first-entry (&optional file)
   "Move point to the beginning of line of the first entry in the
 current buffer or FILE."
   (with-current-buffer
@@ -330,7 +330,7 @@ current buffer or FILE."
         (re-search-forward org-outline-regexp-bol nil t))
     (beginning-of-line)))
 
-(defun iorg--goto-last-entry (&optional file)
+(defun iorg-projects--goto-last-entry (&optional file)
   "Move point to the beginning of line of the last entry in the
 current buffer or FILE."
   (with-current-buffer
@@ -343,7 +343,7 @@ current buffer or FILE."
          (re-search-backward org-outline-regexp-bol nil t))
      (beginning-of-line))))
 
-(defun iorg--filter-multival-property (prop reg)
+(defun iorg-projects--filter-multival-property (prop reg)
   "Returns a list of strings with all elements of MULTIVAL-PROP
 that match REGEXP."
   (remove nil 
@@ -354,50 +354,50 @@ that match REGEXP."
 
 ;;;; Public functions and user commands
 ;;; Project management 
-(defun iorg-initialize-project (&optional dir name)
+(defun iorg-projects-initialize-project (&optional dir name)
   "Copy the iOrg project template into DIR and rename the project."
   (interactive "DProject directory: \nsProject name: ")
   (let* ((directory
           (if dir
-              (iorg--normalize-existing-dir-name dir)
-            (iorg--pwd)))
+              (iorg-projects--normalize-existing-dir-name dir)
+            (iorg-projects--pwd)))
          (project-name 
           (if (and name (non-empty-string-p name))
               name
             (concat
              "project"
              (number-to-string
-              (1+ (iorg--max-numbering-unnamed-projects))))))
+              (1+ (iorg-projects--max-numbering-unnamed-projects))))))
          (project-dir (concat directory project-name)))
     (copy-directory
      (concat
-      iorg-dir "project")
+      iorg-projects-dir "project")
      project-dir)
-    (iorg-update-project project-dir)))
+    (iorg-projects-update-project project-dir)))
 
 
-(defun iorg-update-project (&optional dir)
+(defun iorg-projects-update-project (&optional dir)
   "Update filenames and configuration file for iOrg project in
 present working directory or DIR."
   (interactive "DProject directory: ")
   (let ((proj
          (if dir
-             (iorg--normalize-existing-dir-name dir)
-           (iorg--pwd))))
-    (iorg--rename-project-files nil proj)
-    ;; (iorg--update-project-config proj)
-    ;; (iorg--update-iorg-config proj)
+             (iorg-projects--normalize-existing-dir-name dir)
+           (iorg-projects--pwd))))
+    (iorg-projects--rename-project-files nil proj)
+    ;; (iorg-projects--update-project-config proj)
+    ;; (iorg-projects--update-iorg-projects-config proj)
     ))
 
-(defun iorg-rename-project (name &optional dir)
+(defun iorg-projects-rename-project (name &optional dir)
   "Rename iOrg project in present working directory of DIR."
   (interactive "sNew project name: \nDProject directory: ")
   (let ((proj
          (if dir
-             (iorg--normalize-existing-dir-name dir)
-           (iorg--pwd))))
+             (iorg-projects--normalize-existing-dir-name dir)
+           (iorg-projects--pwd))))
     (cond
-     ((not (iorg--project-directory-structure-p proj))
+     ((not (iorg-projects--project-directory-structure-p proj))
       (message "Directory does not confirm to iOrg directory structure."))
      ((not (non-empty-string-p name))
       (message "New project name must be a string of length > 0"))
@@ -405,25 +405,25 @@ present working directory or DIR."
       (condition-case err
           ;; rename and update project
           (let ((new-proj
-                 (iorg--normalize-new-dir-name
+                 (iorg-projects--normalize-new-dir-name
                   (concat
                    (file-name-directory
                     (directory-file-name proj)) name))))
             (rename-file
              (directory-file-name proj)
              new-proj)
-            (iorg-update-project new-proj))
+            (iorg-projects-update-project new-proj))
         (error 
          (princ
           (format
            "Error while renaming project: %s" err))
          nil))))))
  
-(defun iorg-delete-project (&optional project)
+(defun iorg-projects-delete-project (&optional project)
   "Delete directory of current project or PROJECT and eliminate
-  it from the `iorg-projects-plist'")
+  it from the `iorg-projects-projects-plist'")
 
-(defun iorg-export-project (dir &optional server)
+(defun iorg-projects-export-project (dir &optional server)
   "Export project defined in the current directory or in DIR, and
 start the elnode server when SERVER is non-nil"
   (interactive "DProject directory: ")
@@ -432,7 +432,7 @@ start the elnode server when SERVER is non-nil"
     (message "Not a valid directory name")))
 
 ;;; PlantUML transformation
-(defun iorg-plantuml-to-code (&optional file)
+(defun iorg-projects-plantuml-to-code (&optional file)
   "Transform all PlantUML source blocks in Org-file FILE into
 Org-mode files (with entries) and Emacs Lisp files (with
 functions and variables), following the transformation rules of

+ 293 - 0
iorg/lisp/iorg-server.el

@@ -0,0 +1,293 @@
+;;; iorg-server.el -- elnode handlers and such for handling web POST/GET requests
+
+(require 'org)
+(require 'elnode)
+(require 'org-export)
+(require 'org-e-html)
+(require 'org-agenda)
+(require 'iorg-util)
+
+;;;; Declare functions
+(declare-function org-entry-is-todo-p "org" nil)
+(declare-function org-get-todo-state "org" nil)
+(declare-function org-check-for-org-mode "org-agenda" nil)
+
+(defconst iorg-server-dir
+  (file-name-directory (or load-file-name (buffer-file-name)))
+  "The project directory of the 'simple' app in canonical form")
+
+(defconst iorg-server-urls
+  '(("^$"      . iorg-initialize-simple-handler)
+    ("^todo/$" . iorg-change-state-handler)
+    ("^edit/$" . iorg-edit-headline-handler)))
+
+(defun iorg-server-dispatcher-handler (httpcon)
+  "Dispatch requests to the 'iorg-server' app"
+  (elnode-log-access "iorg-server" httpcon)
+  (elnode-dispatcher httpcon iorg-server-urls))
+
+(defun iorg-server-postprocess (transc-str back-end comm-chan)
+  "Add buttons to HTML export to make headlines editable."
+  ;; TODO: (2) adding buttons to html export
+  (with-temp-buffer
+    (insert transc-str)
+    (goto-char (point-min))
+    (while (and
+            (re-search-forward iorg-server-todo-regexp nil t)
+            (re-search-forward iorg-server-outline-text-regexp nil t))
+      (goto-char (match-beginning 0))
+      (insert
+       (concat
+        "<form action=\"http://localhost:8031/todo/\">"
+        "  <input type=\"submit\" value=\" Finish \" name=\"outline-1\">"
+        "</form>")))
+    (buffer-substring-no-properties (point-min) (point-max))))
+
+
+(defun iorg-server-wrap-headline-todo-in-select (transc-str back-end comm-chan) 
+  "Wrap the todo part of the (BACK-END = html) transcoded Org headline TRANSC-STR into a html select-field, using information from the communication channel COMM-CHAN."
+    (with-temp-buffer
+    (insert transc-str)
+    (goto-char (point-min))
+    (while (re-search-forward iorg-server-todo-regexp nil t)
+      (goto-char (match-end 0))
+      (insert
+       (concat
+        "<select "
+        "name=\"iorg-server-todo\""
+        "size=\"1\">"
+        "<option selected>TODO</option>"
+        "<option>DONE</option>")))
+    (while (re-search-forward iorg-server-span-end-repexp nil t)
+      (goto-char (match-beginning 0))
+      (insert "<\select>"))
+    (buffer-substring-no-properties (point-min) (point-max))))
+
+(defun iorg-server-wrap-headline-tags-in-text (transc-str back-end comm-chan) 
+  "Wrap the tags in the (BACK-END = html) transcoded Org headline TRANSC-STR into one html text-field each, using information from the communication channel COMM-CHAN."
+    (with-temp-buffer
+    (insert transc-str)
+    (goto-char (point-min))
+    (while (re-search-forward iorg-server-tag-regexp nil t)
+      (goto-char (match-end 0))
+      (insert
+       (concat
+        "<input "
+        "type=\"text\""
+        "name=\"iorg-server-tag\""
+        "size=\"40\""
+        "maxlenght=\"80\">")))
+    (while (re-search-forward iorg-server-span-end-repexp nil t)
+      (goto-char (match-end 0))
+      (insert "<\input>"))
+    (buffer-substring-no-properties (point-min) (point-max))))
+
+(defun iorg-server-wrap-headline-string-in-text (transc-str back-end comm-chan) 
+  "Wrap the headline string in the (BACK-END = html) transcoded Org headline TRANSC-STR into a html text-field, using information from the communication channel COMM-CHAN."
+  (with-temp-buffer
+    (insert transc-str)
+    (goto-char (point-min))
+    (and
+     (re-search-forward "&nbsp;&nbsp;&nbsp;" nil t)
+     (re-search-backward iorg-server-span-end-repexp nil t)
+     (progn
+       (goto-char (match-end 0))
+       (insert
+        (concat
+         "<input "
+         "type=\"text\""
+         "name=\"iorg-server-headline\""
+         "size=\"40\""
+         "maxlenght=\"80\">"))
+       (and (re-search-forward "<" nil t)
+            (goto-char (match-beginning 0))
+            (insert "<\input>"))))
+    (buffer-substring-no-properties (point-min) (point-max))))
+
+(defun iorg-server-wrap-headline-in-form (transc-str back-end comm-chan) 
+  "Wrap the headline in the (BACK-END = html) transcoded Org headline TRANSC-STR into a html form, using information from the communication channel COMM-CHAN."
+    (with-temp-buffer
+    (insert transc-str)
+    (goto-char (point-min))
+    (while (re-search-forward iorg-server-outline-container-regexp nil t)
+      (goto-char (match-end 0))
+      (insert "<form action=\"http://localhost:8031/edit/\">"))
+    (while (re-search-forward iorg-server-div-end-repexp nil t)
+      (goto-char (match-beginning 0))
+      (insert
+        "<input type=\"submit\" value=\" Edit \" name=\"outline-container-1\">"
+        "</form>"))
+    (buffer-substring-no-properties (point-min) (point-max))))
+
+(defun iorg-server-wrap-headline-content-in-textarea (transc-str back-end comm-chan) 
+  "Wrap the content of the (BACK-END = html) transcoded Org headline TRANSC-STR into a html textarea, using information from the communication channel COMM-CHAN."
+    ;; TODO delete this line:
+    (message "Raw value headline: %S" (org-element-property :raw-value headline))
+    (message "Content headline: %s" (org-element-contents headline))
+    (with-temp-buffer
+    (insert transc-str)
+    (goto-char (point-min))
+    (while (re-search-forward iorg-server-outline-text-regexp nil t)
+      (goto-char (match-end 0))
+      (insert
+       (concat
+        "<textarea name=\"iorg-server-content\""
+        "cols=\"79\" rows=\"30\">" )))
+    (and (re-search-forward iorg-server-div-end-repexp nil t)
+      (goto-char (match-beginning 0))
+      (insert "<\textarea>"))
+    (buffer-substring-no-properties (point-min) (point-max))))
+
+
+(defun iorg-server-launch (port)
+  "Launch the elnode server which will serve and edit simple.org."
+  ;; TODO: (1) elnode serving simple.org to html
+  (interactive "nPort number: ")
+  (elnode-start
+   'iorg-server-dispatcher-handler
+   :port port :host "localhost"))
+
+ (defun iorg-initialize-iorg-server-handler (httpcon)
+  "Serves the start-page of the 'simple' app"
+  (elnode-send-file httpcon (iorg--org-to-html "simple.org")))
+
+ (defun iorg-change-state-handler (httpcon)
+  "Called by the elnode form handler to update task state."
+  ;; TODO: (3) handle form post data and update an Org-mode file
+  (message "entering `iorg-change-state-handler'")  
+  (let ((params (elnode-http-params httpcon)))
+    (message "These are the http-params: \n %s" params)
+    (with-current-buffer
+        (find-file (expand-file-name "simple.org" iorg-server-dir))
+      (save-excursion
+        (iorg--params-find-entry params)
+        (org-todo 'done))
+      (save-buffer)
+      ;(kill-buffer (current-buffer))
+      )
+    (iorg-initialize-iorg-server-handler httpcon)))
+
+
+;; (defun iorg-edit-headline-handler (httpcon)
+;;   "Called by the elnode form handler to update headline."
+;;   ;; TODO: (3) handle form post data and update an Org-mode file
+;;   (message "entering `iorg-edit-headline-handler'")  
+;;   (let ((params (elnode-http-params httpcon)))
+;;     (message "These are the http-params: \n %s" params)
+;;     (with-current-buffer
+;;         (find-file (expand-file-name "simple.org" iorg-server-dir))
+;;       (save-excursion
+;;         ;; (iorg--params-find-entry params)
+;;         ;; (org-todo 'done))
+;;       (save-buffer)
+;;       ;(kill-buffer (current-buffer))
+;;       )
+;;     (iorg-initialize-iorg-server-handler httpcon))))
+  
+
+(defun iorg--get-outline-level (param-list)
+  "Return level of outline-tree encoded in http-params"
+  (and
+   (listp param-list)
+   (assoc-re iorg-alist-outline-regexp param-list 2)))
+
+
+(defun iorg--normalize-outline-level (outline-level)
+  "Normalize OUTLINE-LEVEL in the format \"[-[:digit:]]+\" to a
+list of numbers (as strings). The lenght of the returned list is
+equal to the number of sublevels we need to walk down in the
+outline tree, the value of each number identifies the nth-entry
+in the Org file on that level."
+(if (not
+     (and
+      (iorg--stringp outline-level)
+      (string-match "[-[:digit:]]+" outline-level)))
+    (error "Wrong type or format of OUTLINE-LEVEL argument")
+  (delete "" (split-string outline-level "-"))))
+
+ (defun iorg--params-find-entry (param-list &optional file)
+  "Go to the entry in the current Org buffer that is specified in the PARAM-LIST"
+  (condition-case err
+      (let* ((outline-level
+              (iorg--get-outline-level param-list))
+             (normalized-outline-level
+              (iorg--normalize-outline-level outline-level))
+             (sublevel-p nil))
+        (with-current-buffer
+            (if (and file (file-exists-p file))
+                (find-file file)
+             (find-file (expand-file-name "simple.org" iorg-server-dir)))
+          (org-check-for-org-mode)
+          (save-restriction
+            (widen)
+            (iorg--goto-first-entry)
+            (mapc
+             (lambda (n)
+               (if sublevel-p
+                   (outline-next-heading))
+               (org-forward-same-level
+                (1- (string-to-number n)) "INVISIBLE-OK")
+               (unless sublevel-p
+                 (setq sublevel-p 1)))
+             normalized-outline-level))))
+    (error "Error while going to outline entry specified in PARAM-LIST: %s " err)))
+
+(defun iorg--org-to-html (org-file)
+  "Export ORG-FILE to html and return the expanded filename"
+  (if (not (file-exists-p (expand-file-name org-file iorg-server-dir)))
+      (error "File doesn't exist")
+    (save-window-excursion
+      (with-current-buffer
+          (find-file (expand-file-name org-file iorg-server-dir))
+        (and
+         (org-check-for-org-mode)
+         (org-export-to-file
+          'e-html
+          (expand-file-name
+           (concat
+            (file-name-sans-extension
+             (file-name-nondirectory org-file))
+            ".html") iorg-server-dir )))))))
+
+
+(defun iorg-404-handler (httpcon)
+  ;; TODO: This should probably actually serve a 404 page rather than
+  ;;       throwing an error
+  (progn
+    (elnode-log-access "simple" httpcon)
+    (error "iorg: 404 handler invoked")))
+
+(provide 'iorg-server)
+
+
+
+
+-----------------------------------
+
+
+(defun iorg-server-static-export-handler (httpcon file)
+  "Exports an Org file to static html"
+  (elnode-send-file httpcon (iorg--org-to-html file 'STATIC)))
+
+
+(defun iorg--org-to-html (org-file &optional STATIC)
+  "Export ORG-FILE to html and return the expanded filename. If STATIC is non nil, export to static html, otherwise use the iOrg exporter"
+  (if (not (file-exists-p (expand-file-name org-file iorg-server-dir)))
+      (error "File doesn't exist")
+    (save-window-excursion
+      (with-current-buffer
+          (find-file (expand-file-name org-file iorg-server-dir))
+        (and
+         (org-check-for-org-mode)
+         (org-export-to-file
+          (if STATIC 'e-html 'iorg) 
+          (expand-file-name
+           (concat
+            (file-name-sans-extension
+             (file-name-nondirectory org-file))
+            ".html") iorg-server-dir )))))))
+
+
+
+
+(provide 'iorg-server)

controller/bugpile-controller.el → server/bugpile-server.el


test/iorg-testsuite.el → test/bugpile-testsuite.el


view/edit-tasks/edit-task-view.org → view/edit-tasks/bugpile-edit-task-view.org