Index: openacs-4/packages/acs-templating/tcl/head-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/head-procs.tcl,v
diff -u -r1.23 -r1.24
--- openacs-4/packages/acs-templating/tcl/head-procs.tcl 7 Mar 2018 20:49:33 -0000 1.23
+++ openacs-4/packages/acs-templating/tcl/head-procs.tcl 9 Mar 2018 10:22:29 -0000 1.24
@@ -147,12 +147,16 @@
} {
Flush a a script tag, which was previously set in the head section via template::add_script.
One can provide a wild
-
+
+ @author Gustaf Neumann
+ @creation-date 2018-03-09
+
@param src src attribute of the script tag, ie. the source url of the
script. A glob pattern similar link in "string match" can be provided.
@see ::template::head::add_script
} {
array unset ::template::head::scripts $src
+ flush_included $src
}
@@ -200,6 +204,9 @@
} {
Flush a a link tag, which was previously set in the head section via template::head::add_link
+ @author Gustaf Neumann
+ @creation-date 2018-03-09
+
@param href the href attribute of the link tag, eg. the target document
of the link. A glob pattern similar link in "string match"
can be provided.
@@ -209,8 +216,72 @@
@see ::template::head::add_link
} {
array unset ::template::head::links $rel,$href
+ flush_included $href
}
+ad_proc -public template::head::includes {
+ {-container:required}
+ {-parts:required}
+} {
+
+ Define, that a compound resource (container) contains multiple
+ parts. Container and parts are typically urls, which are referred
+ to by a "href" attribute or by link or a "src" attribute of a
+ script.
+
+ @author Gustaf Neumann
+ @creation-date 2018-03-09
+
+ @param container compound resource
+ @param parts list of resources, which are included in a compound resource (container).
+
+ @see ::template::head::add_link
+ @see ::template::head::add_script
+ @see ::template::head::included_p
+} {
+ set ::template::head::includes($container) $parts
+ foreach p $parts {
+ set ::template::head::included($p) $container
+ }
+}
+
+ad_proc -private template::head::included_p {
+ resource
+} {
+
+ Check, if the provided resource is included by some other resource.
+
+ @author Gustaf Neumann
+ @creation-date 2018-03-09
+
+ @param uri resource
+ @see ::template::head::includes
+} {
+ return [info exists ::template::head::included($resource)]
+}
+
+ad_proc -private template::head::flush_included {
+ resource
+} {
+ Flush a part relations ships of a compound resource
+
+ @author Gustaf Neumann
+ @creation-date 2018-03-09
+
+ @param resource compound resource
+ @see ::template::head::add_link
+} {
+ ns_log notice "flush_included <$resource> includes: [array get ::template::head::includes $resource]"
+ foreach {container parts} [array get ::template::head::includes $resource] {
+ unset ::template::head::includes($container)
+ foreach p $parts {
+ unset ::template::head::included($p)
+ }
+ }
+}
+
+
+
ad_proc -public template::head::add_meta {
{-http_equiv ""}
{-name ""}
@@ -602,6 +673,17 @@
# Generate the tag multirow
variable ::template::head::links
+
+ #
+ # Filter out included links, such we have to do this only once.
+ #
+ foreach name [array names links] {
+ lassign [split $name ,] rel href
+ if {[::template::head::included_p $href]} {
+ template::head::flush_link -href $ref -rel $rel
+ }
+ }
+
template::multirow create link rel type href title lang media order crossorigin integrity
if {[array exists links]} {
# first non alternate stylesheet
@@ -662,9 +744,15 @@
# Generate the head tag multirow
variable ::template::head::scripts
+
template::multirow create headscript type src charset defer async content order crossorigin integrity
if {[array exists scripts]} {
+
foreach name [array names scripts] {
+ if {[::template::head::included_p $name]} {
+ continue
+ }
+
foreach {type src charset defer async content order crossorigin integrity} $scripts($name) {
template::multirow append headscript \
$type \
Index: openacs-4/packages/acs-templating/tcl/test/head-test-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/test/head-test-procs.tcl,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-templating/tcl/test/head-test-procs.tcl 9 Mar 2018 10:22:29 -0000 1.1
@@ -0,0 +1,49 @@
+ad_library {
+
+ Tests for adp parsing
+
+ @author Gustaf Neumann
+ @creation-date 2018-03-09
+}
+
+aa_register_case -cats {api smoke} head_includes {
+ simple test head includes test cases
+} {
+
+ #
+ # Define two containers, both with two elements
+ #
+ template::head::includes -container a -parts {b c}
+ template::head::includes -container e -parts {f g}
+
+ aa_equals "is a already included" [template::head::included_p a] 0
+ aa_equals "is b already included" [template::head::included_p b] 1
+
+ #
+ # Flush one container via flush_link; the contained elements
+ # should be flushed as well.
+ #
+ template::head::flush_link -href a -rel stylesheet
+
+ aa_equals "is a already included" [template::head::included_p a] 0
+ aa_equals "is b already included" [template::head::included_p b] 0
+
+ aa_equals "is e already included" [template::head::included_p e] 0
+ aa_equals "is f already included" [template::head::included_p f] 1
+
+ #
+ # Flush the second container via flush_script; the contained
+ # elements should be flushed as well.
+ #
+ template::head::flush_script -src e
+
+ aa_equals "is e already included" [template::head::included_p e] 0
+ aa_equals "is f already included" [template::head::included_p f] 0
+}
+
+
+# Local variables:
+# mode: tcl
+# tcl-indent-level: 4
+# indent-tabs-mode: nil
+# End: