artanis
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

controller syntax (for guix)


From: Mortimer Cladwell
Subject: controller syntax (for guix)
Date: Sat, 10 Sep 2022 06:12:22 -0400

Below I am talking about my toy Artanis app "myapp" found at https://github.com/mbcladwell/myapp
 
If I generate the pages.scm controller using 'art draw controller...' I get the templated first lines that I modify to look like:

------8<--------------pages.scm-----START----------------8<-------------
; Controller intro definition of pages
;; Please add your license header here.
;; This file is generated automatically by GNU Artanis.
(define-artanis-controller pages) ; DO NOT REMOVE THIS LINE!!!

(use-modules (artanis utils)(artanis artanis)(myapp lib mylib))
------8<--------------------------END----------------8<-------------

There are two potential sources of guix warnings when controllers using this syntax are packaged and installed by guix:

1. error: define-artanis-controller: unbound variable
hint: Did you forget `(use-modules (artanis mvc controller))'?

2. hint: File `.../pages.scm' should probably start with: (define-module (myapp app controllers pages))
 
Note that these are warnings only, the app runs fine.  However if you have 10 controllers in your app you will get 10 warnings with each invocation of guix package i, -r, -s or guix pull.    I think that might be disconcerting for casual guix users.

These warnings can be eliminated by rewriting the controller as a module:

------8<--------------modified pages.scm-----START----------------8<-------------
(define-module (myapp app controllers pages)
   #:autoload (myapp app models pages) (#,(datum->syntax #'pages (symbol-append '$ (syntax->datum #'pages))))
  #:use-module (myapp lib mylib)
  #:use-module (artanis artanis)
  #:use-module (artanis env)
  #:use-module (artanis utils)
  #:use-module (artanis mvc controller)
  #:use-module (artanis webapi restful)
  )

(define-artanis-controller pages) ; DO NOT REMOVE THIS LINE!!!

(pages-define page1
              (lambda (rc).........etc.
------8<--------------------------END----------------8<-------------

artanis/mvs/controller.scm must be appropriately modified:

------8<--------------modified artanis/mvc/controller.scm-----START----------------8<-------------
(define-syntax define-artanis-controller
  (lambda (x)
    (syntax-case x ()
      ((_ name) (identifier? #'name)
       #`(begin
           ;; NOTE: we have to encapsulate them to a module for protecting namespaces
           ;; NOTE: we're not going to imort (artanis env) directly to avoid revealing global
           ;;       env vars to users.
     ================REMOVE BELOW======================
     ;;      (define-module (app controllers name)
     ;;        #:autoload (app models name) (#,(datum->syntax #'name (symbol-append '$ (syntax->datum #'name))))
     ;;        #:use-module (artanis artanis)
     ;;        #:use-module (artanis env)
     ;;        #:use-module (artanis utils))
     ================REMOVE ABOVE======================
           (define-syntax-rule (#,(datum->syntax x 'view-render) method e)
             (let ((file (format #f "~a/app/views/~a/~a.html.tpl"
                                 (immutable-toplevel) 'name method)))
               (cond
                ((file-exists? file)
                 (let ((html ((@@ (artanis tpl) tpl-render-from-file) file e)))
                   ((@ (artanis artanis) response-emit) html)))
                (else ((@ (artanis artanis) response-emit) "" #:status 404)))))

------8<-------------------------------------------------------END----------------8<-------------

i.e. I comment out the define-module section and explicitly move it into the controller.  Note this breaks your desire for encapsulation. There are probably work-arounds but I haven't thought that through yet.  These changes have not been tested extensively, only on myapp which does not have models, so I am uncertain of the #:autoload modification.

Your thoughts?  OK to change controller syntax?
Thanks
Mortimer



reply via email to

[Prev in Thread] Current Thread [Next in Thread]