vlthr / levee Goto Github PK
View Code? Open in Web Editor NEWControlled rendering of Liquid templates.
License: MIT License
Controlled rendering of Liquid templates.
License: MIT License
Liquid custom tags allow each tag to define the structure of its arguments entirely freely, so a filter must handle the parsing of its own arguments. It would be nice if this complexity was not exposed to the user of the library, since the vast majority of filters would not it.
Filters could possibly be represented as a partial function, defined something like follows:
@Filter
case class MyFilter() {
def apply() {
case (input: Value, a: Int, b: Int) => ...
case (input: Value, args: String) => ...
}
}
In the Filter macro, matching String -> (Int, Int) and String -> String parsers could be generated automatically, such that the filter above would work when called with:
{{ "Hello world" | myfilter: "xxx" }}
or
{{ "Hello World" | myfilter: 1, 2 }}
Parsing:
Evaluation/Rendering:
Rendering a template should not error out on the first exception but rather collect as many errors as is meaningful and then report them to the user.
Possible solutions:
{{ true > false }}
will currently yield true
, but in liqp the same tag renders to false
.
Something like sbt testExamples
to render all the template files in a given folder, then comparing the result with another file containing the expected output. Then sbt genExamples
to regenerate the expected outputs.
Some tags and filters such as slice
can have an optional positional argument.
dottydoc-templating (de-submodule) โ sbt compile
[warn] Executing in batch mode.
[warn] For better performance, hit [ENTER] to switch to interactive mode, or
[warn] consider launching sbt without any commands, or explicitly passing 'shell'
[info] Loading global plugins from /home/von/.sbt/0.13/plugins
[info] Loading project definition from /home/von/bb/dottydoc-templating/project
[info] Set current project to dottydoc-templating (in build file:/home/von/bb/dottydoc-templating/)
[warn] Binary version (0.1.2-RC1) for dependency ch.epfl.lamp#scala-library;0.1.2-RC1
[warn] in macros#macros_0.1;0.1-SNAPSHOT differs from Scala binary version in project (0.1).
[info] Updating {file:/home/von/bb/dottydoc-templating/}macros...
[info] Resolving ch.epfl.lamp#dotty-library_0.1;0.1.2-RC1 ...
[warn] circular dependency found: ch.epfl.lamp#scala-library;0.1.2-RC1->ch.epfl.lamp#dotty-library_0.1;0.1.2-RC1->...
[warn] circular dependency found: ch.epfl.lamp#dotty-library_0.1;0.1.2-RC1->ch.epfl.lamp#scala-library;0.1.2-RC1->...
[info] Resolving my.fengy#gestalt_2.11;0.1.1 ...
[warn] module not found: my.fengy#gestalt_2.11;0.1.1
[warn] ==== local: tried
[warn] /home/von/.ivy2/local/my.fengy/gestalt_2.11/0.1.1/ivys/ivy.xml
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/my/fengy/gestalt_2.11/0.1.1/gestalt_2.11-0.1.1.pom
[warn] ==== sonatype-snapshots: tried
[warn] https://oss.sonatype.org/content/repositories/snapshots/my/fengy/gestalt_2.11/0.1.1/gestalt_2.11-0.1.1.pom
[warn] ==== sonatype-releases: tried
[warn] https://oss.sonatype.org/content/repositories/releases/my/fengy/gestalt_2.11/0.1.1/gestalt_2.11-0.1.1.pom
[warn] ==== typesafe-ivy-releases: tried
[warn] https://repo.typesafe.com/typesafe/ivy-releases/my.fengy/gestalt_2.11/0.1.1/ivys/ivy.xml
[info] Resolving org.scala-lang.modules#scala-xml_2.11;1.0.1 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: my.fengy#gestalt_2.11;0.1.1: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Unresolved dependencies path:
[warn] my.fengy:gestalt_2.11:0.1.1 (/home/von/bb/dottydoc-templating/build.sbt#L26)
[warn] +- macros:macros_0.1:0.1-SNAPSHOT
sbt.ResolveException: unresolved dependency: my.fengy#gestalt_2.11;0.1.1: not found
[trace] Stack trace suppressed: run last macros/*:update for the full output.
[error] (macros/*:update) sbt.ResolveException: unresolved dependency: my.fengy#gestalt_2.11;0.1.1: not found
[error] Total time: 3 s, completed Jun 9, 2017 4:31:16 PM
The error seems to be related to a mismatch in dotty versions. Doing an sbt publishLocal
in gestalt publishes to:
[info] published ivy to /home/von/.ivy2/local/me.fengy/gestalt_0.4/0.1.1/ivys/ivy.xml
Implementing both filters and custom tags with arguments turns out to be fairly cumbersome due to all the type checking required to make the filter robust - especially if trying to catch all detectable errors before returning.
Having a somewhat cumbersome API for defining these in a well-behaved way is not necessarily a problem for code that is internal to the project, but the current API is not easily approachable by users and is also fairly verbose and boilerplate heavy. Fixing this now would both allow for user-extensibility and would also make implementing the remaining standard set of filters and tags easier.
A filter application has the following form:
{{ input | filterName: arg0, arg1 }}
The filter must be able to (where possible) simultaneously detect all instances of the following:
Filters always take a single value as input, so type checking should amount simply to checking which subclass of value was given as input. Error message should at least specify what the invalid type is, but preferably also what the expected type/types are.
A given filter may be defined for a variable number of arguments, and if an invalid number of arguments is given, the error message should preferably be able to give some indication of how to fix it.
If a filter is given the correct number of arguments but of the wrong value types, the error message should specify the invalid type and if possible also an expected type.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.