Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ examples/generated/
test/output/

# ci
.github/scripts/release/node_modules/
.github/scripts/release/node_modules/
out
.claude
44 changes: 40 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ This tool parses Rive (`.riv`) files and extracts component names, artboards, st
- Diffing `.riv` files for version control purposes
- Generating complete code components

The tool uses [Mustache](https://mustache.github.io/) templating for flexible output generation.
The tool supports both [Mustache](https://mustache.github.io/) and [Inja](https://github.com/pantor/inja) template engines for flexible output generation.

:warning: Note that this tool is still experimental and untested. Feedback and contributions are appreciated.

Expand All @@ -69,13 +69,49 @@ Example:

## Custom Templates

You can use custom Mustache templates for code generation:
You can use custom templates for code generation with either Mustache or Inja template engines:

```sh
./build/out/lib/release/rive_code_generator -i ./rive_files/ -o ./output/rive.json -t templates/json_template.mustache
# Using Mustache template
./build/out/lib/release/rive_code_generator -i ./rive_files/ -o ./output/rive.json -t templates/mustache/json_template.mustache

# Using Inja template
./build/out/lib/release/rive_code_generator -i ./rive_files/ -o ./output/rive.json -t templates/inja/json_template.inja -e inja
```

Sample templates are available in the [`templates`](./templates) directory.
Sample templates are available in the [`templates`](./templates) directory:
- [`templates/mustache/`](./templates/mustache/) - Mustache templates
- [`templates/inja/`](./templates/inja/) - Inja templates

### Filtering Private Elements

Use the `--ignore-private` flag to exclude elements from code generation based on naming conventions:

```sh
./build/out/lib/release/rive_code_generator -i ./rive_files/ -o ./output/rive.json -t templates/mustache/json_template.mustache --ignore-private
```

When enabled, the following elements will be skipped:
- Elements starting with `_` (underscore)
- Elements starting with `internal` (case-insensitive)
- Elements starting with `private` (case-insensitive)

This applies to:
- **Artboards**: Artboards with private names are excluded
- **Animations**: Animations with private names are excluded from their artboards
- **State Machines**: State machines with private names are excluded from their artboards
- **View Models**: View models with private names are completely excluded
- **View Model Properties**: Properties with private names are excluded from their view models

**Example:**
```
# These will be excluded when --ignore-private is used:
- Artboard: "_InternalArtboard"
- Animation: "private_animation"
- State Machine: "internalStateMachine"
- View Model: "_TestViewModel"
- Property: "privateProperty"
```

### Template Syntax

Expand Down
10 changes: 5 additions & 5 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ if [[ $RUN == true ]]; then
fi
if [[ $DEV == true ]]; then
pwd
# "$OUT/$EXECUTABLE" -i ../samples/signage_v03.riv -o out/rive_generated.dart -t ../templates/dart_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/rating.riv -o out/rive_generated.dart -t ../templates/dart_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive_generated.dart -t ../templates/dart_template.mustache
"$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive_viewmodel.dart -t ../templates/viewmodel_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive.json -t ../templates/json_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/signage_v03.riv -o out/rive_generated.dart -t ../templates/mustache/dart_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/rating.riv -o out/rive_generated.dart -t ../templates/mustache/dart_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive_generated.dart -t ../templates/mustache/dart_template.mustache
"$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive_viewmodel.dart -t ../templates/mustache/viewmodel_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive.json -t ../templates/mustache/json_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/nested_test.riv -o out/rive_generated.dart --help
# "$OUT/$EXECUTABLE" -i ../samples/ -o out/rive_generated.dart
fi
Binary file added dependencies/bin/premake5
Binary file not shown.
27 changes: 21 additions & 6 deletions examples/example.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Get the directory where this script is located
script_dir="$(cd "$(dirname "$0")" && pwd)"

# Define the possible paths
release_path="../build/out/lib/release/rive_code_generator"
debug_path="../build/out/lib/debug/rive_code_generator"
release_path="$script_dir/../build/out/lib/release/rive_code_generator"
debug_path="$script_dir/../build/out/lib/debug/rive_code_generator"

# Check for release build first, then debug build
if [[ -f "$release_path" ]]; then
Expand All @@ -15,9 +18,21 @@ fi
# Execute the generator with the stored path
"$generator_path" --help

# Generate a JSON file from all the sample .riv files using a custom template
"$generator_path" -i ../samples/ -o generated/rive_all.json -t ../templates/json_template.mustache
# Generate a JSON file from all the sample .riv files using Mustache template
"$generator_path" -i "$script_dir/../samples/" -o "$script_dir/generated/rive_all.json" -t "$script_dir/../templates/mustache/json_template.mustache"

# Generate a Dart file from one .riv file using Mustache template
"$generator_path" -i "$script_dir/../samples/rating.riv" -o "$script_dir/generated/rive_rating.dart" -t "$script_dir/../templates/mustache/dart_template.mustache"

# Generate Swift code using inja template with all sample .riv files
# Note: Using modular swift_example.inja with {% include %} directives
# Run from parent directory so includes can resolve correctly
(cd "$script_dir/.." && "$generator_path" -i "$script_dir/../samples/" -o "$script_dir/generated/rive_all.swift" -t "$script_dir/../templates/custom/Swift/swift_example.inja" -e inja)

# Generate a Dart file from one .riv file
"$generator_path" -i ../samples/rating.riv -o generated/rive_rating.dart -t ../templates/dart_template.mustache
# Generate Swift code using inja template for each individual .riv file
for riv_file in "$script_dir/../samples/"*.riv; do
filename=$(basename "$riv_file" .riv)
echo "Generating Swift code for $filename..."
(cd "$script_dir/.." && "$generator_path" -i "$riv_file" -o "$script_dir/generated/${filename}.swift" -t "$script_dir/../templates/custom/Swift/swift_example.inja" -e inja)
done

Loading