@@ -27,7 +27,8 @@ Built-in system values automatically available in all configurations.
2727
2828# # Using Variables in Configuration
2929
30- You can reference variables using either `${VAR_NAME}` or `{{VAR_NAME}}` syntax in most configuration fields.
30+ You can reference variables using either `${VAR_NAME}` or `{{VAR_NAME}}` syntax in most configuration fields, *
31+ *including source paths**.
3132
3233# ## Example
3334
@@ -61,21 +62,139 @@ When a variable is defined in multiple places, it is resolved in the following o
6162
6263# # Built-in Predefined Variables
6364
64- # ### Date and Time
65+ # ## Date and Time Variables
6566
66- - ` ${DATETIME}` - Current date and time (e.g., `2024-03-22 14:33:00`)
67- - ` ${DATE}` - Current date (e.g., `2024-03-22`)
68- - ` ${TIME}` - Current time (e.g., `14:33:00`)
69- - ` ${TIMESTAMP}` - Current Unix timestamp
67+ | Variable | Description | Example |
68+ |----------------|------------------------|-----------------------|
69+ | `${DATETIME}` | Current date and time | `2024-03-22 14:33:00` |
70+ | `${DATE}` | Current date | `2024-03-22` |
71+ | `${TIME}` | Current time | `14:33:00` |
72+ | `${TIMESTAMP}` | Current Unix timestamp | `1711115580` |
7073
71- # ### System Information
74+ # ## System Information Variables
7275
73- - ` ${USER}` - Current system user
74- - ` ${HOME_DIR}` - User's home directory
75- - ` ${TEMP_DIR}` - System temporary directory
76- - ` ${OS}` - Operating system name
77- - ` ${HOSTNAME}` - Computer hostname
78- - ` ${PWD}` - Current working directory
76+ | Variable | Description | Example |
77+ |---------------|----------------------------|------------------------------|
78+ | `${USER}` | Current system user | `john.doe` |
79+ | `${HOME_DIR}` | User's home directory | `/home/john.doe` |
80+ | `${TEMP_DIR}` | System temporary directory | `/tmp` |
81+ | `${OS}` | Operating system name | `Linux`, `Darwin`, `Windows` |
82+ | `${HOSTNAME}` | Computer hostname | `dev-machine.local` |
83+ | `${PWD}` | Current working directory | `/home/user/project` |
84+
85+ # ## Project Path Variables
86+
87+ | Variable | Description | Example |
88+ |------------------|-----------------------------------|--------------------------------------|
89+ | `${ROOT_PATH}` | Project root directory path | `/home/user/my-project` |
90+ | `${CONFIG_PATH}` | Configuration file path | `/home/user/my-project/context.yaml` |
91+ | `${ENV_PATH}` | Environment file path (if loaded) | `/home/user/my-project/.env.local` |
92+ | `${BINARY_PATH}` | CTX binary path | `/usr/local/bin/ctx` |
93+
94+ # # Using Variables in Source Paths
95+
96+ Variables can now be used in source paths, making configurations more flexible and reusable across different
97+ environments and project structures.
98+
99+ # ## Basic Source Path Variables
100+
101+ ` ` ` yaml
102+ variables:
103+ src_dir: src/Application
104+
105+ documents:
106+ - description: "Application Code"
107+ outputPath: docs/application.md
108+ sources:
109+ - type: file
110+ sourcePaths:
111+ - "{{src_dir}}/Controllers"
112+ - "{{src_dir}}/Services"
113+ filePattern: "*.php"
114+ ` ` `
115+
116+ # ## Using Predefined Path Variables
117+
118+ ` ` ` yaml
119+ documents:
120+ - description: "Project Structure"
121+ outputPath: docs/structure.md
122+ sources:
123+ - type: file
124+ sourcePaths:
125+ - "${ROOT_PATH}/src"
126+ - "${ROOT_PATH}/config"
127+ filePattern: "*.php"
128+ ` ` `
129+
130+ # ## Environment-Specific Paths
131+
132+ ` ` ` yaml
133+ variables:
134+ env: production
135+ module_path: modules/${env}
136+
137+ documents:
138+ - description: "Environment Modules"
139+ outputPath: docs/{{env}}-modules.md
140+ sources:
141+ - type: file
142+ sourcePaths:
143+ - "{{module_path}}/api"
144+ - "{{module_path}}/services"
145+ ` ` `
146+
147+ # ## Import Paths with Variables
148+
149+ Variables are resolved before path prefixes are applied during imports :
150+
151+ ` ` ` yaml
152+ # main-config.yaml
153+ variables:
154+ services_base: services
155+
156+ import:
157+ - path: "{{services_base}}/api/context.yaml"
158+ pathPrefix: /api
159+ - path: "{{services_base}}/auth/context.yaml"
160+ pathPrefix: /auth
161+ ` ` `
162+
163+ # ## Dynamic Multi-Environment Configuration
164+
165+ ` ` ` yaml
166+ variables:
167+ app_env: ${APP_ENV} # From environment variable
168+
169+ documents:
170+ - description: "Environment-Specific Configuration"
171+ outputPath: docs/{{app_env}}-config.md
172+ sources:
173+ - type: file
174+ sourcePaths:
175+ - "config/{{app_env}}"
176+ - "${ROOT_PATH}/config/{{app_env}}/services"
177+ filePattern: "*.yaml"
178+ ` ` `
179+
180+ # ## Complex Path Construction
181+
182+ ` ` ` yaml
183+ variables:
184+ version: 2.1.0
185+ platform: linux
186+ arch: x64
187+ build_dir: builds/{{version}}/{{platform}}-{{arch}}
188+
189+ documents:
190+ - description: "Build Artifacts"
191+ outputPath: docs/builds/{{version}}.md
192+ sources:
193+ - type: file
194+ sourcePaths:
195+ - "{{build_dir}}/binaries"
196+ - "{{build_dir}}/packages"
197+ ` ` `
79198
80199# # Loading Variables from `.env` Files
81200
@@ -103,6 +222,8 @@ Custom variables are particularly useful for:
1032223. **API Credentials** : Store tokens and keys in one place
1042234. **Template Values** : Reuse common text across multiple documents
1052245. **Import Control** : Use variables in import paths to control what gets imported
225+ 6. **Multi-Environment Configurations** : Switch between dev, staging, and production paths
226+ 7. **Monorepo Management** : Reference different packages or services dynamically
106227
107228# # Examples
108229
@@ -114,6 +235,7 @@ variables:
114235 company: Acme Corp
115236 api_base: https://api.example.com/v2
116237 environment: staging
238+ source_root: src/{{environment}}
117239
118240documents:
119241 - description: "{{company}} API Documentation"
@@ -124,11 +246,59 @@ documents:
124246 - "{{api_base}}/schema"
125247 headers:
126248 Authorization: "Bearer {{API_TOKEN}}"
249+
250+ - type: file
251+ sourcePaths:
252+ - "{{source_root}}/Controllers"
253+ - "{{source_root}}/Models"
254+ filePattern: "*.php"
255+
127256 - type: text
128257 content: |
129258 # {{company}} API Documentation
130259 Version: {{version}}
131260 Environment: {{environment}}
261+ Source Path: {{source_root}}
132262
133263 Generated on {{DATETIME}} by {{USER}}
134- ` ` `
264+ Project Root: ${ROOT_PATH}
265+ ` ` `
266+
267+ # ## Monorepo Package Documentation
268+
269+ ` ` ` yaml
270+ variables:
271+ package_name: auth-service
272+ packages_dir: packages
273+
274+ documents:
275+ - description: "{{package_name}} Documentation"
276+ outputPath: docs/packages/{{package_name}}.md
277+ sources:
278+ - type: file
279+ sourcePaths:
280+ - "{{packages_dir}}/{{package_name}}/src"
281+ filePattern: "*.php"
282+
283+ - type: file
284+ sourcePaths:
285+ - "${ROOT_PATH}/{{packages_dir}}/{{package_name}}/README.md"
286+ ` ` `
287+
288+ # # Important Notes
289+
290+ # ## Variable Resolution in Imports
291+
292+ When using variables in source paths within imported configurations :
293+
294+ 1. Variables are resolved **before** path prefixes are applied
295+ 2. Absolute paths (starting with `/`) are not modified by path prefixes
296+ 3. Variables from the importing configuration are available in imported files
297+
298+ # ## Best Practices
299+
300+ 1. **Use descriptive variable names** : ` src_controllers` instead of `sc`
301+ 2. **Combine custom and predefined variables** : Leverage both for maximum flexibility
302+ 3. **Document your variables** : Add comments in YAML for team clarity
303+ 4. **Test variable resolution** : Verify paths exist before running generation
304+ 5. **Avoid circular references** : Don't reference variables within themselves
0 commit comments