Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ashur committed Mar 1, 2023
0 parents commit 6cd2a59
Show file tree
Hide file tree
Showing 9 changed files with 3,848 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.md]
indent_style = space
indent_size = 4
10 changes: 10 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable valid-jsdoc */
const classnames = require( "./src/classnames" );

/**
* @param {import("@11ty/eleventy/src/UserConfig")} eleventyConfig
*/
module.exports = ( eleventyConfig ) =>
{
eleventyConfig.addShortcode( "classnames", classnames );
};
48 changes: 48 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
"env": {
"es2021": true,
"node": true,
},
"extends": "eslint:recommended",
"rules": {
"arrow-parens": ["error", "always"],
"brace-style": ["error", "allman"],
"camelcase": "warn",
"comma-dangle": ["error", "always-multiline"],
"indent": ["error", "tab"],
"max-len": [0, {
"ignoreComments": true,
"ignoreTrailingComments": true,
"ignoreUrls": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreRegExpLiterals": true,
"ignorePattern": true,
}],
"new-cap": "warn",
"no-console": "warn",
"no-invalid-this": "error",
"no-negated-condition": "warn",
"object-curly-spacing": ["error", "always"],
"quotes": ["error", "double"],
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
},
}],
"semi": ["error", "always"],
"sort-requires/sort-requires": 2,
"sort-vars": ["error", {
"ignoreCase": true,
}],
"space-in-parens": ["error", "always", {
"exceptions": ["empty"],
}],
},
"parserOptions": {
"sourceType": "module",
},
"plugins": [
"sort-requires",
],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# eleventy-plugin-classnames

An [Eleventy](https://11ty.dev/) shortcode for joining truthy, non-duplicate argument values into a space-delimited string.

> Inspired by the [classnames](https://www.npmjs.com/package/classnames) package by [JedWatson](https://github.com/JedWatson/classnames)
## Setup

Run the following command at the root of your Eleventy project

```shell
npm install @aaashur/eleventy-plugin-classnames
```

then include it in your `.eleventy.js` config file:

```javascript
const classnames = require("@aaashur/eleventy-plugin-classnames");

module.exports = (eleventyConfig) => {
eleventyConfig.addPlugin(classnames);
};
```

## Usage

```njk
{%- set color = "turquoise" -%}
{%- set primary = false -%}
{%- set sectionTitle = "Section Title" -%}
<h2 class="{% classnames
"block__element",
"block__element--primary" if primary,
"block__element--" + color if color
%}">
{{ sectionTitle }}
</h2>
```

would return

```html
<h2 class="block__element block__element--turquoise">
Section Title
</h2>
```
Loading

0 comments on commit 6cd2a59

Please sign in to comment.