Skip to content

Commit

Permalink
(chore): Add DocC
Browse files Browse the repository at this point in the history
  • Loading branch information
N3v1 committed Oct 23, 2024
1 parent cd00fa5 commit cd4b66e
Show file tree
Hide file tree
Showing 11 changed files with 416 additions and 2 deletions.
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@

*.DS_Store
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
21 changes: 21 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "scribble-gyb",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "scribble-gyb",
targets: ["scribble-gyb"]),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "scribble-gyb"),

]
)
19 changes: 19 additions & 0 deletions Sources/scribble-gyb/Documentation.docc/Changelog/Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog

A concise record of notable changes and updates to Scribble-GYB.

@Metadata {
@PageImage( purpose: icon, source: "starbubble", alt: "A background icon")
@PageColor(yellow)
}

## v0.1.0 (Stable Release)

**What's New:**

We are excited to announce the stable release of Scribble-GYB, designed to assist developers in maintaining a consistent and DRY (Don't Repeat Yourself) codebase. In this release, we have added support for the following:

- Initial release of Scribble GYB
- Added documentation guide for GYB

**Full Changelog:** [https://github.com/ScribbleLabApp/scribble-gyb/commits/0.1.0](https://github.com/ScribbleLabApp/scribble-gyb/commits/0.1.0)
11 changes: 11 additions & 0 deletions Sources/scribble-gyb/Documentation.docc/Customization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Customization

<!--@START_MENU_TOKEN@-->Summary<!--@END_MENU_TOKEN@-->

## Overview

<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->

### Section header

<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->
30 changes: 30 additions & 0 deletions Sources/scribble-gyb/Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ``scribble_gyb``

Automates boilerplate code generation using templates with embedded Python for Swift, Objective-C, and Objective-C++

@Metadata {
@DisplayName("Scribble GYB")
@TitleHeading("Tool")
@PageColor(orange)
@SupportedLanguage(swift)
@SupportedLanguage(objc)
@SupportedLanguage(objc++)
}

## Overview

`scribble-gyb` is a flexible tool for automating the generation of repetitive code patterns in ScribbleLabApp projects. It enables developers to integrate Python logic into template files for Swift, Objective-C, and Objective-C++ source code, reducing manual coding and ensuring consistency across the codebase. By leveraging `scribble-gyb`, teams can maintain DRY (Don't Repeat Yourself) principles, improve productivity, and minimize the risk of errors. The tool supports complex logic, dynamic variable substitution, and loops, making it an essential utility for large-scale projects requiring reusable components and clean code organization.

## Topics

### Essentials

- <doc:Installation>
- <doc:Customization>
- <doc:Processing>
- <doc:Changelog>

### Syntax

- <doc:Syntax>
- <doc:Supported-Types>
29 changes: 29 additions & 0 deletions Sources/scribble-gyb/Documentation.docc/Installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Installation

A comprehensive guide to integrating Scribble GYB into your project for seamless boilerplate code generation.

## Overview

Scribble GYB can be integrated into your project using two primary methods: **(a)** *as a Git submodule* or **(b)** by *manually copying the necessary files* into your project directory. Choose the option that best fits your development workflow.

@TabNavigator {
@Tab("Git Submodule") {
To use Scribble GYB, add it to your project either as a Git submodule or by manually copying the files into your project directory. For the Git submodule option, navigate to your project and run the following commands:

```bash
git clone https://github.com/ScribbleLabApp/scribble-gyb.git
git submodule init
git submodule update
```
}

@Tab("Copying Source Files") {
For manual integration, clone the repository and copy the contents into a designated directory within your project:

```bash
git clone https://github.com/ScribbleLabApp/scribble-gyb.git
mkdir -p /path/to/your-project/utils
cp -R scribble-gyb/* /path/to/your-project/utils/
```
}
}
60 changes: 60 additions & 0 deletions Sources/scribble-gyb/Documentation.docc/Processing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Processing GYB Sources

Generate source code using Scribble GYB

## Overview

Scribble GYB (Generate Your Boilerplate) provides developers with the capability to dynamically generate Swift, Objective-C, and Objective-C++ source code from GYB templates. These templates incorporate Python code, allowing for complex logic and variable manipulation that can yield highly customizable source files. This documentation outlines the steps necessary to process GYB templates, highlighting key considerations and the necessary configurations for successful execution.

### Prerequisites

Before you can generate source code using Scribble GYB, ensure you have the following prerequisites:

- **GYB Executable:** The gyb executable must be available in the specified directory `(./utils/gyb)` as indicated in the `generate_sources.sh` script. To install `scribble-gyb` see **<doc:Installation>**.
- **GYB Template Files:** Your GYB template files must be organized with the appropriate file extensions based on the target programming language, as outlined in the table below.

| Language | GYB Extension |
| :-----------: | :---------------: |
| Swift | `.swift.gyb` |
| Objective-C | `.m.gyb` |
| Objective-C++ | `.mm.gyb` |

### Setting Up Your Environment

Before running the script, ensure your project directory structure is correctly set up. The `generate_sources.sh` script expects the following layout:

- Your GYB templates should be located in the `Sources` or `Tests` directories of your project.
- Ensure that you have permission to execute the script. You can modify the permissions using the following command:

```sh
chmod +x generate-sources.sh
```

### Running the GYB Generation Script

To process your GYB templates and generate source files, execute the [`generate_sources.sh`](https://github.com/ScribleLabApp/scribble-gyb/bloob/main/generate-sources.sh) script provided in the repository. This script performs the following key operations:

1. **Navigating to the Project Directory:** The script sets the root of the project directory to the parent directory of the script's location.
2. **Defining the GYB Executable Path:** The script specifies where to find the gyb executable.
3. **Handling Line Directives:** The script allows the option to disable or enable line directives in GYB output, depending on whether you want to include file and line information for debugging purposes.
4. **Creating a Temporary Directory:** A temporary directory is created to store intermediate files during the generation process, which is cleaned up after execution.
5. **Finding GYB Template Files:** The script searches the `Sources` and `Tests` directories for files with the `.swift.gyb`, `.m.gyb`, and `.mm.gyb` extensions [`(see above)`](#prerequisites).
6. **Generating Output Files:** For each found GYB file, the script executes the GYB command to produce the corresponding source file in an `autogenerated` subdirectory.
To run the script, simply execute the following command in your terminal:
```sh
./generate-sources.sh
```
### Output Generation
After running the script, the generated files will be saved in subdirectories under the original `Sources` or `Tests` directories, preserving the original directory structure. The generated source files will have the same name as the GYB templates, but without the `.gyb` extension.
### Important Considerations
- **Adjusting the Script for Source Locations:** If your GYB templates are located in a different directory, you will need to adjust the find command within the script to point to the correct paths.
- **Keeping GYB Templates Updated:** The script automatically updates the generated files only when changes are detected in the GYB templates, preventing unnecessary overwrites and preserving your workflow.
- **Removing Obsolete Files:** The script includes functionality to clean up any autogenerated files that no longer have a corresponding GYB template, helping maintain a tidy project directory.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions Sources/scribble-gyb/Documentation.docc/Supported Types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Supported Types

A comprehensive guide to the supported data types in Scribble GYB for efficient boilerplate code generation.

## Overview

GYB (Generate Your Boilerplate) is designed to simplify code generation by supporting a variety of data types across Swift, Objective-C, and Objective-C++. Below is a comprehensive overview of the supported types, along with their descriptions, valid ranges, and examples for easy reference.

@TabNavigator {
@Tab("Swift GYB") {
### Supported Swift Types

**Swift** is a powerful programming language that supports a wide range of data types. Here are the key types available in GYB:

| **Type** | **Description** | **Value Range** | **Example** |
|----------------|---------------------------------------------------|---------------------------------------------|----------------------------|
| `String` | A sequence of characters representing textual data. Ideal for handling words, sentences, and any string manipulations. | N/A | `"Hello, World!"` |
| `Int` | A signed integer type used for whole numbers. It can represent both positive and negative values and is suitable for general-purpose arithmetic. | `-9223372036854775808` to `9223372036854775807` | `42` |
| `Int8` | An 8-bit signed integer, useful for storing small integer values. It provides a limited range, making it suitable for scenarios with constrained memory usage. | `-128` to `127` | `Int8(127)` |
| `Int16` | A 16-bit signed integer, providing a larger range than `Int8`. It is often used for situations where moderate integer values are necessary. | `-32768` to `32767` | `Int16(32767)` |
| `Int32` | A 32-bit signed integer, which can hold larger values than `Int16`, making it suitable for a broader range of applications. | `-2147483648` to `2147483647` | `Int32(2147483647)` |
| `Int64` | A 64-bit signed integer that can accommodate very large integers, useful for calculations requiring high precision. | `-9223372036854775808` to `9223372036854775807` | `Int64(9223372036854775807)` |
| `UInt8` | An 8-bit unsigned integer, suitable for small non-negative values. It is often used in scenarios where negative values are not needed. | `0` to `255` | `UInt8(255)` |
| `UInt16` | A 16-bit unsigned integer, allowing for moderately sized non-negative integers. This type is beneficial for scenarios like counting or indexing. | `0` to `65535` | `UInt16(65535)` |
| `UInt32` | A 32-bit unsigned integer, providing a larger range of non-negative values than `UInt16`. Ideal for applications where larger counts are required. | `0` to `4294967295` | `UInt32(4294967295)` |
| `UInt64` | A 64-bit unsigned integer, accommodating very large non-negative integers, suitable for extensive numerical computations. | `0` to `18446744073709551615` | `UInt64(18446744073709551615)` |
| `Bool` | A Boolean type representing truth values, which can either be `true` or `false`. This type is commonly used in conditional statements. | `true` or `false` | `true` |
| `Double` | A double-precision floating-point number that can handle a wide range of values, making it suitable for high-precision calculations, such as scientific computations. | ~±1.7e308 | `3.14159` |
| `Float` | A single-precision floating-point number, used for calculations where less precision is acceptable. It's generally used in graphics and simple calculations. | ~±3.4e38 | `2.71828f` |

}

@Tab("ObjC GYB") {
### Supported Objective-C Types

**Objective-C** supports a variety of types that are essential for developing robust applications. Below are the supported types in GYB:

| **Type** | **Description** | **Value Range** | **Example** |
|----------------|---------------------------------------------------|---------------------------------------------|----------------------------|
| `NSString` | Represents a string object in Objective-C. It allows for rich string manipulation and is essential for handling text. | N/A | `@"Hello, World!"` |
| `NSInteger` | A signed integer type, commonly used for array indexing and general numeric operations in Objective-C. It adapts to the platform's word size, providing flexibility. | `-9223372036854775808` to `9223372036854775807` | `NSInteger value = 42;` |
| `NSUInteger` | An unsigned integer type, used for non-negative counts, particularly when dealing with collections. It is guaranteed to never be negative, making it ideal for indexing. | `0` to `18446744073709551615` | `NSUInteger count = 10;` |
| `BOOL` | Represents a Boolean value, allowing for true or false states in Objective-C. Commonly used in conditional logic and state management. | `YES` or `NO` | `BOOL isActive = YES;` |
| `CGFloat` | A floating-point type, typically used for UI measurements. It adapts its precision based on the platform, providing flexibility in graphics calculations. | Varies depending on the platform | `CGFloat width = 100.0;` |
}

@Tab("ObjC++ GYB") {
### Supported Objective-C++ Types

**Objective-C++** combines the features of C++ with those of Objective-C, allowing for a rich set of types:

| **Type** | **Description** | **Value Range** | **Example** |
|----------------|---------------------------------------------------|---------------------------------------------|----------------------------|
| `std::string` | A string class from the C++ Standard Library, providing powerful string manipulation capabilities. It is essential for modern C++ applications. | N/A | `std::string name = "John";` |
| `int` | A signed integer type, standard in C++. It provides a basic numeric type for general arithmetic operations. | `-2147483648` to `2147483647` | `int age = 30;` |
| `unsigned int` | An unsigned integer type used for non-negative integer values. This is commonly used in counting operations and array indexing. | `0` to `4294967295` | `unsigned int count = 5;` |
| `bool` | A Boolean type that represents truth values, either `true` or `false`. It is widely used in conditional expressions and logical operations. | `true` or `false` | `bool isValid = true;` |
| `float` | A single-precision floating-point number in C++, suitable for simpler numerical calculations where high precision is not critical. | ~±3.4e38 | `float pi = 3.14f;` |
| `double` | A double-precision floating-point number that provides higher precision for complex calculations, often used in scientific computations. | ~±1.7e308 | `double e = 2.71828;` |
}
}

### Conclusion

Understanding the supported data types in GYB empowers developers to efficiently generate boilerplate code that is both type-safe and optimized for performance. By leveraging these types, you can ensure that your generated code meets the specific requirements of your Swift, Objective-C, or Objective-C++ projects, enhancing code quality and maintainability.


## See Also

- <doc:Syntax>
Loading

0 comments on commit cd4b66e

Please sign in to comment.