Skip to content

Commit

Permalink
Merge pull request #46 from 40ants/lct-changes
Browse files Browse the repository at this point in the history
A few features I've added during the latest hackathon
  • Loading branch information
svetlyak40wt authored Dec 6, 2023
2 parents 0bb8787 + bc887f6 commit b4af6d3
Show file tree
Hide file tree
Showing 24 changed files with 108 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
},
{
"name": "Install SBLint wrapper",
"run": "qlot exec ros install 40ants-linter",
"run": "qlot exec ros install 40ants-asdf-system 40ants-linter",
"shell": "bash"
},
{
"name": "Run Linter",
"run": "qlot exec 40ants-linter --system \"reblocks\"",
"run": "qlot exec 40ants-linter --system \"reblocks\" --imports",
"shell": "bash"
}
]
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
/libssl.dylib
/lispapp
.DS_Store


*.fasl
4 changes: 2 additions & 2 deletions qlfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
("quicklisp" .
(:class qlot/source/dist:source-dist
:initargs (:distribution "http://beta.quicklisp.org/dist/quicklisp.txt" :%version :latest)
:version "2023-02-15"))
:version "2023-10-21"))
("ultralisp" .
(:class qlot/source/dist:source-dist
:initargs (:distribution "http://dist.ultralisp.org" :%version :latest)
:version "20230527224500"))
:version "20231205205000"))
2 changes: 2 additions & 0 deletions reblocks.asd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
;; This package defines an :around method for reblocks/widgets:render
;; which adds a wrapper around widget body
"reblocks/widgets/render-methods"
"reblocks/routes-error-handler"
"reblocks/dependencies-impl"
;; we need to depend on this package, because
;; lack:builder will try to find `LACK.MIDDLEWARE.SESSION`
;; package
Expand Down
3 changes: 2 additions & 1 deletion src/ci.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
(defworkflow linter
:on-pull-request t
:cache t
:jobs ((40ants-ci/jobs/linter:linter)))
:jobs ((40ants-ci/jobs/linter:linter
:check-imports t)))


