Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix js default action format #66

Merged
merged 4 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
"ubuntu-latest",
"windows-latest"
],
"exclude": [
{
"os": "windows-latest",
"lisp": "ccl-bin"
}
],
"lisp": [
"sbcl-bin",
"ccl-bin"
Expand All @@ -37,13 +43,14 @@
"steps": [
{
"name": "Checkout Code",
"uses": "actions/checkout@v3"
"uses": "actions/checkout@v4"
},
{
"name": "Setup Common Lisp Environment",
"uses": "40ants/setup-lisp@v3",
"uses": "40ants/setup-lisp@v4",
"with": {
"asdf-system": "reblocks"
"asdf-system": "reblocks",
"cache": "true"
}
},
{
Expand Down
36 changes: 5 additions & 31 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,15 @@
"steps": [
{
"name": "Checkout Code",
"uses": "actions/checkout@v3"
},
{
"name": "Grant All Perms to Make Cache Restoring Possible",
"run": "sudo mkdir -p /usr/local/etc/roswell\n sudo chown \"${USER}\" /usr/local/etc/roswell\n # Here the ros binary will be restored:\n sudo chown \"${USER}\" /usr/local/bin",
"shell": "bash"
},
{
"name": "Get Current Month",
"id": "current-month",
"run": "echo \"value=$(date -u \"+%Y-%m\")\" >> $GITHUB_OUTPUT",
"shell": "bash"
},
{
"name": "Cache Roswell Setup",
"id": "cache",
"uses": "actions/cache@v3",
"with": {
"path": "qlfile\nqlfile.lock\n~/.cache/common-lisp/\n~/.roswell\n/usr/local/etc/roswell\n/usr/local/bin/ros\n/usr/local/Cellar/roswell\n.qlot",
"key": "a-${{ steps.current-month.outputs.value }}-${{ env.cache-name }}-ubuntu-latest-quicklisp-sbcl-bin-${{ hashFiles('qlfile.lock', '*.asd') }}"
}
},
{
"name": "Restore Path To Cached Files",
"run": "echo $HOME/.roswell/bin >> $GITHUB_PATH\n echo .qlot/bin >> $GITHUB_PATH",
"shell": "bash",
"if": "steps.cache.outputs.cache-hit == 'true'"
"uses": "actions/checkout@v4"
},
{
"name": "Setup Common Lisp Environment",
"uses": "40ants/setup-lisp@v3",
"uses": "40ants/setup-lisp@v4",
"with": {
"asdf-system": "reblocks-docs"
},
"if": "steps.cache.outputs.cache-hit != 'true'"
"asdf-system": "reblocks-docs",
"cache": "true"
}
},
{
"name": "Build Docs",
Expand Down
36 changes: 5 additions & 31 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,15 @@
"steps": [
{
"name": "Checkout Code",
"uses": "actions/checkout@v3"
},
{
"name": "Grant All Perms to Make Cache Restoring Possible",
"run": "sudo mkdir -p /usr/local/etc/roswell\n sudo chown \"${USER}\" /usr/local/etc/roswell\n # Here the ros binary will be restored:\n sudo chown \"${USER}\" /usr/local/bin",
"shell": "bash"
},
{
"name": "Get Current Month",
"id": "current-month",
"run": "echo \"value=$(date -u \"+%Y-%m\")\" >> $GITHUB_OUTPUT",
"shell": "bash"
},
{
"name": "Cache Roswell Setup",
"id": "cache",
"uses": "actions/cache@v3",
"with": {
"path": "qlfile\nqlfile.lock\n~/.cache/common-lisp/\n~/.roswell\n/usr/local/etc/roswell\n/usr/local/bin/ros\n/usr/local/Cellar/roswell\n.qlot",
"key": "a-${{ steps.current-month.outputs.value }}-${{ env.cache-name }}-ubuntu-latest-quicklisp-sbcl-bin-${{ hashFiles('qlfile.lock', '*.asd') }}"
}
},
{
"name": "Restore Path To Cached Files",
"run": "echo $HOME/.roswell/bin >> $GITHUB_PATH\n echo .qlot/bin >> $GITHUB_PATH",
"shell": "bash",
"if": "steps.cache.outputs.cache-hit == 'true'"
"uses": "actions/checkout@v4"
},
{
"name": "Setup Common Lisp Environment",
"uses": "40ants/setup-lisp@v3",
"uses": "40ants/setup-lisp@v4",
"with": {
"asdf-system": "reblocks"
},
"if": "steps.cache.outputs.cache-hit != 'true'"
"asdf-system": "reblocks",
"cache": "true"
}
},
{
"name": "Change dist to Ultralisp if qlfile does not exist",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"steps": [
{
"name": "Checkout Code",
"uses": "actions/checkout@v3"
"uses": "actions/checkout@v4"
},
{
"name": "Create release tag",
Expand Down
18 changes: 8 additions & 10 deletions src/actions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,14 @@ situation (e.g. redirect, signal an error, etc.)."))
It accepts any function as input and produces a string with JavaScript code."
(check-type args (or null hash-table))

(let* ((action-code (make-action action)))
(cond
(args
(let ((options (dict "args" args)))
(format nil *js-default-action*
action-code
(yason:with-output-to-string* ()
(yason:encode options)))))
(t
(format nil *js-default-action* action-code)))))
(let* ((action-code (make-action action))
(serialized-args
(when args
(yason:with-output-to-string* ()
(yason:encode (dict "args" args))))))
(format nil *js-default-action*
action-code
serialized-args)))


(defun make-js-form-action (action)
Expand Down
6 changes: 5 additions & 1 deletion src/ci.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
:on-push-to "master"
:by-cron "0 10 * * 1"
:on-pull-request t
;; :cache t
:cache t
:jobs ((40ants-ci/jobs/run-tests:run-tests
:os ("ubuntu-latest"
"windows-latest")
:lisp ("sbcl-bin"
"ccl-bin")
:exclude ((:os "windows-latest"
;; CCL-BIN 1.13 has issues on Windows
;; https://github.com/40ants/reblocks/actions/runs/10862718561/job/30146062047?pr=66
:lisp "ccl-bin"))
:coverage t)))

(defworkflow docs
Expand Down
9 changes: 9 additions & 0 deletions src/doc/changelog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"URL"
"URI"
"API"
"PR"
"DOM"
"AJAX"
"JSON"
Expand All @@ -35,6 +36,14 @@
"REBLOCKS/SESSION:INIT")
:external-links (("Ultralisp" . "https://ultralisp.org"))
:external-docs ("https://40ants.com/log4cl-extras/"))
(0.61.0 2024-09-14
"""
Fixes
=====

* Fixed an error inside REBLOCKS/ACTIONS:MAKE-JS-ACTION function when called without :ARGS. (Thanks to olivercsr@github for the PR)

""")
(0.60.0 2024-07-28
"""
Incompatible Changed
Expand Down
42 changes: 31 additions & 11 deletions t/actions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#:hamcrest/rove
#:reblocks-tests/utils)
(:import-from #:reblocks/actions
#:generate-action-code
#:make-js-action
#:make-action
#:eval-action
#:on-missing-action
Expand All @@ -19,7 +21,11 @@
(:import-from #:reblocks/variables
#:*current-app*)
(:import-from #:serapeum
#:fmt))
#:dict
#:fmt)
(:import-from #:cl-mock
#:with-mocks
#:answer))
(in-package #:reblocks-tests/actions)


Expand Down Expand Up @@ -123,18 +129,17 @@


(deftest make-action-success
(reblocks/app:with-app (make-instance 'test-app)
(with-test-session ()
(with-test-request ("/")
(internal-make-action #'identity "abc123")
(with-test-session ()
(with-test-request ("/")
(internal-make-action #'identity "abc123")

(ok (equal (make-action "abc123")
"abc123")
"When action is defined make-action should return it's name")
(ok (equal (make-action "abc123")
"abc123")
"When action is defined make-action should return it's name")

(ok (equal (make-action #'identity)
"abc123")
"This also should work if a function was given as an argument")))))
(ok (equal (make-action #'identity)
"abc123")
"This also should work if a function was given as an argument"))))


(defun test-action ()
Expand All @@ -149,3 +154,18 @@

(ok (equal (make-action-url "test-action")
"/foo/bar?action=test-action"))))))


(deftest make-js-action-test ()
(with-test-session ()
(with-test-request ("/")
(with-mocks ()
(answer generate-action-code "action:code")

(ok (equal (make-js-action 'identity)
"return initiateAction(\"action:code\")"))

(ok (equal (make-js-action 'identity
:args (dict
"foo" 100500))
"return initiateAction(\"action:code\", {\"args\":{\"foo\":100500}})"))))))
Loading