flyx / emerald Goto Github PK
View Code? Open in Web Editor NEWHTML5 templating engine for Nimrod
License: Do What The F*ck You Want To Public License
HTML5 templating engine for Nimrod
License: Do What The F*ck You Want To Public License
I've tried this on 0.16.0 and the development branch of Nim.
Here's the code:
import
emerald, streams
proc mixin_with_params(content: string) {.html_mixin.} =
p: content
proc genSummaryPage(thingy: string) {.html_templ.} =
body:
call_mixin mixin_with_params(thingy)
proc doit() =
let
outfs = newFileStream(stdout)
t = newGenSummaryPage()
t.thingy = "blah"
t.render(outfs)
doit()
Compiling it gives me this error:
hg.nim(7, 37) template/generic instantiation from here
hg.nim(9, 34) Error: undeclared identifier: 'thingy'
It seems specific to passing the thingy
parameter to the mixin. Replacing call_mixin mixin_with_params(thingy)
with call_mixin mixin_with_params("a string")
works fine, and I can reference thingy
in other parts of the template. Just not as a mixin parameter.
Current Nim from devel branch, import emerald
throws this:
/home/deen/.nimble/pkgs/emerald-0.2.2/emerald/html.nim(299, 32) Error: expression 'quit "[emerald] " & lineInfo(node) & ": Unexpected " &
"command (expected replace, prepend or append)" & ": \"" &
$ident_name(node[0]) & "\"", 1' is of type 'NimNode' and has to be discarded
I would like to use Emerald from Jester but I can't seem to figure out how. How would I use this in Jester?
Currently, all emerald-specific identifiers are matched case-sensitively. They should instead match just like all identifiers in Nim: Ignoring case and underscores.
HTML allows the usage of arbitrary data-*
attributes on any tag. emerald should support that. Possible implementation:
emerald:
p(data={str="foo", num=5}): "content"
output:
<p data-str="foo" data-num="5">content</p>
Open questions:
Table
, a seq
, something else as value?It's a regression in compiler that started between version 0.19 and 0.20.
This code compiled in Nim 0.20 crashes compiler:
import emerald
proc parent() {.html_templ.} =
block content:
discard
proc child() {.html_templ: parent.} =
prepend content:
h1(): "Hello!"
append content:
h1(): "Hello!"
/home/konrad/.nimble/pkgs/emerald-0.2.3/emerald/html.nim(660, 36) Warning: use {.base.} for base methods; baseless methods are deprecated [UseBase]
/home/konrad/.nimble/pkgs/emerald-0.2.3/emerald/html.nim(345, 25) Error: internal error: environment misses: :obj
Changing this line
Line 345 in 8b443ef
objName = ident":obj"
fixes it.
Related issue in compiler is open in nim-lang/Nim#11214
import emerald
proc mySection() {.html_mixin.} =
section:
h1: title
put mixin_content()
proc parent(title: string) {.html_templ.} =
block content:
h1: title
proc templ(numItems: int) {.html_templ: parent.} =
append content:
call_mixin mySection():
p: "Content"
Result:
../emerald/src/emerald/html.nim(343, 25) Error: expression ':obj427134' has no type (or is ambiguous)
import emerald, json
proc homeView(test: JsonNode) {.html_templ.} =
html(lang = "en"):
body:
p: test["str"].str # This works
p: test["int"].num # This doesnt
p: $(test["int"].num) # This doesnt as well, but differently
p: "" & $(test["int"].num) # Ok, this works, but looks strange =)
var
a = ""
b = 0
strong(a) # fails
strong($b) # also fails
For once defer
is now a keyword. The rest seems to be macro-related.
import emerald
proc mySection(title: string) {.html_mixin.} =
section:
h1: title
put mixin_content()
proc parent() {.html_templ.}=
block content:
h1: "Content:"
proc templ(numItems: int) {.html_templ: parent.} =
append content:
html(lang="en"):
body:
call_mixin mySection("First section"):
p: "Content"
call_mixin mySection("Second section"):
p: "More content"
Result:
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
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.