Greg Slepak  committed f46ca2d

added SET_DFLY_SELF function and corresponding DFLY_SELF and DFLY_SELF_DIR symbols.

  • Participants
  • Parent commits 9f28677

Comments (0)

Files changed (4)

     active plugins folder if you want to use it.
   * added utf8-urlencode/decode functions to Request, they handle foreign characters perfectly.
   * much improved the smtp module that comes with newLISP and added it to the inactive plugins.
+  * added 'SET_DFLY_SELF' function and the corresponding DFLY_SELF and DFLY_SELF_DIR global symbols.
 Version 0.51

File example-site/dragonfly-framework/dragonfly.lsp

 	(replace {\.\.[/|\\]} path "" 0) ; we don't want them getting at things they shouldn't
 	(if-not ext (set 'ext (regex-captcha {.*\.(\w+)$} path)))
 	(if ext (Response:content-type (Response:extension->type ext)))
+	(SET_DFLY_SELF path)
 	(unless (DF:display-file path)
 		(DF:die "Failed to get: " path)
 (define (run)
+	(SET_DFLY_SELF path)
 	(load path)
 	(set 'ctx-str (string "Resource." (join (map title-case (parse resource_name "_")))))
 	(set 'ctx-sym (sym ctx-str))

File example-site/dragonfly-framework/lib/utils.lsp

 		(dolist (x assoc-list) (ctx (first x) (last x)))
+;; @syntax (SET_DFLY_SELF <str-filepath>)
+;; @param <str-filepath> The path to the file being served, or the primary file responsible for handling this route.
+;; <p>Routes should call this global function with the path to the file that's being displayed
+;; or the file that's principly in charge of handling this route. This function will then
+;; set the global variables 'DFLY_SELF' and 'DFLY_SELF_DIR' to point to that file and its
+;; parent directory, respectively.</p>
+;; <p>The default routes 'Route.Static' and 'Route.Resource' call this function first thing
+;; in their 'Route:run' methods, prior to loading the files. This is the recommended way of
+;; calling this function.</p>
+	(define (SET_DFLY_SELF file)
+		(when (setf file (real-path file))
+			(set (global 'DFLY_SELF)     file
+			     (global 'DFLY_SELF_DIR) (regex-captcha {^(.+/)} file)
+			)
+		)
+	)
 	; these functions should be global (define-subclass should not)
 	(global 'load-files-in-dir 'regex-captcha 'load-once
-		'wrap-func 'into-ctx-assoc 'add-to-load-path
+		'wrap-func 'into-ctx-assoc 'add-to-load-path 'SET_DFLY_SELF
 	; swap these functions for ours and save the originals

File example-site/dragonfly-framework/plugins-inactive/route_cgi.lsp

 (define (run)
+	(SET_DFLY_SELF path)
 	(load path)