Assembler Composition Rules

Understanding the five core composition rules

Overview

This document outlines the five core composition rules used in the Arshu Assembler framework. These rules define how HTML templates and JSON data are merged to generate the final output.

1 Direct Composition

Concept: A main template directly includes the content of another HTML file.

Mechanism

The main template uses a {{'{{'}}ComponentName{{'}}'}} placeholder. The engine replaces this placeholder with the content of ComponentName.html, which is typically located in a Component/ subdirectory.

Direct Composition Diagram

Example

<!-- main.html -->
<div>
  {{'{{'}}Html1AContent{{'}}'}}
</div>

<!-- Component/Html1AContent.html -->
<h3>This is the content</h3>

2 Slotted Composition

Concept: A main template defines content that is then placed into a specific "slot" within a reusable layout template.

Mechanism

This allows for creating reusable page layouts where only specific sections change.

Slotted Composition Diagram

Example

<!-- Layout/Center.html -->
<div class="center">
  {{'{{'}}$Content{{'}}'}}
</div>

<!-- main.html -->
{{'{{'}}#Center}}
  {{'{{'}}@Content}}
    <h1>Hello World</h1>
  {{'{{'}}/@Content}}
{{'{{'}} /Center}}

3 Contextual Composition

Concept: A template includes content from a component whose location is determined by the current application context or view.

Mechanism

The main template (e.g., html3A.html) uses a {{'{{'}}ComponentName{{'}}'}} placeholder. The engine resolves this by looking for ComponentName.html within a context-specific Views/ directory. This allows different views to use the same placeholder name but load different content.

Contextual Composition Diagram

4 JSON Key Composition

Concept: A template is populated with simple string values from a corresponding JSON file.

Mechanism

JSON Key Composition Diagram

Example

// data.json
{
  "Title": "Welcome",
  "Description": "Hello World"
}

<!-- template.html -->
<h1>{{'{{'}}$Title{{'}}'}}</h1>
<p>{{'{{'}}$Description{{'}}'}}</p>

5 JSON Array Composition

Concept: A template iterates over an array of objects from a JSON file to generate a block of HTML for each item.

Mechanism

JSON Array Composition Diagram

Example

// data.json
{
  "Items": [
    { "Name": "Item 1", "Price": 10 },
    { "Name": "Item 2", "Price": 20 }
  ]
}

<!-- template.html -->
{{'{{'}}@Items}}
  <div>
    <h3>{{'{{'}}$Name{{'}}'}}</h3>
    <p>Price: ${{'{{'}}$Price{{'}}'}}</p>
  </div>
{{'{{'}} /Items}}

{{'{{'}}^Items}}
  <p>No items available</p>
{{'{{'}} /Items}}

Summary

These five composition rules form the foundation of the Arshu Assembler framework, enabling powerful and flexible template-based content generation across multiple programming languages.

Back to Home