You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,14 @@ The Scribble GYB configuration simplifies boilerplate code generation for Scribb
19
19
20
20
3.3 [Conditional Logic](#conditional-logic)
21
21
22
+
3.4 [Loops](#loops)
23
+
24
+
4.[Using gyb_utils.py for Shared Utilities](#using-gyb-utils-py-for-shared-utilities)
25
+
26
+
4.1 [Declaring global variables](#declaring-global-utilities-in-gyb-utils-py)
27
+
28
+
4.2 [Importing and Using Utilities](#importing-and-using-utilities-in-gyb-templates)
29
+
22
30
## Overview
23
31
24
32
GYB (Generate Your Boilerplate) is a tool used to generate source code by mixing Python code with template files. It allows developers to avoid redundancy by dynamically generating patterns across different files or languages. Scribble GYB offers a powerful way to ensure clean, consistent code while minimizing manual coding effort.
@@ -192,6 +200,39 @@ struct User {
192
200
193
201
## Using gyb_utils.py for Shared Utilities
194
202
203
+
The `gyb_utils.py` file in the Scribble GYB configuration allows you to declare global variables, helper functions, or imports that can be reused across different GYB templates. This is especially useful when you have common logic or variables that need to be shared.
204
+
205
+
### Declaring Global Utilities in `gyb_utils.py`
206
+
207
+
You can modify the `gyb_utils.py` file to declare any utility functions, global variables, or imports. For example, you can declare shared constants or utility functions like this:
208
+
209
+
```py
210
+
# gyb_utils.py
211
+
PI = 3.14159
212
+
213
+
def square(x):
214
+
return x * x
215
+
```
216
+
217
+
### Importing and Using Utilities in GYB Templates
218
+
219
+
Once you have your utilities declared, you can import them into any GYB template by using a simple Python import statement at the top of your template:
220
+
221
+
```py
222
+
%{
223
+
from gyb_utils import *
224
+
}%
225
+
226
+
print("The value of PI is ${PI}")
227
+
print("The square of 4 is ${square(4)}")
228
+
```
229
+
230
+
This allows you to maintain clean, reusable code in your GYB templates, avoiding redundancy and making your templates more maintainable.
0 commit comments