sourrust / karver Goto Github PK
View Code? Open in Web Editor NEWA simple template engine inspired by jinja2
License: BSD 3-Clause "New" or "Revised" License
A simple template engine inspired by jinja2
License: BSD 3-Clause "New" or "Revised" License
As of commit 7f62a10, karver only evaluates logic of the if statement as a check for a variable's existence.
Example:
{% if title %}
<title>{{ title }}</title>
{% else %}
<title>No Title</title>
{% endif %}
It would be nice to implement some of the suggested features list in said comment.
That list being:
Hello !
I played a bit with your package; I could run a simple program with json data so I am quite happy :)
However I could not build the tests.
I am working on the master branch (commit 187b0a2)
$ cabal configure --enable-tests
Resolving dependencies...
Configuring karver-0.1.0...
$ cabal build
Building karver-0.1.0...
Preprocessing library karver-0.1.0...
In-place registering karver-0.1.0...
Preprocessing test suite 'spec' for karver-0.1.0...
ghc: could not execute: hspec-discover
damien@grigny:~/src/karver(master)$ cabal list hspec
regards,
Damien
I wonder why the Object
constructor in the Value
data type holds a map of Text
to Text
, not Text
to Value
s?
data Value = Literal Text | Object (HashMap Text Text) | List (Vector Value)
It does not allow nested objects and is too limited for many use cases. I wonder if it is on purpose of something that can be considered as an improvment?
what do you think about the following approach.
renderTemplate'' :: Monad m => (Text -> m Text) -> HashMap Text Value -> Text -> m Text
where the function Text -> m Text
can be e.g. TIO.readFile . T.unpack
for the current behavior or return . fromJust . flip lookup myIncludesMap
for a pure approach.
of course these are partial, but so is renderTemplate
today. i will file a new bug about it separately. of course that signature should change as well, when a total function is desired.
In my template I am using the character '{' and it seems to cause the rest of the template to be ignored. Removing it everything is fine.
For expression parsers, like conditionParser
and loopParser
, the indentation is incorrect. And as a result, so are the tests when it comes to multi line parsing.
For test like this for loop, there shouldn't be an extra \n
and the indention is lost as well. Expected text should really be something like:
let expected = unlines [ "Some libraries used:"
, " * attoparsec"
, " * hspec"
]
The other example is the multi line if else statement. What should be expected is:
let expected = Right $ ConditionTok "title" " {{ title }}\n" " title\n"
This problem is also reference in issue #1.
right now a non-existent include raises an error and parse errors or lookup errors in the context will just render nonsensical text without the calling application being aware of it.
i would need renderTemplate
to return Either KarverError Text
with a suitable data KarverError = InvalidTemplate LineNo ColumnNo Text | NoSuchInclude Text | ...
.
i propose the following change to renderTemplate
, so that the current behavior is still possible. add another argument to renderTemplate
that decides what to do. e.g. renderTemplate :: (KarverError -> Either a Text) -> HashMap Text Value -> Text -> Either a Text
.
what do you think?
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.