Git Product home page Git Product logo

pug2svelte's Introduction

Archived. Check out svelte-preprocess for more advanced uses.

pug2svelte

Build Status npm version Dependencies Status

Use svelte with pug syntax.

Install

npm i -D pug pug2svelte@latest
let pug2svelte = require('pug2svelte')

pug2svelte('<template>p Hello World!</template>')
// <p> Hello World!</p>

Supported Svelte syntaxes

// attribute
a(href='page/{p}') page {p}

button(disable={!clickable})
button(disable='{number === 42}')
button({disable})
button(on:click|once={handler})

// spread attributes
Widget({...things})

// if
{#if answer === 42}
  p what was the question?
  
// if else
{#if porridge.temperature > 100}
  p too hot!
{:else if 80 > porridge.temperature}
  p too cold!
{:else}
  p just right!
  
// other svelte blocks
{#each todos as todo}
  p {todo.text}
{:else}
  p No tasks today!

{#await promise}
  p waiting for the promise to resolve...
{:then value}
  p The value is {value}
{:catch error}
  p Something went wrong: {error.message}
  
// nested blocks
div1
  {#if}
    div2
    {#each}
      {#await}

// <div1>
//   {#if}
//     <div2></div2>
//     {#each}
//       {#await}
//       {/await}
//     {/each}
//   {#if}
// </div1>

Use with Rollup

// rollup.config.js
import svelte from 'rollup-plugin-svelte'
import pug2svelte from 'pug2svelte'

export default {
  plugins: [
    svelte({
      extensions: ['.svelte'],
      preprocess: {
        markup: ({ content }) => ({ code: pug2svelte(content) })
      },
      ...
    })
  ]
}
// app.svelte
<template>p Hello {name}!</template>

<script>
  let name = 'World'
</script>
<!-- Hello World! -->

Parse from pug file

// rollup.config.js
...
extensions: ['.pug'],
preprocess: {
  markup: ({ content }) => ({ code: pug2svelte(content, { pug: true }) })
}
...
// app.pug
p Hello {name}!

script.
  let name = 'World'

Pug render options

You can also pass any options of pug.render()

pug2svelte(content, {
  pretty: true
  })

License

MIT

pug2svelte's People

Contributors

tienpv222 avatar

Watchers

 avatar

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.