No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
COPYING
README.md
build.sbt

README.md

Rellyfiler Template

Rellyfiler Template is a minimalistic tool for long text forms with formal parameters/variables definition and template provisioning, following the builder pattern.

Free order of Formal Parameters, Provisioning and Template source

Since this tool uses the builder pattern, the user is free to chose the order in which he defines formal parameters, provisioning and template source itself. This makes composition and rendering of templates easy, transparent and enhances the long term maintainability.

Practice shows that having the (potentially very long) template text at the end of an coding block can help to keep it lucid.

Strict model-view separation

Model and view are strictly separated, so complexity keeps low, even when template texts get bigger.

Inline Templates

Since Scala is offering perfect legacy multi-line string embedding, there is no need for external template files. Anything can be kept in Scala source code itself.

Minimal formalization

Currently, only placeholder IDs are formalized, this ensures that template source text and provisioning of parameter values stay consistent.

Consistentency Checks

Formal Parameters, Provisioning and Template source are building three corner stones, which are interwined with each other.

There are important consistency checks before and while rendering the output.

For details, please refer to Template test cases.

Low footprint, few dependencies

The source code for this library is ~ 100 lines of code (LOC).

Remarks

  • Line Endings are OS-dependent, no conversion takes place
  • Multiple occurences of the same placeholder are provisioned simultaneous, at once
  • Provisionings are checked against the formal paramters definition
  • Excessive placeholders in template text, which are not definied as placerholders, are checked
  • The placeholder escaping is done by « and ». You can enter those symbols on your keyboard by Alt-0171 («) and Alt-0187 (»)

Example

package rellyfiler_template_demo

import punychar.rellyfiler.template.Template

object generator.Test {

   def main(args: Array[String]): Unit = {

      Template.create
        .formalParameter("a")
        .formalParameter("b")
        .provision(t => t
          .add("a", "Ok!")
          .add("b", "End of story"))
        .template(
           """
             |This is a short story. Line 1. «a»
             |This is a short story. Line 2. «a»
             |This is a short story. Line 3. «a»
             |This is a short story. Line 4. «a»
             |This is a short story. Line 5. «a»
             |«b»
             |""".stripMargin)
        .self(t => println(t.render))
   }
}

produces

This is a short story. Line 1. Ok!
This is a short story. Line 2. Ok!
This is a short story. Line 3. Ok!
This is a short story. Line 4. Ok!
This is a short story. Line 5. Ok!
End of story