Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
lefrancois committed Jul 9, 2021
0 parents commit 6bcc9ac
Show file tree
Hide file tree
Showing 15 changed files with 461 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.vscode
8 changes: 8 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MIT License
Copyright (c) 2021 Michael Lefrancois

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Alpine Lorem

Add easy lorem ipsum text creation to your Alpine 3.x components with a custom directive.

> This package only supports Alpine v3.x.
## About

This plugin adds a new `x-lorem` to Alpine that allows to easliy create lorem ipsum text.

## Installation

### CDN

Include the following `<script>` tag in the `<head>` of your document, just before Alpine.

```html
<script
src="https://cdn.jsdelivr.net/npm/@lefrancois/alpine-lorem@1.x.x/dist/cdn.min.js"
defer
></script>
```

### NPM

```bash
npm install @lefrancois/alpine-lorem
```

Add the `x-lorem` directive to your project by registering the plugin with Alpine.

```js
import Alpine from "alpinejs";
import Lorem from "@lefrancois/alpine-lorem";

Alpine.plugin(Lorem);

window.Alpine = Alpine;
window.Alpine.start();
```

## Usage

To create random lorem ipsum text, just use the `x-lorem` directive on an element.

```html
<div x-data>
<div x-lorem></div>
</div>
```

Optionally you can set the number of paragraphs and word per paragraph.

```html
<div x-data>
<div x-lorem="[2,160]"></div>
</div>
```

## License

Copyright (c) 2021 Michael Lefrancois

Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.
5 changes: 5 additions & 0 deletions builds/cdn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Lorem from '../src/index'

document.addEventListener('alpine:initializing', () => {
window.Alpine.plugin(Lorem)
})
3 changes: 3 additions & 0 deletions builds/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Lorem from '../src/index'

export default Lorem
42 changes: 42 additions & 0 deletions dist/cdn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(() => {
// src/index.js
function src_default(Alpine) {
Alpine.directive("lorem", (el, {expression}, {evaluate}) => {
const dict = ["a", "ac", "accumsan", "ad", "adipiscing", "aenean", "aenean", "aliquam", "aliquam", "aliquet", "amet", "ante", "aptent", "arcu", "at", "auctor", "augue", "bibendum", "blandit", "class", "commodo", "condimentum", "congue", "consectetur", "consequat", "conubia", "convallis", "cras", "cubilia", "curabitur", "curabitur", "curae", "cursus", "dapibus", "diam", "dictum", "dictumst", "dolor", "donec", "donec", "dui", "duis", "egestas", "eget", "eleifend", "elementum", "elit", "enim", "erat", "eros", "est", "et", "etiam", "etiam", "eu", "euismod", "facilisis", "fames", "faucibus", "felis", "fermentum", "feugiat", "fringilla", "fusce", "gravida", "habitant", "habitasse", "hac", "hendrerit", "himenaeos", "iaculis", "id", "imperdiet", "in", "inceptos", "integer", "interdum", "ipsum", "justo", "lacinia", "lacus", "laoreet", "lectus", "leo", "libero", "ligula", "litora", "lobortis", "lorem", "luctus", "maecenas", "magna", "malesuada", "massa", "mattis", "mauris", "metus", "mi", "molestie", "mollis", "morbi", "nam", "nec", "neque", "netus", "nibh", "nisi", "nisl", "non", "nostra", "nulla", "nullam", "nunc", "odio", "orci", "ornare", "pellentesque", "per", "pharetra", "phasellus", "placerat", "platea", "porta", "porttitor", "posuere", "potenti", "praesent", "pretium", "primis", "proin", "pulvinar", "purus", "quam", "quis", "quisque", "quisque", "rhoncus", "risus", "rutrum", "sagittis", "sapien", "scelerisque", "sed", "sem", "semper", "senectus", "sit", "sociosqu", "sodales", "sollicitudin", "suscipit", "suspendisse", "taciti", "tellus", "tempor", "tempus", "tincidunt", "torquent", "tortor", "tristique", "turpis", "ullamcorper", "ultrices", "ultricies", "urna", "ut", "ut", "varius", "vehicula", "vel", "velit", "venenatis", "vestibulum", "vitae", "vivamus", "viverra", "volutpat", "vulputate"];
let paragraphs = 1;
let words = 100;
if (expression) {
const parts = evaluate(expression);
paragraphs = parts[0];
words = parts[1];
}
const punct = "..,,,,,!?";
let lorem = "";
for (var i = 0; i < paragraphs; i++) {
let collectWords = [];
for (var k = 0; k < words; k++) {
collectWords.push(dict[Math.floor(Math.random() * dict.length)]);
}
let index = Math.floor(Math.random() * 10 + 1);
let selectedPunct = ",";
while (index < collectWords.length - 1) {
selectedPunct = punct.charAt(Math.floor(Math.random() * punct.length));
collectWords[index] += selectedPunct;
if ([".", "!", "?"].includes(selectedPunct)) {
collectWords[index + 1] = collectWords[index + 1].charAt(0).toUpperCase() + collectWords[index + 1].slice(1);
}
index += Math.floor(Math.random() * 10 + 2);
}
collectWords[collectWords.length - 1] += ".";
collectWords[0] = collectWords[0].charAt(0).toUpperCase() + collectWords[0].slice(1);
lorem = lorem + "<p>" + collectWords.join(" ") + "</p>";
}
el.innerHTML = lorem;
});
}

// builds/cdn.js
document.addEventListener("alpine:initializing", () => {
window.Alpine.plugin(src_default);
});
})();
1 change: 1 addition & 0 deletions dist/cdn.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions dist/module.cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var __defProp = Object.defineProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, {get: all[name], enumerable: true});
};

