Skip to content

Commit 6cd2a59

Browse files
committed
Initial commit
0 parents  commit 6cd2a59

9 files changed

+3848
-0
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[*.md]
2+
indent_style = space
3+
indent_size = 4

.eleventy.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable valid-jsdoc */
2+
const classnames = require( "./src/classnames" );
3+
4+
/**
5+
* @param {import("@11ty/eleventy/src/UserConfig")} eleventyConfig
6+
*/
7+
module.exports = ( eleventyConfig ) =>
8+
{
9+
eleventyConfig.addShortcode( "classnames", classnames );
10+
};

.eslintrc.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module.exports = {
2+
"env": {
3+
"es2021": true,
4+
"node": true,
5+
},
6+
"extends": "eslint:recommended",
7+
"rules": {
8+
"arrow-parens": ["error", "always"],
9+
"brace-style": ["error", "allman"],
10+
"camelcase": "warn",
11+
"comma-dangle": ["error", "always-multiline"],
12+
"indent": ["error", "tab"],
13+
"max-len": [0, {
14+
"ignoreComments": true,
15+
"ignoreTrailingComments": true,
16+
"ignoreUrls": true,
17+
"ignoreStrings": true,
18+
"ignoreTemplateLiterals": true,
19+
"ignoreRegExpLiterals": true,
20+
"ignorePattern": true,
21+
}],
22+
"new-cap": "warn",
23+
"no-console": "warn",
24+
"no-invalid-this": "error",
25+
"no-negated-condition": "warn",
26+
"object-curly-spacing": ["error", "always"],
27+
"quotes": ["error", "double"],
28+
"require-jsdoc": ["error", {
29+
"require": {
30+
"FunctionDeclaration": true,
31+
},
32+
}],
33+
"semi": ["error", "always"],
34+
"sort-requires/sort-requires": 2,
35+
"sort-vars": ["error", {
36+
"ignoreCase": true,
37+
}],
38+
"space-in-parens": ["error", "always", {
39+
"exceptions": ["empty"],
40+
}],
41+
},
42+
"parserOptions": {
43+
"sourceType": "module",
44+
},
45+
"plugins": [
46+
"sort-requires",
47+
],
48+
};

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# eleventy-plugin-classnames
2+
3+
An [Eleventy](https://11ty.dev/) shortcode for joining truthy, non-duplicate argument values into a space-delimited string.
4+
5+
> Inspired by the [classnames](https://www.npmjs.com/package/classnames) package by [JedWatson](https://github.com/JedWatson/classnames)
6+
7+
## Setup
8+
9+
Run the following command at the root of your Eleventy project
10+
11+
```shell
12+
npm install @aaashur/eleventy-plugin-classnames
13+
```
14+
15+
then include it in your `.eleventy.js` config file:
16+
17+
```javascript
18+
const classnames = require("@aaashur/eleventy-plugin-classnames");
19+
20+
module.exports = (eleventyConfig) => {
21+
eleventyConfig.addPlugin(classnames);
22+
};
23+
```
24+
25+
## Usage
26+
27+
```njk
28+
{%- set color = "turquoise" -%}
29+
{%- set primary = false -%}
30+
{%- set sectionTitle = "Section Title" -%}
31+
32+
<h2 class="{% classnames
33+
"block__element",
34+
"block__element--primary" if primary,
35+
"block__element--" + color if color
36+
%}">
37+
{{ sectionTitle }}
38+
</h2>
39+
```
40+
41+
would return
42+
43+
```html
44+
<h2 class="block__element block__element--turquoise">
45+
Section Title
46+
</h2>
47+
```

0 commit comments

Comments
 (0)