Coder Social home page Coder Social logo

emerald's People

Contributors

flyx avatar goldenreign avatar zacharycarter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

emerald's Issues

Undeclared identifier calling a mixin with a template parameter.

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.

Doesn't work anymore in current Nim

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

Usage in Jester?

I would like to use Emerald from Jester but I can't seem to figure out how. How would I use this in Jester?

Use Nim ident matching

Currently, all emerald-specific identifiers are matched case-sensitively. They should instead match just like all identifiers in Nim: Ignoring case and underscores.

Support data attributes on HTML tags

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:

  • Is the value required to be a table constructor literal?
  • If not, can it take a Table, a seq, something else as value?

Prepend and append regression in Nim 0.20

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

objName = genSym(nskParam, ":obj")

to

        objName = ident":obj"

fixes it.

Related issue in compiler is open in nim-lang/Nim#11214

Can't call parent template vars from inside mixin

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)

Can not format a "complex" expression in a nice way

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 =)

Using call_mixin inside child template results in SIGSEGV

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?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.