// builds/module.js
__markAsModule(exports);
__export(exports, {
default: () => module_default
});

// src/index.js
function src_default(Alpine) {
Alpine.directive("lorem", (el, {expression}, {evaluate}) => {
const dict = ["a", "ac", "accumsan", "ad", "adipiscing", "aenean", "aenean", "aliquam", "aliquam", "aliquet", "amet", "ante", "aptent", "arcu", "at", "auctor", "augue", "bibendum", "blandit", "class", "commodo", "condimentum", "congue", "consectetur", "consequat", "conubia", "convallis", "cras", "cubilia", "curabitur", "curabitur", "curae", "cursus", "dapibus", "diam", "dictum", "dictumst", "dolor", "donec", "donec", "dui", "duis", "egestas", "eget", "eleifend", "elementum", "elit", "enim", "erat", "eros", "est", "et", "etiam", "etiam", "eu", "euismod", "facilisis", "fames", "faucibus", "felis", "fermentum", "feugiat", "fringilla", "fusce", "gravida", "habitant", "habitasse", "hac", "hendrerit", "himenaeos", "iaculis", "id", "imperdiet", "in", "inceptos", "integer", "interdum", "ipsum", "justo", "lacinia", "lacus", "laoreet", "lectus", "leo", "libero", "ligula", "litora", "lobortis", "lorem", "luctus", "maecenas", "magna", "malesuada", "massa", "mattis", "mauris", "metus", "mi", "molestie", "mollis", "morbi", "nam", "nec", "neque", "netus", "nibh", "nisi", "nisl", "non", "nostra", "nulla", "nullam", "nunc", "odio", "orci", "ornare", "pellentesque", "per", "pharetra", "phasellus", "placerat", "platea", "porta", "porttitor", "posuere", "potenti", "praesent", "pretium", "primis", "proin", "pulvinar", "purus", "quam", "quis", "quisque", "quisque", "rhoncus", "risus", "rutrum", "sagittis", "sapien", "scelerisque", "sed", "sem", "semper", "senectus", "sit", "sociosqu", "sodales", "sollicitudin", "suscipit", "suspendisse", "taciti", "tellus", "tempor", "tempus", "tincidunt", "torquent", "tortor", "tristique", "turpis", "ullamcorper", "ultrices", "ultricies", "urna", "ut", "ut", "varius", "vehicula", "vel", "velit", "venenatis", "vestibulum", "vitae", "vivamus", "viverra", "volutpat", "vulputate"];
let paragraphs = 1;
let words = 100;
if (expression) {
const parts = evaluate(expression);
paragraphs = parts[0];
words = parts[1];
}
const punct = "..,,,,,!?";
let lorem = "";
for (var i = 0; i < paragraphs; i++) {
let collectWords = [];
for (var k = 0; k < words; k++) {
collectWords.push(dict[Math.floor(Math.random() * dict.length)]);
}
let index = Math.floor(Math.random() * 10 + 1);
let selectedPunct = ",";
while (index < collectWords.length - 1) {
selectedPunct = punct.charAt(Math.floor(Math.random() * punct.length));
collectWords[index] += selectedPunct;
if ([".", "!", "?"].includes(selectedPunct)) {
collectWords[index + 1] = collectWords[index + 1].charAt(0).toUpperCase() + collectWords[index + 1].slice(1);
}
index += Math.floor(Math.random() * 10 + 2);
}
collectWords[collectWords.length - 1] += ".";
collectWords[0] = collectWords[0].charAt(0).toUpperCase() + collectWords[0].slice(1);
lorem = lorem + "<p>" + collectWords.join(" ") + "</p>";
}
el.innerHTML = lorem;
});
}

