How theurw101/erb-to-epp works
Purpose and Entry Points
This Rust project converts Embedded Ruby (.erb) templates to Puppet Embedded Puppet (.epp) syntax. It supports a native CLI and a browser-delivered WebAssembly build. The sole implementation entry point is src/main.rs; the browser host is index.html.
Native CLI Boundary
The CLI accepts an input ERB path and optionally an output EPP path. It reads the source template, applies conversion stages, then writes converted text to stdout or the requested destination. Native packaging and dependencies are defined by Cargo.toml.
Paths:
• src/main.rs
• Cargo.toml
Browser / Wasm Boundary
The same Rust conversion logic is compiled with wasm-pack --target web and invoked from the static browser UI. The HTML page supplies the user interaction and loads the generated Wasm package; styling is separate. The web path intentionally does not expose parameter-tag generation.
Paths:
• index.html
• src/main.rs
• themes/styles.css
Template Parsing and Preservation
Conversion operates on template text while distinguishing ERB tag content from literal text. This boundary is essential: Ruby-instance-variable markers (@) are converted only inside template tags, preserving ordinary content such as email addresses. ERB whitespace trim delimiters (<%-, -%>) are retained through output generation.
Paths:
• src/main.rs
EPP Control-Flow Translation
Conditional ERB constructs are rewritten into EPP block syntax: if, unless, elsif, else, and end become brace-delimited Puppet expressions, including EPP’s else if form. This stage must preserve source ordering and tag delimiters while tracking opening and closing blocks.
Paths:
• src/main.rs
Expression and Iteration Translation
Expressions are normalized from Ruby-oriented to Puppet-oriented syntax: instance variables become $ variables; missing variable sigils inside tags are added; scope.function_versioncmp(...) is converted to versioncmp(...). Simple .each do |...| constructs become EPP iteration blocks, while guarded empty-hash iteration patterns gain explicit existence/type checks before iterating.
Paths:
• src/main.rs
Parameter Declaration Generation
For native conversion, discovered input variables can be emitted as an EPP parameter tag at the beginning of a new template. The generated declaration includes inferred Puppet types and variable names. This is a distinct output-enrichment stage from core text conversion and is unavailable in the WebAssembly UI.
Paths:
• src/main.rs
Components 14
Native CLI
- Cargo package · Defines native dependencies and Wasm build inputs.
Cargo.toml - CLI entry · Accepts ERB input and optional EPP output paths.
src/main.rs - ERB source
- Parameter generation · Infers variables and prepends an EPP parameter tag.
src/main.rs - EPP output
Conversion Core
- Conversion entry · Shared by native and WebAssembly execution.
src/main.rs - Tag-aware parsing · Separates ERB tags from literal text.
src/main.rs - Literal preservation · Keeps non-tag text and ERB trim delimiters intact.
src/main.rs - Control-flow rewrite · Converts conditional tags into brace-delimited EPP blocks.
src/main.rs - Expression rewrite · Normalizes variables and versioncmp calls inside tags.
src/main.rs - Iteration rewrite · Converts each loops and guards empty-hash iteration.
src/main.rs
Browser / Wasm
- Browser UI · Collects template input and invokes the generated Wasm package.
index.html - Wasm conversion module · Compiles the shared Rust converter with wasm-pack.
src/main.rs - UI styles
themes/styles.css
Connections 16
- Cargo package → CLI entry: packages
- ERB source → CLI entry: input path
- CLI entry → Conversion entry: converts
- Conversion entry → Tag-aware parsing: parses
- Tag-aware parsing → Literal preservation: preserves literals
- Tag-aware parsing → Control-flow rewrite: translates control tags
- Tag-aware parsing → Expression rewrite: translates expressions
- Expression rewrite → Iteration rewrite: rewrites loops
- Literal preservation → Parameter generation: converted template
- Control-flow rewrite → Parameter generation: converted tags
- Iteration rewrite → Parameter generation: converted loops
- Parameter generation → EPP output: writes
- Browser UI → Wasm conversion module: loads and invokes
- Wasm conversion module → Conversion entry: uses shared conversion
- UI styles → Browser UI: styles
- Conversion entry → EPP output: Web output without parameters