question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using in HAML templates

See original GitHub issue

Hello!

I just migrated my Rails app to vite.js. I would like to integrate windicss. I have followed the docs and it kind of works.

I can use @apply in my stylesheets and I can use windi classes in HTML templates. However. I have mixed results in HAML templates - which I use in all my projects. I have added .haml extension to confing, so templates are scanned.

Apparently there are some issues with HAML syntax. I learned that using hash syntax for classes works:

%div{:class => 'my-nice-class other-class'}

But mixing with HAML dot notation (very common) causes troubles:

%div.my-nice-class.other-nice-class

The strange thing is, that sometimes it works, sometimes not. I am trying to find out what could be the source of troubles… I though it was the dashes in class-names, but probably it is not…

I am using normal vite processing from vite_rails gem.

Is somebody using HAML with Windi? I fould some haml references in docs/examples, but technically it is not confirmed anywhere that it should work 😉

thanks in advance for any hints! Jakub

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
gaultierqcommented, Jul 1, 2022

Thanks @cmwoodal ;

Your extractor also works with slim

Iterating on your work, I need to match top-1/2

// haml.extractor.js
const classRegex = /(?<=\.)([\w\-]+)|(?<=class[\:=]\s*['"][\w\:\-\/\!\[\]#\s]*)([\w\:\-\/\!\[\]#]+)(?=[\w\:\-\/\!\[\]#\s]*['"])/gm;
const tagRegex = /(?<=\n\s*%)(?!script|meta|style|link)([\w\-]+)(?=[\n\s\.\({])/gm;

export const extractFromHaml = (content) => {
    return {
        classes: content.match(classRegex) || [],
        tags: content.match(tagRegex) || [],
    };
};
// windi.config.js

extractors: [
  {
    extractor: extractFromHaml,
    extensions: ['haml', 'slim'],
  }
]
2reactions
cmwoodalcommented, Jul 1, 2022

I’ve run into the same issue – the scanner doesn’t recognize the dot notation classes nor the HAML % notation tags. Fortunately windicss provides the ability to provide custom extractor functions that can be used to provide special handling. For this situation I was able to provide a special extractor function specifically for HAML files

import { defineConfig, transform } from "windicss/helpers";

export default defineConfig({
  theme: {
    extend: {},
  },
  plugins: [
    require("windicss/plugin/aspect-ratio"),
    require("windicss/plugin/forms"),
    require("windicss/plugin/typography"),
    transform("daisyui"),
  ],
  extract: {
    extractors: [
      {
        extractor: (function hamlExtractor() {
          const classRegex =
            /(?<=\.)([\w\-]+)|(?<=class[\:=]\s*['"][\w\:\-\!\[\]#\s]*)([\w\:\-\!\[\]#]+)(?=[\w\:\-\!\[\]#\s]*['"])/gm;
          const tagRegex = /(?<=\n\s*%)(?!script|meta|style|link)([\w\-]+)(?=[\n\s\.\({])/gm;
          return function extractFromHaml(content) {
            return {
              classes: content.match(classRegex) || [],
              tags: content.match(tagRegex) || [],
            };
          };
        })(),
        extensions: ["haml"],
      },
    ],
  },
});

The regexes for both classes and tags have been tested to return a concise list of matches:

classes:

image

tags:

image

Hope this is helpful for anyone else who might run into this situation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Haml
It's not just beauty for beauty's sake either; Haml accelerates and simplifies template creation down to veritable haiku. Unspace Interactive and several other ......
Read more >
Templating with ERB & HAML - Jumpstart Lab Curriculum
Open the view template in app/views/articles/index. · Rename the template to index. · Cut everything except the H1 to a temporary file so...
Read more >
netzpirat/haml-coffee: Haml templates where you can ... - GitHub
Haml Coffee Templates Build Status ... Haml Coffee is a JavaScript templating solution that uses Haml as markup, understands inline CoffeeScript and generates...
Read more >
Using HAML with Ruby on Rails | Grio Blog
HAML, also known as HTML abstraction markup language, is a templating language that was designed to make the HTML cleaner while providing more ......
Read more >
Templating in Haml questions - ruby on rails - Stack Overflow
Now my question is I wanted to get into templates with haml/rails. Do I need to have ruby installed on my unit to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found