// builds/module.js
var module_default = src_default;
41 changes: 41 additions & 0 deletions dist/module.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// src/index.js
function src_default(Alpine) {
Alpine.directive("lorem", (el, {expression}, {evaluate}) => {
const dict = ["a", "ac", "accumsan", "ad", "adipiscing", "aenean", "aenean", "aliquam", "aliquam", "aliquet", "amet", "ante", "aptent", "arcu", "at", "auctor", "augue", "bibendum", "blandit", "class", "commodo", "condimentum", "congue", "consectetur", "consequat", "conubia", "convallis", "cras", "cubilia", "curabitur", "curabitur", "curae", "cursus", "dapibus", "diam", "dictum", "dictumst", "dolor", "donec", "donec", "dui", "duis", "egestas", "eget", "eleifend", "elementum", "elit", "enim", "erat", "eros", "est", "et", "etiam", "etiam", "eu", "euismod", "facilisis", "fames", "faucibus", "felis", "fermentum", "feugiat", "fringilla", "fusce", "gravida", "habitant", "habitasse", "hac", "hendrerit", "himenaeos", "iaculis", "id", "imperdiet", "in", "inceptos", "integer", "interdum", "ipsum", "justo", "lacinia", "lacus", "laoreet", "lectus", "leo", "libero", "ligula", "litora", "lobortis", "lorem", "luctus", "maecenas", "magna", "malesuada", "massa", "mattis", "mauris", "metus", "mi", "molestie", "mollis", "morbi", "nam", "nec", "neque", "netus", "nibh", "nisi", "nisl", "non", "nostra", "nulla", "nullam", "nunc", "odio", "orci", "ornare", "pellentesque", "per", "pharetra", "phasellus", "placerat", "platea", "porta", "porttitor", "posuere", "potenti", "praesent", "pretium", "primis", "proin", "pulvinar", "purus", "quam", "quis", "quisque", "quisque", "rhoncus", "risus", "rutrum", "sagittis", "sapien", "scelerisque", "sed", "sem", "semper", "senectus", "sit", "sociosqu", "sodales", "sollicitudin", "suscipit", "suspendisse", "taciti", "tellus", "tempor", "tempus", "tincidunt", "torquent", "tortor", "tristique", "turpis", "ullamcorper", "ultrices", "ultricies", "urna", "ut", "ut", "varius", "vehicula", "vel", "velit", "venenatis", "vestibulum", "vitae", "vivamus", "viverra", "volutpat", "vulputate"];
let paragraphs = 1;
let words = 100;
if (expression) {
const parts = evaluate(expression);
paragraphs = parts[0];
words = parts[1];
}
const punct = "..,,,,,!?";
let lorem = "";
for (var i = 0; i < paragraphs; i++) {
let collectWords = [];
for (var k = 0; k < words; k++) {
collectWords.push(dict[Math.floor(Math.random() * dict.length)]);
}
let index = Math.floor(Math.random() * 10 + 1);
let selectedPunct = ",";
while (index < collectWords.length - 1) {
selectedPunct = punct.charAt(Math.floor(Math.random() * punct.length));
collectWords[index] += selectedPunct;
if ([".", "!", "?"].includes(selectedPunct)) {
collectWords[index + 1] = collectWords[index + 1].charAt(0).toUpperCase() + collectWords[index + 1].slice(1);
}
index += Math.floor(Math.random() * 10 + 2);
}
collectWords[collectWords.length - 1] += ".";
collectWords[0] = collectWords[0].charAt(0).toUpperCase() + collectWords[0].slice(1);
lorem = lorem + "<p>" + collectWords.join(" ") + "</p>";
}
el.innerHTML = lorem;
});
}

// builds/module.js
var module_default = src_default;
export {
module_default as default
};
22 changes: 22 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alpine.js Lorem</title>
<script type="module">
import Lorem from '../dist/module.esm.js'

document.addEventListener('alpine:initializing', () => {
window.Alpine.plugin(Lorem)
})
</script>
<script defer src="https://unpkg.com/alpinejs@3.1.1/dist/cdn.min.js"></script>
</head>
<body>
<h1>1 paragraph with 100 words (default)</h1>
<div x-data x-lorem></div>
<h1>3 Paragraphs with 90 words</h1>
<div x-data x-lorem="[3,90]"></div>
</body>
</html>
67 changes: 67 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@lefrancois/alpine-lorem",
"description": "Add easy lorem ipsum text creation to your Alpine 3.x components with a custom directive.",
"version": "1.0.0",
"author": {
"name": "Michael Lefrancois",
"email": "michael@lefrancois.de",
"url": "https://www.lefrancois.de"
},
"repository": {
"type": "git",
"url": "https://github.com/lefrancois/alpine-lorem"
},
"main": "dist/module.cjs.js",
"module": "dist/module.esm.js",
"devDependencies": {
"brotli-size": "^4.0.0",
"esbuild": "^0.8.39"
},
"scripts": {
"build": "node ./scripts/build.js",
"watch": "node ./scripts/build.js --watch"
}
}
Loading

0 comments on commit 6bcc9ac

Please sign in to comment.