npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-awesome-pug

v0.1.3

Published

Enhances the usage of pug html-templates for Svelte

Downloads

206

Readme

svelte-awesome-pug

Using the Svelte Preprocessor to process Pug can look a bit funky.

svelte-awesome-pug unfunkies it in a good way. Here's a video showcasing the ease of use working with svelte-awesome-pug

Plans

Install

npm i -D svelte-awesome-pug

Wrap the svelte preprocessor with the awesome-pug pre and post processors

import { awesomePugPre, awesomePugPost } from 'svelte-awesome-pug'

/** @type {import('@sveltejs/kit').Config} */
const config = {
    preprocess: [
        awesomePugPre,
        preprocess(),
        awesomePugPost
    ],

Incompatibility

I'm a [TAB] kind of guy, so I haven't supported (or thought of) space indentation yet. The code is pretty simple so feel free to make a pull-request! Take a look at awesome-pug-pre.js

Key features

Is compatible with old-style pug. So any existing pug code shouldn't break.

No need for != and quotes

    //- pug
    .some-div(on:click!='{() => ...}')
    //- awesome-pug
    .some-div(on:click={() => ...})

Indented components

    //- Without awesome-pug
    Input.Text()
    //- Becomes  <Input class="Text">
    //- With awesome-pug
    Input.Text()
    // Becomes   <Input.Text>

Spreading objects

    .some-div('{...$$restProps}')
    //         ^ ts(-1) error
    .some-div(...$$restProps)
    // Results in <div class="some-div" {...$$restProps}>

More

Okay, so making pug not look like 💩 is great. Now ... here are some personal additions of functionality (like them or not)

export:

Export will export/(forward) the attribute for you. Like on:click forwards events, export:class will allow the component to retrieve the class attribute:

    //- Component.svelte
    .some-div(export:class)
    Component.another-class

The attribute input will be default value. (With an exception of export:class and export:style which will always have the default value of '' if you don't provide any)

So..

    //- Component.svelte
    Table(export:data)
    //- Becomes    let __export_data__

    ...
    
    Component
    //- Component was created without the export `data`
    
    


    //- Component.svelte
    Table(export:data={undefined})
    //- Becomes    let __export_data__ = undefined

    ...
    
    Component

Exporting strings

There are two ways to deal with exported strings:

    Table(export:header='Some header')
	//- Becomes    
	//-            let __export_header__ = ''
	//-            Table(header='Some header {__export_header__}')

	Table(export:header={'Some header'})
    //- Becomes    
	//-            let __export_header__ = 'Some header'
	//-            Table(header!='{__export_header__}')

style: and class: directives

You can't normally do

    Component(class:active class:somebool)
    //- "Can't use class directive on components"

However, with svelte-awesome-pug we can add a space in-between AND have multiple like so:

    Component(class :active :somebool)
    //- Becomes   <Component class="{active ? 'active' : ''}  {somebool ? 'somebool' : ''}">

    Component(class :enabled={isEnabled})
    //- Becomes   <Component class="{isEnabled ? 'enabled' : ''}>

Same with style! (or should I say... IN STYLE🕺✨)

    Component(
        export:style
            :--some-variable="{wawiable}px"
            :margin="10px"
    )

--variables

Speaking of style. You can assign CSS variables directly as attributes

    #some-div(
        --some-variable="{wariable}px"
    )

~~my cat is snoring loudly~~

svelte:fragment shortcut

If you wanna skip writing the whole damn fragmentely sveltery text, you can just

    Component
        (slot="Some named slot")
            .some-div
    
    //- Becomes <svelte:fragment slot="Some named slot">...

Wraps true, false, numbers, arrays into { }

    div(
        some-bool=true
        another-bool=false
        some-num=123.23
        some-array=[1, 2, 3]
    )

    //- Becomes   
        <div  
            some-bool={true}
            another-bool={false}
            some-num={123.23}
            some-array={[1, 2, 3]}
        >

You can comment out attributes

It removes the assigned value and indented items (relative to the commented part).

    .some-div(
        //- some-attribute={() => {
            ...
        }}
        another-attribute={...}
        //- export:class
            :some
            :class
    )

    //- Becomes  <div class="some-div" another-attribute={...}>

Footnotes

Maybe create a language server extension

Definitely possible, but I have a tight schedule, so that might first see the light of day in 2024.

Allow Svelte statements {#if ...} in a "non-recursively-indented way" (unlike +if(...))

This

<template lang="pug">
    {#if value > 10}
        span Value is above 10!!🚀✨

    {#if value < 10}
        span Value is below 10

</template>

Results in </template> attempted to close an element that was not opents(-1) ... and I personally don't want errors in my .svelte files unless there is one ...

So this feature will be implemented if this gets resolved.

The feature specifically will look like


    {#if value}
        ...
    {:else if}
        ...
    {:else}
        ...
    
    //- Becomes
    +if('value')
        ...
        +elseif('...')
            ...
            +else
                ...

and support all {#...}