; Code generation for Dojo classes (especially declare, define, imports) (defun dojo-jsgen-open-file (directory name) "Uses find file to open a (new) js file for the class with the given name in the given directory. Returns a two element list containing project and path of the class." (let* ((file-name (concat directory name ".js")) (curr-path (file-truename directory)) (project nil) (path nil) ) ; (log-i18n (format "dojo-cdes-jsgen-generate-page dir = [%s], curr-path = [%s]" directory curr-path)) (if (starts-with curr-path dojo-workspace-path) (setq curr-path (substring curr-path (length dojo-workspace-path))) ) (let* ((first-slash-pos (string-match "/" curr-path)) ) (setq project (substring curr-path 0 first-slash-pos)) (setq curr-path (substring curr-path (1+ first-slash-pos))) ) (if (starts-with curr-path "src/main/resources/OSGI-INF/webapp/") (setq curr-path (substring curr-path (length "src/main/resources/OSGI-INF/webapp/"))) ) (let* ((last-slash-pos (last-index-of curr-path "/")) ) (setq path (concat (substring curr-path 0 (1+ last-slash-pos)) name)) ) ; (log-i18n (format "dojo-cdes-jsgen-generate-page determined curr-path = [%s], project = [%s], path = [%s]" curr-path project path)) (find-file file-name) (list project path) ) ) (defun dojo-jsgen-insert-imports (path-symbol-pairs) "Given a list of two-element-lists, this function generates the import section of a Dojo file, starting with the 'define(' and ending with the opening curly bracket after the final symbol. I.e., something like define([ 'bar/foo'], function(Foo) {" (insert "define([ ") (newline) (let* ((n 0) ) (dolist (path-symbol-pair path-symbol-pairs) (dojo-insert-js (concat "\"" (nth 0 path-symbol-pair) "\"" (if (< n (1- (length path-symbol-pairs))) "," ""))) (setq n (1+ n)) ) (setq n 0) (dojo-insert-js "], function(") (newline) (dolist (path-symbol-pair path-symbol-pairs) (dojo-insert-js (concat (nth 1 path-symbol-pair) (if (< n (1- (length path-symbol-pairs))) "," ""))) (setq n (1+ n)) ) (dojo-insert-js ") {") ) ) (defun dojo-jsgen-classes-insert-classname-log-section (package-name name) (newline) (dojo-insert-js (concat "var className = \"" package-name name "\";")) (newline) (dojo-insert-js "var log = new TinyLog(className);") (newline) ) (defun dojo-jsgen-insert-declare-section (package-name name) "Inserts the section between the imports and the declare line of a Dojo js file" (dojo-jsgen-classes-insert-classname-log-section package-name name) (dojo-insert-js (concat "var " name " = declare(className, ContentWidget, {")) (newline) ) (defun dojo-jsgen-insert-default-content-widget-constructor () (dojo-insert-fct-start "constructor" "params") (dojo-insert-js "lang.mixin(this, params);") (newline) (dojo-insert-js "this.topDiv = this.constructTopDiv();") (newline) (dojo-insert-js "this.allFieldsValid = true;") (dojo-insert-fct-end) ) (defun dojo-jsgen-insert-default-content-widget-functions (name) ; constructor (dojo-jsgen-insert-default-content-widget-constructor) ; getWidgetId (dojo-insert-fct "getWidgetId" "" (concat "return \"" name "\";")) ; getDataId (dojo-insert-fct "getDataId" "" "return null;") ; getContainer (dojo-insert-fct "getContainer" "" "return this.topDiv;") ) (provide 'dojo-jsgen-classes)