(defworkflow ci
Expand Down
9 changes: 5 additions & 4 deletions src/default-init.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
(:import-from #:reblocks/widgets/string-widget
#:make-string-widget)
(:import-from #:reblocks/app
#:*current-app*)
(:import-from #:spinneret/cl-markdown))
#:*current-app*))
(in-package #:reblocks/default-init)


Expand All @@ -43,8 +42,10 @@ CL-USER> (defmethod reblocks/page:init-page ((app ~A) (url-path string) expire-a
CL-USER> (reblocks/debug:reset-latest-session)"))

(:p "Then reload the page.")
(:p ("Read more in [documentation](~A)."
quickstart-url)))
(:p "Read more in "
(:a :href quickstart-url
"documentation")
"."))
:escape-p nil)))


Expand Down
1 change: 1 addition & 0 deletions src/dependencies-impl.lisp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(uiop:define-package #:reblocks/dependencies-impl
(:use #:cl)
(:import-from #:log)
(:import-from #:reblocks/response
#:send-script)
(:import-from #:parenscript
Expand Down
20 changes: 14 additions & 6 deletions src/dependencies.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:use #:cl)
(:import-from #:cl-ppcre)
(:import-from #:cl-fad)
(:import-from #:parenscript)
(:import-from #:routes)
(:import-from #:puri)
(:import-from #:serapeum
Expand Down Expand Up @@ -52,7 +51,11 @@ be stored.")
((type :type (member :css :js :png :jpg :gif)
:initarg :type
:initform (error ":type argument is required.")
:reader get-type))
:reader get-type)
(defer :type boolean
:initarg :defer
:initform nil
:reader defer))
(:documentation "This class represents a web-dependency. It could be CSS, JS or an image.
All dependencies are divided into REMOTE-DEPENDENCY or LOCAL-DEPENDENCY."))
Expand Down Expand Up @@ -185,7 +188,9 @@ as a response to some action.")
(:js
(with-html
(:script :src (get-url dependency)
:type "text/javascript" "")))
:type "text/javascript"
:defer (defer dependency)
"")))

(:css
(with-html
Expand All @@ -210,7 +215,8 @@ as a response to some action.")
(:script :src (get-url dependency)
:type "text/javascript"
:integrity (get-integrity dependency)
:crossorigin (get-crossorigin dependency))))
:crossorigin (get-crossorigin dependency)
:defer (defer dependency))))
;; CSS
(:css
(with-html
Expand Down Expand Up @@ -317,7 +323,8 @@ by infering it from URL or a path"))
type
integrity
crossorigin
cache-in-memory)
cache-in-memory
defer)
"Creates a JavaScript dependency, served from the disk.
If the system's name is given, then the path is calculated relatively
Expand Down Expand Up @@ -348,7 +355,8 @@ to this system's source root."
:type type
:remote-url path-or-url
:integrity integrity
:crossorigin crossorigin))
:crossorigin crossorigin
:defer defer))
(pathname
(let ((path path-or-url))
(when system
Expand Down
14 changes: 14 additions & 0 deletions src/doc/changelog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@
"REBLOCKS/SESSION:INIT")
:external-links (("Ultralisp" . "https://ultralisp.org"))
:external-docs ("https://40ants.com/log4cl-extras/"))
(0.55.0 2023-12-05
"""
Added
=====
* Optional argument :defer was added to javascript dependencies.
* Argument BASE-URI was added to REBLOCKS/RESPONSE:MAKE-URI function.
* Now Reblocks responds with Server-Timing and this performance information can be
viewed in the browser. Read more about this header at
[Mozilla's docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing).
* Generic-function REBLOCKS/WIDGET:UPDATE now has an optional argument REMOVED.
You can set it to T to remove widget from the DOM tree.
""")
(0.54.0 2023-10-22
"""
Added
Expand Down
9 changes: 8 additions & 1 deletion src/doc/debug.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@


(defsection @debug (:title "Debugging Reblocks"
:ignore-words ("REBLOCKS"))
:ignore-words ("REBLOCKS"
"HTTP"))
"# Performance
Reblocks return response timing in the Server-Timing HTTP header.
This performance information can be viewed in the browser.
Read more about it at [Mozilla's docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing).
"

"# API"
(status function)
Expand Down
1 change: 1 addition & 0 deletions src/doc/widgets.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
(defsection @widgets (:title "Widgets"
:ignore-words ("CSS"
"API"
"DOM"
"JS"
"HTML"
"DIV"))
Expand Down
2 changes: 0 additions & 2 deletions src/error-handler.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
(:import-from #:reblocks/variables
#:*current-app*
#:*invoke-debugger-on-error*)
(:import-from #:alexandria
#:with-gensyms)
(:import-from #:reblocks/html
#:with-html-string)
(:import-from #:reblocks/page
Expand Down
1 change: 0 additions & 1 deletion src/hooks.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#:symbolicate
#:ensure-symbol
#:with-gensyms)
(:import-from #:40ants-doc)
(:import-from #:40ants-doc/ignored-words
#:ignore-words-in-package)

Expand Down
5 changes: 5 additions & 0 deletions src/js/jquery/jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ window.commandHandlers = {
var target = jQuery('#' + params.domId);
target.replaceWith(widget);
},
'removeWidget': function(params) {
var widget = jQuery(params.widget);
var target = jQuery('#' + params.domId);
target.remove();
},
'insertWidget': function(params) {
console.log('inserting widget' + params);

Expand Down
1 change: 1 addition & 0 deletions src/page-dependencies.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#:app)
(:import-from #:serapeum
#:defvar-unbound)
(:import-from #:log)
(:import-from #:reblocks/dependencies
#:dependency-equal
#:get-url)
Expand Down
2 changes: 1 addition & 1 deletion src/preview.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
(:import-from #:log)
(:import-from #:reblocks/app)
(:import-from #:reblocks/server)
(:import-from #:reblocks/session)
(:import-from #:trivial-open-browser
#:open-browser)
(:import-from #:reblocks/widget
#:create-widget-from
#:defwidget)
(:import-from #:reblocks/page)
(:export #:preview
#:stop))
(in-package #:reblocks/preview)
Expand Down
2 changes: 0 additions & 2 deletions src/request-handler.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
#:*timing-level*
#:*timing-report-fn*
#:timing)
(:import-from #:bordeaux-threads
#:with-lock-held)
(:import-from #:jonathan
#:to-json)
(:import-from #:trivial-timeout
Expand Down
1 change: 0 additions & 1 deletion src/request.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#:query-string->alist)

;; Just to add dependency
(:import-from #:reblocks/session)
(:import-from #:quri)
(:import-from #:str
#:split)
Expand Down
30 changes: 20 additions & 10 deletions src/response.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
#:get-uri
#:ajax-request-p
#:get-header)
(:import-from #:reblocks/variables
#:*ignore-missing-actions*)
(:import-from #:reblocks/js/base
#:with-javascript-to-string
#:with-javascript)
(:import-from #:reblocks/app
#:get-prefix)
(:import-from #:reblocks/commands
#:add-command)
(:import-from #:quri)
Expand Down Expand Up @@ -162,15 +158,20 @@
(lack.response:response-set-cookies response))


(defun make-uri (new-path)
(defun make-uri (new-path &key base-uri)
"Makes a new URL, based on the current request's URL.
If new-path can be absolute, like /logout or relative,
Argument NEW-PATH can be absolute, like /logout or relative,
like ./stories.
Also, it can contain a query params like /login?code=100500"
(let* ((base (get-uri))
(parsed-base (quri:uri base))
Also, it can contain a query params like /login?code=100500
By default, function takes a base-uri from the current request,
bun in case if you want to call the function in a context where
request is not available, you can pass BASE-URI argument explicitly."
(let* ((base-uri (or base-uri
(get-uri)))
(parsed-base (quri:uri base-uri))
(parsed-new-path (quri:uri new-path))
(new-url (quri:merge-uris parsed-new-path
parsed-base)))
Expand Down Expand Up @@ -293,7 +294,16 @@
;; show the old state of the page in case of caching.
:cache-control "no-cache, no-store, must-revalidate"))
(*response* (lack.response:make-response 200 headers ""))
(result (funcall thunk)))
(started-at (get-internal-real-time))
(result (funcall thunk))
(ended-at (get-internal-real-time))
(duration (float (/ (- ended-at started-at)
internal-time-units-per-second))))

;; Timing header according to
;; https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing
(add-header :server-timing
(format nil "render;dur=~A" duration))

(cond
((and result (listp result))
Expand Down
11 changes: 4 additions & 7 deletions src/server.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#:get-route
#:add-route
#:add-routes)
(:import-from #:reblocks/routes-error-handler)
(:import-from #:reblocks/app
#:get-prefix
#:app-serves-hostname-p
Expand All @@ -29,16 +28,14 @@
(:import-from #:reblocks/request-handler
#:handle-request)

(:import-from #:lack.request
(:import-from #:lack/request
#:make-request)
(:import-from #:lack
#:builder)
(:import-from #:lack/response)
(:import-from #:clack
#:clackup)
(:import-from #:cl-strings
#:starts-with)
;; Just dependencies
(:import-from #:reblocks/dependencies-impl)
(:import-from #:reblocks/debug)
(:import-from #:log)
(:import-from #:reblocks/welcome/app
Expand Down Expand Up @@ -213,8 +210,8 @@ Make instance, then start it with ``start`` method."

(defun make-response-for-clack (response)
(etypecase response
(lack.response:response
(lack.response:finalize-response response))
(lack/response:response
(lack/response:finalize-response response))
(list response)
(function response)))

Expand Down
2 changes: 0 additions & 2 deletions src/session.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#:make-weak-hash-table)
(:import-from #:alexandria
#:ensure-gethash)
(:import-from #:metatilities
#:deprecated)
(:import-from #:lack.session.store
#:remove-session)

Expand Down
4 changes: 2 additions & 2 deletions src/welcome/widget.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
(:import-from #:reblocks/server
#:get-port
#:get-interface)
(:import-from #:reblocks/session)
(:import-from #:reblocks/html
#:with-html)
(:import-from #:reblocks/widget
Expand All @@ -15,7 +14,8 @@
#:get-prefix
#:webapp-name
#:*current-app*)
(:import-from #:local-time))
(:import-from #:local-time)
(:import-from #:reblocks/page))
(in-package #:reblocks/welcome/widget)


Expand Down
Loading

0 comments on commit b4af6d3

Please sign in to comment.