Rename cmp to scope

This commit is contained in:
Akira Tempaku 2024-04-15 00:08:03 +09:00
parent b771eec3b5
commit 92c11d61a9
5 changed files with 13 additions and 13 deletions

View file

@ -11,7 +11,7 @@
(pi:define-element page ()
(pi:h
(section :data-cmp "pages/about"
(section :data-scope "pages/about"
(h1 "About")
(a :href "/" :hx-boost "true"
"top"))))

View file

@ -7,7 +7,7 @@
(pi:define-element page ()
(pi:h
(section :data-cmp "pages/index"
(section :data-scope "pages/index"
(h1 "Hello, World!")
(a :href "/about" :hx-boost "true"
"About"))))

View file

@ -1,4 +1,4 @@
@scope ([data-cmp='pages/about']) {
@scope ([data-scope='pages/about']) {
:scope {
height: 100svh;
background-color: thistle;

View file

@ -1,4 +1,4 @@
@scope ([data-cmp='pages/index']) {
@scope ([data-scope='pages/index']) {
:scope {
height: 100svh;
background-color: aliceblue;

View file

@ -4,15 +4,15 @@
(:export #:collect-style-links))
(in-package #:hp/view/optimizer)
(defun detect-components (page-str)
(remove-duplicates (re:all-matches-as-strings "(?<=data-cmp=\")[^\"]*(?=\")"
page-str)
(defun detect-scopes (html-str)
(remove-duplicates (re:all-matches-as-strings "(?<=data-scope=\")[^\"]*(?=\")"
html-str)
:test #'string=))
(defun components->stylesheets (data-cmps)
(mapcar (lambda (cmp-name)
(concatenate 'string "/styles/" cmp-name ".css"))
data-cmps))
(defun scopes->stylesheets (scopes)
(mapcar (lambda (scope)
(concatenate 'string "/styles/" scope ".css"))
scopes))
(defun collect-style-links (page-str)
(components->stylesheets (detect-components page-str)))
(defun collect-style-links (html-str)
(scopes->stylesheets (detect-scopes html-str)))