diff options
Diffstat (limited to 'compute_scripts.awk')
-rwxr-xr-x | compute_scripts.awk | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/compute_scripts.awk b/compute_scripts.awk index e5efc49..2d7ea72 100755 --- a/compute_scripts.awk +++ b/compute_scripts.awk @@ -56,6 +56,7 @@ BEGIN { directive_args_patterns["EXPORT"] = "^(" EXPORT_AS_re "|" identifier_re ")$" directive_args_patterns["LOADJS"] = "^[^[:space:]]+$" + directive_args_patterns["LOADCSS"] = "^[^[:space:]]+$" } function validate_path(read_path, path, line) { @@ -125,6 +126,7 @@ function process_file(path, read_path, mode, if (mode == "html" && path == read_path) { clear_array(page_js_deps) page_js_deps_count = 0 + clear_array(page_css_deps) } modes[path] = mode @@ -200,7 +202,7 @@ function process_file(path, read_path, mode, if (directive !~ \ /^(IF|ENDIF|ELSE|ELIF|ERROR|INCLUDE|INCLUDE_VERBATIM|COPY_FILE)$/ && (mode != "js" || directive !~ /^(IMPORT|FROM|EXPORT)$/) && - (mode != "html" || directive !~ /^LOADJS$/) && + (mode != "html" || directive !~ /^(LOADJS|LOADCSS)$/) && (mode != "manifest" || directive !~ /^(LOADJS|LOADHTML)$/)) { printf "ERROR: Invalid # directive in %s: %s\n", read_path, line > "/dev/stderr" @@ -300,6 +302,10 @@ function process_file(path, read_path, mode, if (load_js_file(path, read_path, directive_args, line) < 1) return 1 } + } else if (directive == "LOADCSS") { + if (load_css_file(path, read_path, directive_args, line, + page_css_deps)) + return 1 } else if (directive == "LOADHTML") { if (load_html_file(path, read_path, directive_args, line)) return 1 @@ -537,7 +543,7 @@ function compute_deps(js_path, dependencies, count, dependencies_added, } # Here js_deps and js_deps_count are optional args, used when loading scripts -# into an HTML page to avoid having th same script loaded twice in multiple +# into an HTML page to avoid having the same script loaded twice in multiple # places. function load_js_file(root_path, read_path, loaded_path, line, js_deps, js_deps_count, @@ -576,6 +582,25 @@ function load_js_file(root_path, read_path, loaded_path, line, return js_deps_count } +# css_deps is an array used to avoid having the same stylesheet loaded twice in +# multiple places in a single HTML page. +function load_css_file(root_path, read_path, loaded_path, line, css_deps) { + delete css_deps[""] + + if (validate_path(read_path, loaded_path, line)) + return 1 + + if (!(loaded_path in css_deps)) { + css_deps[loaded_path] + to_copy[loaded_path] + added_line = ("<link rel=\"stylesheet\" type=\"text/css\" " \ + "href=\"/" loaded_path "\" />") + add_line(root_path, added_line) + } + + return 0 +} + function load_html_file(root_path, read_path, loaded_path, line) { if (validate_path(read_path, loaded_path, line)) return 1 |