-
Notifications
You must be signed in to change notification settings - Fork 9
Integrate Inja Code Generation #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cerupcat
wants to merge
18
commits into
rive-app:main
Choose a base branch
from
Whatnot-Inc:wn/codegen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* add-data-binding: refactor: prefer camelCase chore: fix build warnings feat: add windows build scripts chore: bump rive runtime submodule chore: clang formatting feat: add data binding
…nV3.riv. The root cause was missing null pointer checks in three places: 1. Nested ViewModel Property Access (main.cpp:691-693) Problem: Chained calls viewModel->createInstance()->propertyViewModel() without null checks Fix: Added null checks for createInstance(), propertyViewModel(), instance(), and viewModel() 2. Enum Property Access (main.cpp:730-736) Problem: Chained calls accessing enum properties without null checks Fix: Added null checks for createViewModelInstance(), propertyValue(), and all subsequent property accesses 3. Default Value Property Access (main.cpp:786-818) Problem: Accessing property values without null checks for boolean, number, string, and color types Fix: Added null checks for each property value access 4. Nested Artboard Instance Access (main.cpp:525) Problem: nested->artboardInstance() could return null causing crash during recursion Fix: Added null check before recursively calling getNestedTextValueRunPathsFromArtboard() 5. Default Artboard Instance Access (main.cpp:882) Problem: defaultArtboard->instance()->defaultStateMachine() without null check on instance() Fix: Added null check for instance() before accessing defaultStateMachine()
Resolved conflicts: - build/build.sh: Kept template paths with mustache/ subdirectory structure - src/main.cpp: Kept Inja integration and metadata features - Removed duplicate templates/viewmodel_template.mustache (we have templates/mustache/viewmodel_template.mustache)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Integrate Inja Template Engine
Overview
This PR adds support for the Inja template engine as an alternative to Mustache, providing more powerful templating capabilities for code generation while maintaining full backward compatibility with existing Mustache templates.
Motivation
Mustache templating is limited in terms of logic and requires the data source to provide granular details (e.g., array size counts, whether a property exists, last element detection). Inja is a modern C++ templating language that provides more control flow and expressions without requiring the data source to be overly detailed.
Key Features
1. Dual Template Engine Support
-e, --engineflag to choose betweenmustache(default) andinja{% if condition %}{% for item in items %}withloop.is_first,loop.is_lastlength(),upper(),lower(), etc.{% include "partial.inja" %}2. Enhanced Metadata & Relationships
3. Private Element Filtering
--ignore-privateflag to exclude elements based on naming conventions:_(underscore)internal(case-insensitive)private(case-insensitive)4. Modular Swift Templates
{% include %}feature5. Template Organization
templates/mustache/- Mustache templatestemplates/inja/- Inja templatestemplates/custom/Swift/- Modular Swift template exampleChanges Summary
37 files changed, 32,265 insertions(+), 63 deletions(-)
Core Changes
TemplateEngineenum and rendering logicshouldIncludeElement()for private filteringTemplate Infrastructure
Templates & Examples
Testing & Documentation
Usage Examples
Basic Inja Template Usage
# Generate code using Inja template ./rive_code_generator -i samples/rating.riv -o output.swift \ -t templates/custom/Swift/swift_example.inja -e injaWith Private Filtering
# Exclude private elements ./rive_code_generator -i samples/ -o output.dart \ -t templates/inja/dart_template.inja -e inja --ignore-privateModular Templates with Includes
The Swift templates demonstrate using includes for modular organization:
Testing
All 7 tests pass:
Backward Compatibility
Additional Improvements
Note: This implementation maintains full compatibility with upstream while adding powerful new templating capabilities that don't require data source modifications.