Giter VIP home page Giter VIP logo

Comments (5)

gr1feel avatar gr1feel commented on August 27, 2024

This is code also doesn't work https://gist.github.com/gr1feel/5418016
I suppose what problem in parentheses.

from vash.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

I'm not sure I follow, those render just fine for me:

$ echo '<a onclick="alert('@model.text1')">click me!</a> ' | ./node_modules/vash/bin/vash --json '{"debug": false}' --render '{ "text1": "hello" }'
<a onclick="alert(hello)">click me!</a>
drewp@SpottedRadioFreeAir /tmp/vash-test$ node
> var vash = require('vash');
undefined
> var tpl = vash.compile("<a onclick=\"alert('@model.text1')\">click me!</a>")
undefined
> tpl({ text1: "hello" })
'<a onclick="alert(\'hello\')">click me!</a>'

Could you provide more details as to what "fail" means in your case?

from vash.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

Any other details you can provide?

from vash.

gr1feel avatar gr1feel commented on August 27, 2024

Hi,
Sorry for delay. Check this example (pages /test1 and /test2).

https://docs.google.com/file/d/0B0E2riyj_WiwVDBNMnpvTndBaFU/view

from vash.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

Ok, thanks for the examples, they really help.

The issue is that a <br /> tells Vash to enter and immediately exit markup mode and return to the previous mode, which is this case is a code block. Thus Text1: and Text2: are being interpreted as code instead of markup. Vash requires that any actual content be wrapped in either html tags (or the fake <text> tag) or an @: for a single line.

There is another issue too in the same vein. The parentheses in (@model.text2) are being interpreted as code. When compiled, it looks like this:

(__vbuffer.push(html.escape(model.text2).toHtmlString());)

A semicolon is not valid JS within the grouping parentheses, so this is actually not even compiling. The error reporting is giving you a false sense of where the error is happening because it's not actually at runtime, but rather at compile time. This is just bad reporting that I've been meaning to fix, and have opened an issue to keep track of it (#22).

Your immediate solution:

@html.block('content', function(model){

  @* Remember that <text> tags are not rendered! *@
  <text>
  <br/>Text1: @model.text1
  <br/>Text2: @model.text2

  <br/>@model.child.xxx


  <span>hi</span> (@model.text2)
  </text>
})

There are others, like using @: on each line (pretty gross, just an example):

@html.block('content', function(model){

  @:<br/>Text1: @model.text1
  @:<br/>Text2: @model.text2

  <br/>@model.child.xxx


  @:<span>hi</span> (@model.text2)
})

from vash.

Related Issues (20)

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.