static-dev / spike

A modern static build tool, powered by webpack
http://spike.js.org
Other
470 stars 29 forks source link

How write JSON on data attributes #79

Closed sibinx7 closed 6 years ago

sibinx7 commented 7 years ago

I need to add JSON on data attributes, but this not working. I use pug template language

  1. Problem One

    <video
    id="vid1"
    class="video-js vjs-default-skin"
    controls
    autoplay
    width="640" height="264"
    data-setup='{ "techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "https://www.youtube.com/watch?v=xjS6SftYQaQ"}] }'
    >
    </video>
  2. Problem 2

    - location = {"lat":"-25.363", "lng":"131.044"}
    #job-description-service-map(data-location=JSON.stringify(location))

    Result

screenshot from 2017-11-09 21-12-58

jescalan commented 7 years ago

This would be an issue for pug, not here in spike. However, I'd recommend encoding your data to base64 so that you don't have a parsing issue with quotes, or escaping all quotes. Reshape will convert to all double quotes in the output, as you can see here. Switching single and double quotes in this specific instance should also solve the issue.