kalastatic
Advanced tools
Comparing version
@@ -5,3 +5,3 @@ { | ||
"repository": "https://github.com/kalamuna/kalastatic.git", | ||
"version": "6.0.0-alpha2", | ||
"version": "6.0.0-alpha3", | ||
"type": "module", | ||
@@ -15,13 +15,18 @@ "license": "MIT", | ||
"dependencies": { | ||
"drupal-twig-extensions": "^1.0.0-beta.5", | ||
"meow": "^12.1.1", | ||
"sass": "^1.69.5", | ||
"twig": "^1.16.0" | ||
"drupal-twig-extensions": "^1.0.0-beta.4", | ||
"meow": "^12.0.1", | ||
"sass": "^1.58.3", | ||
"twig": "^1.16.0", | ||
"twig-markdown": "^1.1.0" | ||
}, | ||
"scripts": { | ||
"test": "bin/kalastatic.js examples/simple" | ||
"test": "bin/kalastatic.js examples/simple", | ||
"pretest": "npm it --prefix test" | ||
}, | ||
"bin": { | ||
"kalastatic": "./bin/kalastatic.js" | ||
}, | ||
"devDependencies": { | ||
"assert-dir-equal": "^1.1.0" | ||
} | ||
} |
@@ -24,2 +24,3 @@ # kalastatic | ||
For more in depth documentation, visit https://kalamuna.github.io/kalastatic/ | ||
An example with some draft documentation for the new version of Kalastatic: | ||
https://kalamuna.github.io/kstat_test |
@@ -7,2 +7,3 @@ // This script would exist within the node module and doesn't need to be invoked during a real project | ||
import Twig from "twig"; | ||
import twigMarkdown from 'twig-markdown'; | ||
@@ -18,3 +19,5 @@ import { | ||
// Add the Twig extensions. | ||
addDrupalExtensions(Twig); | ||
Twig.extend(twigMarkdown); | ||
@@ -35,3 +38,3 @@ // Finds twig pages in a directory and returns an array of filenames | ||
} | ||
} else if (file.endsWith('.twig')) { | ||
} else if (file.endsWith('.html.twig')) { | ||
twigFiles.push(`${directory}/${file}`); | ||
@@ -177,2 +180,14 @@ } | ||
Twig.functions.attach_library = function(library) { | ||
// Check if libraries are defined. | ||
if (!config.libraries) { | ||
console.error(`kalastatic: Called attach_library('${library}'), but no libraries are defined. Add the library definitions to package.json's kalastatic.libraries configuration. See https://kalamuna.github.io/kstat_test/kalastatic-functions-filters/#attach-library`); | ||
return; | ||
} | ||
// Check if the desired library is defined. | ||
if (!Object.hasOwn(config.libraries, library)) { | ||
console.error(`kalastatic: Called attach_library('${library}'), but the library is not defined. Add it to package.json's kalastatic.libraries configuration. See https://kalamuna.github.io/kstat_test/kalastatic-functions-filters/#attach-library`); | ||
return; | ||
} | ||
// Add any associated sylesheets | ||
@@ -183,4 +198,7 @@ for (const source in config.libraries[library].stylesheets) { | ||
renderData.stylesheet_files.push(filename); | ||
renderData.stylesheets[0] += "<link href=\"" + renderData.base_url + "/" + filename + "\" rel=\"stylesheet\">"; | ||
renderData.kalastatic_stylesheets[0] += "<link href=\"" + renderData.base_url + "/" + filename + "\" rel=\"stylesheet\">"; | ||
} | ||
else { | ||
console.error(`kalastatic: Library stylesheet file missing: ${library} ${source} expects "${filename}"`); | ||
} | ||
} | ||
@@ -193,10 +211,19 @@ | ||
renderData.script_files.push(filename); | ||
renderData.scripts[0] += "<script src=\"" + renderData.base_url + "/" + filename + "\" ></script>"; | ||
renderData.kalastatic_scripts[0] += "<script src=\"" + renderData.base_url + "/" + filename + "\" ></script>"; | ||
} | ||
else { | ||
console.error(`kalastatic: Library JavaScript file missing: ${library} ${source} expects "${filename}"`); | ||
} | ||
} | ||
}; | ||
// Get the list of namespaces from the configuration. | ||
Twig.functions.get_namespaces = function() { | ||
if (!config.hasOwnProperty('namespaces')) { | ||
return []; | ||
} | ||
return Object.keys(config.namespaces); | ||
} | ||
// Get the files within the directory of a twig namespace. | ||
@@ -220,8 +247,8 @@ Twig.functions.get_namespace_files = function(namespace) { | ||
renderData.stylesheet_files = []; // Stores which stylesheets have already been added. | ||
renderData.stylesheets = [""]; // Stores the concatinated link tags, with the string in an array to solve the hoisting issue. | ||
for (const source in config.stylesheets) { | ||
let destination = config.destination + '/' + config.stylesheets[source]; | ||
renderData.kalastatic_stylesheets = [""]; // Stores the concatinated link tags, with the string in an array to solve the hoisting issue. | ||
for (const source in config.kalastatic_stylesheets) { | ||
let destination = config.destination + '/' + config.kalastatic_stylesheets[source]; | ||
await compileCSS(source, destination); | ||
renderData.stylesheet_files.push(config.stylesheets[source]); | ||
renderData.stylesheets[0] += "<link href=\"" + renderData.base_url + "/" + config.stylesheets[source] + "\" rel=\"stylesheet\">"; | ||
renderData.stylesheet_files.push(config.kalastatic_stylesheets[source]); | ||
renderData.kalastatic_stylesheets[0] += "<link href=\"" + renderData.base_url + "/" + config.kalastatic_stylesheets[source] + "\" rel=\"stylesheet\">"; | ||
} | ||
@@ -231,9 +258,9 @@ | ||
renderData.script_files = []; // Stores which scripts have already been added. | ||
renderData.scripts = [""]; // Stores the concatinated script tags, with the string in an array to solve the hoisting issue. | ||
for (const source in config.scripts) { | ||
let destination = config.destination + '/' + config.scripts[source]; | ||
renderData.kalastatic_scripts = [""]; // Stores the concatinated script tags, with the string in an array to solve the hoisting issue. | ||
for (const source in config.kalastatic_scripts) { | ||
let destination = config.destination + '/' + config.kalastatic_scripts[source]; | ||
await createDestinationDir(destination); | ||
fs.copyFile(source, destination); | ||
renderData.script_files.push(config.scripts[source]); | ||
renderData.scripts[0] += "<script src=\"" + renderData.base_url + "/" + config.scripts[source] + "\" ></script>"; | ||
renderData.script_files.push(config.kalastatic_scripts[source]); | ||
renderData.kalastatic_scripts[0] += "<script src=\"" + renderData.base_url + "/" + config.kalastatic_scripts[source] + "\" ></script>"; | ||
} | ||
@@ -240,0 +267,0 @@ |
13963
12.06%290
8.21%26
4%5
25%1
Infinity%+ Added
+ Added
+ Added
+ Added
Updated
Updated