How creadores-program/esjs-script-tag works
Project Type and Purpose
• This is a client-side JavaScript library designed to be embedded into HTML pages. Its purpose is to simplify the execution of EsJS (a custom scripting language) and EsHtml (HTML markup in Spanish) by providing a dedicated script tag.
• The README shows that users add this script (CDN hosted) to their HTML and then include either script or div tags with specially defined types (“codigo/esjs” and “codigo/eshtml”) for further custom behaviors. No backend or extra infrastructure is involved.
Analyzing the File Structure
• The top-level “src” directory contains the core logic. Under “src/org/CreadoresProgram/EsJsHtml/”, the file EsjsScriptTag.js is the main component.
• The project is structured simply – without separate modules for a frontend/backend – which is common for a library that gets embedded directly into client-side code.
• The absence of additional directories like “backend”, “tests”, etc., shows that the main focus is on providing a self-contained client-side tool.
Leveraging the README for Additional Insights
• The README demonstrates usage examples for invoking custom EsJS and EsHtml code by embedding specific HTML attributes. This indicates that the library likely scans the DOM or intercepts script additions to process these custom types.
• The design pattern here is to allow developers to extend their HTML with custom behavior by simply inserting the appropriate tags. This is a type of “auto-bootstrap” pattern where the loaded script configures and executes code based on the presence of marked elements.
a. Main Components:
• CDN Delivery: Represents the hosting service (e.g., jsdelivr) that delivers EsjsScriptTag.js.
• HTML Document: The “user’s” HTML page that contains:
• Standard <script> tags that load the EsJS-Script-tag.
• Custom <script type="codigo/esjs"> tags (with or without “src”) for EsJS code.
• Custom
blocks for EsHtml code.
• EsjsScriptTag.js: The central module that, once loaded, acts as the processing engine.
• EsJS Handler: The component/logic within EsjsScriptTag.js that detects and processes <script type="codigo/esjs"> tags.
• EsHTML Handler: The component/logic within EsjsScriptTag.js that detects and processes
blocks.
b. Relationships and Interactions:
• The browser loads the HTML document which includes the script tag linking to EsjsScriptTag.js via the CDN.
• Once executed, this script scans the DOM for elements with type "codigo/esjs" and "codigo/eshtml".
• It passes the found elements to the respective internal handlers:
• For EsJS, it either evaluates inline code or fetches code from external “src” URLs.
• For EsHTML, it interprets and renders the HTML written in Spanish.
• The interactions occur entirely on the client side with a single script module coordinating the process.
c. Architectural Patterns:
• Modular ES module: The library is provided as an ES module (using type="module") allowing modern browsers to import it safely.
• Auto-initialization: On load, the script automatically configures and processes the marked HTML tags.
• Separation of Concerns: Different handling logic for EsJS and EsHTML exists inside the single module, ensuring clarity between processing the scripting language and the HTML dialect.
• Extensibility: The design allows adding more custom elements or attributes in future versions.
d. Relevant Technologies and Frameworks:
• JavaScript (ES6+ features and modules)
• Browser DOM manipulation APIs for scanning and processing custom tags.
• HTML standards, noting the usage of standard <script> tags with type="module" for modularity.
• The CDN (e.g., jsdelivr) serving the library.