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.

Documenting Sass variables, mixins and functions

See original GitHub issue

I want to try and document our Sass variables/mixins/functions and wondered if anyone had any suggestions of how to do this? I’ve tried:

  1. Documenting them as components, but a component requires a .hbs file. I could create an empty file but then the documentation has a blank component in the preview. Perhaps my config.json file could have a value of preview: false which I could use in the theme to remove the preview - but nobody likes empty files sitting around.
  2. Documenting them in the Docs section using .md files. The problem with this is Fractal only allows 1 path to be set for the docs location which means either splitting the documentation from the Sass or creating a task to bundle all documentation into one folder before running Fractal.

I thought about using SassDoc and getting Fractal to <iframe> in the SassDoc export but that seems a little messy.

So, I’m curious to know if anyone has done something similar or could suggest how best to document Sass?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
mikaelkarlsson-secommented, Jun 20, 2018

Hi! I’ve managed to gather the variables in a specific scss file using a Handlebars helper which uses sass-extract, sass-extract-loader and sass-extract-js to gather and return the variables.

Helper:

const sassExtract = require('sass-extract')  
const createSassExtractJsPlugin = require('sass-extract-js/lib/plugin')  

const sassExtractJsPlugin = createSassExtractJsPlugin({ camelCase: false })  
const scssVariables = sassExtract.renderSync({  
    file: 'path/to/file.scss'  
}, {  
    plugins: [sassExtractJsPlugin]  
})  

fractal.docs.engine(hbs).handlebars.registerHelper('getSassVariables', () => {  
    const variables = []  
    // Note: sass-extract-js returns a object with the keys stats, css and vars and vars is the one needed.  
    Object.entries(scssVariables.vars).forEach(property => {  
        variables.push({  
            variable: property[0],  
            value: property[1]  
        })  
    })  
    return variables  
})  

_index.hbs (my documentation file located in components/docs):

<ul>
    {{#each (getSassVariables)}}
    <li>{{this.variable}} - {{this.value}}</li>
    {{/each}}
</ul>

I hope it can help you. 😃

0reactions
stale[bot]commented, Aug 21, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mixin and @include - Sass
Mixins allow you to define styles that can be re-used throughout your stylesheet. They make it easy to avoid using non-semantic classes like...
Read more >
Documentation - Sass
Sass is a stylesheet language that's compiled to CSS. It allows you to use variables, nested rules, mixins, functions, and more, all with...
Read more >
Sass: @function
Functions allow you to define complex operations on SassScript values that you can re-use throughout your stylesheet. They make it easy to abstract...
Read more >
Sass: @use
The @use rule loads mixins, functions, and variables from other Sass stylesheets, and combines CSS from multiple stylesheets together.
Read more >
Sass Basics
Sass has features that don't exist in CSS yet like nesting, mixins, inheritance, ... Think of variables as a way to store information...
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