vue-dummyy 0.0.1-security → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of vue-dummyy might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +103 -5
- package/dist/.gitkeep +0 -0
- package/dist/vue-dummy.cjs.js +80 -0
- package/dist/vue-dummy.es2015.js +76 -0
- package/dist/vue-dummy.js +220 -0
- package/package.json +44 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Paul Collett
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,103 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
### vue-dummy
|
|
2
|
+
## Placeholder Images and Dummy Text for Vue.js
|
|
3
|
+
|
|
4
|
+
`vue-dummy` is a wrapper around the https://dummyjs.com/ library to expose placeholder Images and Dummy, Lorum Ipsum Text as a vue directive
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
Add to your HTML page:
|
|
9
|
+
|
|
10
|
+
```html
|
|
11
|
+
<script src="https://unpkg.com/vue"></script>
|
|
12
|
+
<script src="https://unpkg.com/vue-dummy"></script>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or, import into your module `npm install vue-dummy --save-dev`
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import Vue from "vue"
|
|
19
|
+
import VueDummy from "vue-dummy"
|
|
20
|
+
|
|
21
|
+
Vue.use(VueDummy)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Dummy Text
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<p v-dummy></p>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Choose the number of words:
|
|
31
|
+
```html
|
|
32
|
+
<p v-dummy="150"></p>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Choose random amount of words between 3 & 10:
|
|
36
|
+
```html
|
|
37
|
+
<p v-dummy="'3,10'"></p> <!-- Note: the quotes to pass the expression as a string -->
|
|
38
|
+
<p v-dummy:3,10></p> <!-- or, as a Vue argument-->
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
As a component:
|
|
42
|
+
```html
|
|
43
|
+
<dummy></dummy>
|
|
44
|
+
<dummy text="30"></dummy>
|
|
45
|
+
<dummy t="1,3"></dummy>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Dummy Images
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<img v-dummy="300" />
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<img v-dummy="'400x300'" /> <!-- Note: the quotes to pass the expression as a string -->
|
|
56
|
+
<img v-dummy:400x300 /><!-- or, as a Vue argument -->
|
|
57
|
+
<img v-dummy.400x300 /><!-- or, as a Vue modifier -->
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Use width & height attribues _or, size with CSS_
|
|
61
|
+
```html
|
|
62
|
+
<img v-dummy width="150" height="150" />
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Defaults to the size of the parent container
|
|
66
|
+
```html
|
|
67
|
+
<img v-dummy />
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Create random sized images. _Useful for testing dimentions of unknown sized user uploaded images_
|
|
71
|
+
```html
|
|
72
|
+
<img v-dummy="'100,400x200,400'" /> <!-- Note: the quotes to pass the expression as a string -->
|
|
73
|
+
<img v-dummy:100,400x200,400 /> <!-- or, as a Vue argument (or modifier) -->
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
As a component:
|
|
77
|
+
```html
|
|
78
|
+
<dummy img></dummy>
|
|
79
|
+
<dummy img="400x300"></dummy>
|
|
80
|
+
<dummy i="100"></dummy>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Special Elements
|
|
84
|
+
|
|
85
|
+
Using `v-dummy` on some tags will result in some placeholder content with expected markup. This is useful in some cases like quick styling of elements
|
|
86
|
+
```html
|
|
87
|
+
<ol v-dummy></ol> <!-- outputs a small list -->
|
|
88
|
+
<ul v-dummy></ul> <!-- outputs a small list -->
|
|
89
|
+
<table v-dummy></table> <!-- outputs a small table -->
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Example Repeat Elements
|
|
93
|
+
|
|
94
|
+
Combine with `v-for` to repeat elements
|
|
95
|
+
|
|
96
|
+
```html
|
|
97
|
+
<ul>
|
|
98
|
+
<li v-for="i in 6" v-dummy>#{{i}}: </li>
|
|
99
|
+
</ul>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Examples
|
|
103
|
+
https://git.io/vue-dummy-example
|
package/dist/.gitkeep
ADDED
|
File without changes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
+
|
|
5
|
+
var Dummy = _interopDefault(require('dummyjs'));
|
|
6
|
+
|
|
7
|
+
var Plugin = function () {};
|
|
8
|
+
|
|
9
|
+
Plugin.install = function (Vue, options) {
|
|
10
|
+
if (Plugin.installed) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var directive = function (el, binding) {
|
|
15
|
+
if(!el) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var args = binding.arg // v-dummy:args
|
|
20
|
+
|| Object.keys(binding.modifiers).join(',') // v-dummy.args
|
|
21
|
+
|| (typeof binding.value == 'string' ? binding.value : binding.expression)
|
|
22
|
+
|| '';
|
|
23
|
+
var nodeName = el.nodeName.toLowerCase();
|
|
24
|
+
|
|
25
|
+
if(nodeName === 'img') {
|
|
26
|
+
el.src = Dummy.src(args, el);
|
|
27
|
+
} else if(nodeName === 'table') {
|
|
28
|
+
var tableRow = function () { return ("<tr><td>" + (Dummy.text(3)) + "</td><td>" + (Dummy.text(3)) + "</td><td>" + (Dummy.text(3)) + "</td></tr>"); };
|
|
29
|
+
el.innerHTML = "<thead>" + (tableRow().replace(/td>/g, 'th>')) + "</thead><tbody>" + (tableRow()) + (tableRow()) + (tableRow()) + "</tbody>";
|
|
30
|
+
} else if(nodeName === 'ul' || nodeName === 'ol') {
|
|
31
|
+
el.innerHTML += "<li>" + (Dummy.text(3)) + "</li><li>" + (Dummy.text(3)) + "</li><li>" + (Dummy.text(3)) + "</li>";
|
|
32
|
+
} else {
|
|
33
|
+
el.innerHTML += Dummy.text(args);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
Vue.directive('dummy', {
|
|
38
|
+
// called when the bound element has been inserted into its parent node
|
|
39
|
+
inserted: directive
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
Vue.directive('dummy-self', {
|
|
43
|
+
inserted: function (el, binding) {
|
|
44
|
+
el.outerHTML = Dummy.text(typeof binding.value == 'string' ? binding.value : binding.expression);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
var componentProps = 'i,img,image,t,txt,text,w,words'.split(',');
|
|
49
|
+
var componentPropsObj = componentProps.reduce(function (c, v, i) { c[v] = true; return c }, {});
|
|
50
|
+
|
|
51
|
+
Vue.component('dummy', {
|
|
52
|
+
render: function (createElement) {
|
|
53
|
+
var this$1 = this;
|
|
54
|
+
|
|
55
|
+
var value = '';
|
|
56
|
+
var renderImage = false;
|
|
57
|
+
|
|
58
|
+
for (var i = 0; i < componentProps.length; i++) {
|
|
59
|
+
if(typeof this$1[componentProps[i]] !== 'undefined') {
|
|
60
|
+
value = this$1[componentProps[i]] + '';
|
|
61
|
+
renderImage = componentProps[i][0] === 'i' || value.indexOf('x') > 0;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return createElement(renderImage ? 'img' : 'span', {
|
|
66
|
+
directives: [{
|
|
67
|
+
name: renderImage ? 'dummy' : 'dummy-self',
|
|
68
|
+
value: value
|
|
69
|
+
}]
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
props: componentPropsObj
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
|
77
|
+
window.Vue.use(Plugin);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module.exports = Plugin;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import Dummy from 'dummyjs';
|
|
2
|
+
|
|
3
|
+
var Plugin = function () {};
|
|
4
|
+
|
|
5
|
+
Plugin.install = function (Vue, options) {
|
|
6
|
+
if (Plugin.installed) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
var directive = function (el, binding) {
|
|
11
|
+
if(!el) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var args = binding.arg // v-dummy:args
|
|
16
|
+
|| Object.keys(binding.modifiers).join(',') // v-dummy.args
|
|
17
|
+
|| (typeof binding.value == 'string' ? binding.value : binding.expression)
|
|
18
|
+
|| '';
|
|
19
|
+
var nodeName = el.nodeName.toLowerCase();
|
|
20
|
+
|
|
21
|
+
if(nodeName === 'img') {
|
|
22
|
+
el.src = Dummy.src(args, el);
|
|
23
|
+
} else if(nodeName === 'table') {
|
|
24
|
+
var tableRow = function () { return ("<tr><td>" + (Dummy.text(3)) + "</td><td>" + (Dummy.text(3)) + "</td><td>" + (Dummy.text(3)) + "</td></tr>"); };
|
|
25
|
+
el.innerHTML = "<thead>" + (tableRow().replace(/td>/g, 'th>')) + "</thead><tbody>" + (tableRow()) + (tableRow()) + (tableRow()) + "</tbody>";
|
|
26
|
+
} else if(nodeName === 'ul' || nodeName === 'ol') {
|
|
27
|
+
el.innerHTML += "<li>" + (Dummy.text(3)) + "</li><li>" + (Dummy.text(3)) + "</li><li>" + (Dummy.text(3)) + "</li>";
|
|
28
|
+
} else {
|
|
29
|
+
el.innerHTML += Dummy.text(args);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
Vue.directive('dummy', {
|
|
34
|
+
// called when the bound element has been inserted into its parent node
|
|
35
|
+
inserted: directive
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
Vue.directive('dummy-self', {
|
|
39
|
+
inserted: function (el, binding) {
|
|
40
|
+
el.outerHTML = Dummy.text(typeof binding.value == 'string' ? binding.value : binding.expression);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
var componentProps = 'i,img,image,t,txt,text,w,words'.split(',');
|
|
45
|
+
var componentPropsObj = componentProps.reduce(function (c, v, i) { c[v] = true; return c }, {});
|
|
46
|
+
|
|
47
|
+
Vue.component('dummy', {
|
|
48
|
+
render: function (createElement) {
|
|
49
|
+
var this$1 = this;
|
|
50
|
+
|
|
51
|
+
var value = '';
|
|
52
|
+
var renderImage = false;
|
|
53
|
+
|
|
54
|
+
for (var i = 0; i < componentProps.length; i++) {
|
|
55
|
+
if(typeof this$1[componentProps[i]] !== 'undefined') {
|
|
56
|
+
value = this$1[componentProps[i]] + '';
|
|
57
|
+
renderImage = componentProps[i][0] === 'i' || value.indexOf('x') > 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return createElement(renderImage ? 'img' : 'span', {
|
|
62
|
+
directives: [{
|
|
63
|
+
name: renderImage ? 'dummy' : 'dummy-self',
|
|
64
|
+
value: value
|
|
65
|
+
}]
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
props: componentPropsObj
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
|
73
|
+
window.Vue.use(Plugin);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default Plugin;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
var VueDummy = (function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var rand = function (min, max) {
|
|
5
|
+
if(!min || !max) { return min; }
|
|
6
|
+
min = Math.floor(min);
|
|
7
|
+
max = Math.floor(max) + 1;
|
|
8
|
+
return Math.floor(Math.random() * (max - min)) + min;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// repeat polyfill
|
|
12
|
+
var repeat = function (str, count) {
|
|
13
|
+
return (function (str, count, rpt) {
|
|
14
|
+
for (var i = 0; i < count; i++) { rpt += (typeof str == 'function' ? str() : String(str)); }
|
|
15
|
+
|
|
16
|
+
return rpt;
|
|
17
|
+
})(str, Math.floor(count), '');
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// array.from polyfill (!IE)
|
|
21
|
+
|
|
22
|
+
var text = function () {
|
|
23
|
+
var arguments$1 = arguments;
|
|
24
|
+
|
|
25
|
+
var args = [], len = arguments.length;
|
|
26
|
+
while ( len-- ) { args[ len ] = arguments$1[ len ]; }
|
|
27
|
+
|
|
28
|
+
var wordCount = args.join(',').split(','); // allow for mixed argument input ie. ('20,30') or (20, 30)
|
|
29
|
+
wordCount = rand(wordCount[0], wordCount[1]) || 10;
|
|
30
|
+
|
|
31
|
+
var lib = 'lorem ipsum dolor sit amet consectetur adipiscing elit nunc euismod vel ' +
|
|
32
|
+
'dolor nec viverra nullam auctor enim condimentum odio laoreet libero ' +
|
|
33
|
+
'libero tincidunt est sagittis curabitur vitae';
|
|
34
|
+
|
|
35
|
+
if(wordCount > 3) { lib += (' ' + 'a in id id at'); }
|
|
36
|
+
|
|
37
|
+
var libRepeat = Math.ceil(wordCount/lib.split(' ').length);
|
|
38
|
+
|
|
39
|
+
lib = repeat(lib, libRepeat).split(' ').sort(function () { return 0.5 - Math.random(); }).slice(0, wordCount).join(' ');
|
|
40
|
+
|
|
41
|
+
return lib.charAt(0).toUpperCase() + lib.slice(1);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var src = function () {
|
|
45
|
+
var arguments$1 = arguments;
|
|
46
|
+
|
|
47
|
+
var args = [], len = arguments.length;
|
|
48
|
+
while ( len-- ) { args[ len ] = arguments$1[ len ]; }
|
|
49
|
+
|
|
50
|
+
// allow for mixed argument input ie. (200, 200, el) ('200x200', el), ('200')
|
|
51
|
+
var el = args[args.length - 1] instanceof HTMLImageElement ? args.pop() : null;
|
|
52
|
+
var size = args.splice(0, 2).join('x');
|
|
53
|
+
|
|
54
|
+
if(!size && el) {
|
|
55
|
+
size = [parseInt(el.getAttribute('width') || el.offsetWidth), parseInt(el.getAttribute('height') || el.offsetHeight)].filter(function (v) {return !!v}).join('x');
|
|
56
|
+
size = size || (el.parentNode && el.parentNode.offsetWidth);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// split size to allow for random ranges
|
|
60
|
+
size = (size + '' || '404').split('x').map(function (a){ return rand(a.split(',')[0] || '404', a.split(',')[1]); });
|
|
61
|
+
|
|
62
|
+
var w = size[0];
|
|
63
|
+
var h = size[1] || size[0];
|
|
64
|
+
|
|
65
|
+
// Getting a little messy, but idea is to test next argument to see if it isn't a color (not #..) then remove it from the arguments list and return. Otherwise fallback..
|
|
66
|
+
var text = args[0] && /^\w{2,}/.test(args[0]) ? args.splice(0, 1).pop() : ( el && el.getAttribute('data-text') || (w + '×' + h) );
|
|
67
|
+
var bgColor = (el && el.getAttribute('data-color') || args[0] || '#ccc');
|
|
68
|
+
var textColor = (el && el.getAttribute('data-text-color') || args[1] || '#888');
|
|
69
|
+
|
|
70
|
+
// Better logic out there?
|
|
71
|
+
var fontSize = (w / 3.5 / (text.length * 0.3)) - text.length;
|
|
72
|
+
|
|
73
|
+
return 'data:image/svg+xml,'
|
|
74
|
+
+ encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="'+ w + 'px" height="' + h + 'px">'
|
|
75
|
+
+ '<rect x="0" y="0" width="100%" height="100%" fill="' + bgColor + '"/>'
|
|
76
|
+
+ '<line opacity="0.5" x1="0%" y1="0%" x2="100%" y2="100%" stroke="' + textColor + '" stroke-width="2" />'
|
|
77
|
+
+ '<line opacity="0.5" x1="100%" y1="0%" x2="0%" y2="100%" stroke="' + textColor + '" stroke-width="2" />'
|
|
78
|
+
+ '<text stroke="' + bgColor + '" stroke-width="2em" x="50%" y="50%" alignment-baseline="middle" text-anchor="middle" font-size="'+fontSize+'" font-family="sans-serif">' + text + '</text>'
|
|
79
|
+
+ '<text fill="' + textColor + '" x="50%" y="50%" alignment-baseline="middle" text-anchor="middle" font-size="'+fontSize+'" font-family="sans-serif">' + text + '</text>'
|
|
80
|
+
+ '</svg>');
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
var table = function (rows, rowsTo, cols, colsTo) {
|
|
84
|
+
if ( rows === void 0 ) { rows = 3; }
|
|
85
|
+
if ( rowsTo === void 0 ) { rowsTo = 6; }
|
|
86
|
+
if ( cols === void 0 ) { cols = 3; }
|
|
87
|
+
if ( colsTo === void 0 ) { colsTo = 6; }
|
|
88
|
+
|
|
89
|
+
cols = rand(cols, colsTo || cols);
|
|
90
|
+
rows = rand(rows, rowsTo || rows);
|
|
91
|
+
return "<table><thead><tr>"
|
|
92
|
+
+ repeat(function () { return ("<th>" + (text(1,3)) + "</th>"); }, cols)
|
|
93
|
+
+ "</tr></thead><tbody>"
|
|
94
|
+
+ repeat(("<tr>" + (repeat(function () { return ("<td>" + (text(3,10)) + "</td>"); }, cols)) + "</tr>"), rows)
|
|
95
|
+
+ "</tbody></table>";
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
var html = function (usersTags) {
|
|
99
|
+
var tags = usersTags ? String(usersTags).split(',') : 'h1,h2,h3,h4,h5,ul,ol,table,blockquote,img,form'.split(',').join(',p,').split(',');
|
|
100
|
+
var liFn = function () { return repeat(function () { return ("<li>" + (text(4, 10)) + "</li>"); }, rand(2, 5)); };
|
|
101
|
+
|
|
102
|
+
var special = {
|
|
103
|
+
a: function () { return ("<a href=\"#\">" + (text(2, 4)) + "</a>"); },
|
|
104
|
+
ul: function () { return ("<ul>" + (liFn()) + "</ul>"); },
|
|
105
|
+
ol: function (){ return ("<ol>" + (liFn()) + "</ol>"); },
|
|
106
|
+
table: function () { return table(); },
|
|
107
|
+
img: function () { return ("<img src=\"" + (src('400,1200x200,800')) + "\" />"); },
|
|
108
|
+
select: function () { return ("<select>" + (repeat(function () { return ("<option>" + (text(2,4)) + "</option>"); }, 4, 10)) + "</select>"); },
|
|
109
|
+
p: function () { return ("<p>" + (text(20, 50)) + "</p>"); },
|
|
110
|
+
button: function () { return ("<button>" + (text(1, 4)) + "</button>"); },
|
|
111
|
+
input: function () { return ("<input placeholder=\"" + (text(1,3)) + "\" />"); },
|
|
112
|
+
form: function () { return ("<form action=\"#\">" + (html('label,input,label,select,button')) + "</form>"); }
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
tags = tags
|
|
116
|
+
.map(function (tag) { return tag.trim().toLowerCase(); })
|
|
117
|
+
.map(function (tag) { return special[tag] ? special[tag]() : ("<" + tag + ">" + (text(5, 15)) + "</" + tag + ">"); }).join('');
|
|
118
|
+
|
|
119
|
+
// few extra tags for default
|
|
120
|
+
tags += usersTags ? '' :
|
|
121
|
+
"<hr /><p>" + (text(1, 3)) + " <strong>bold text</strong>. " + (text(1, 3)) + " <em>italic text</em>. " + (text(1, 3)) + " <a href=\"#\">a link</a>. " + (text(150, 250)) + "</p>"
|
|
122
|
+
+ repeat(function () { return ("<p>" + (text(50, 100)) + "</p>"); }, rand(1, 3));
|
|
123
|
+
|
|
124
|
+
return tags;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// Undocumented but you could simply do:
|
|
128
|
+
// Dummy(123) instead of Dummy.text(123)
|
|
129
|
+
// or Dummy('100x100')
|
|
130
|
+
// or Dummy('table')
|
|
131
|
+
var expt = function () {
|
|
132
|
+
var arguments$1 = arguments;
|
|
133
|
+
|
|
134
|
+
var args = [], len = arguments.length;
|
|
135
|
+
while ( len-- ) { args[ len ] = arguments$1[ len ]; }
|
|
136
|
+
|
|
137
|
+
var fn = String(args[0]).indexOf('x') > 0 ? src : parseInt(args[0]) > 0 ? text : html;
|
|
138
|
+
|
|
139
|
+
return fn.apply(void 0, args);
|
|
140
|
+
};
|
|
141
|
+
expt.t = expt.txt = expt.text = text;
|
|
142
|
+
expt.src = expt.image = expt.img = src;
|
|
143
|
+
expt.html = html;
|
|
144
|
+
|
|
145
|
+
var Plugin = function () {};
|
|
146
|
+
|
|
147
|
+
Plugin.install = function (Vue, options) {
|
|
148
|
+
if (Plugin.installed) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
var directive = function (el, binding) {
|
|
153
|
+
if(!el) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var args = binding.arg // v-dummy:args
|
|
158
|
+
|| Object.keys(binding.modifiers).join(',') // v-dummy.args
|
|
159
|
+
|| (typeof binding.value == 'string' ? binding.value : binding.expression)
|
|
160
|
+
|| '';
|
|
161
|
+
var nodeName = el.nodeName.toLowerCase();
|
|
162
|
+
|
|
163
|
+
if(nodeName === 'img') {
|
|
164
|
+
el.src = expt.src(args, el);
|
|
165
|
+
} else if(nodeName === 'table') {
|
|
166
|
+
var tableRow = function () { return ("<tr><td>" + (expt.text(3)) + "</td><td>" + (expt.text(3)) + "</td><td>" + (expt.text(3)) + "</td></tr>"); };
|
|
167
|
+
el.innerHTML = "<thead>" + (tableRow().replace(/td>/g, 'th>')) + "</thead><tbody>" + (tableRow()) + (tableRow()) + (tableRow()) + "</tbody>";
|
|
168
|
+
} else if(nodeName === 'ul' || nodeName === 'ol') {
|
|
169
|
+
el.innerHTML += "<li>" + (expt.text(3)) + "</li><li>" + (expt.text(3)) + "</li><li>" + (expt.text(3)) + "</li>";
|
|
170
|
+
} else {
|
|
171
|
+
el.innerHTML += expt.text(args);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
Vue.directive('dummy', {
|
|
176
|
+
// called when the bound element has been inserted into its parent node
|
|
177
|
+
inserted: directive
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
Vue.directive('dummy-self', {
|
|
181
|
+
inserted: function (el, binding) {
|
|
182
|
+
el.outerHTML = expt.text(typeof binding.value == 'string' ? binding.value : binding.expression);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
var componentProps = 'i,img,image,t,txt,text,w,words'.split(',');
|
|
187
|
+
var componentPropsObj = componentProps.reduce(function (c, v, i) { c[v] = true; return c }, {});
|
|
188
|
+
|
|
189
|
+
Vue.component('dummy', {
|
|
190
|
+
render: function (createElement) {
|
|
191
|
+
var this$1 = this;
|
|
192
|
+
|
|
193
|
+
var value = '';
|
|
194
|
+
var renderImage = false;
|
|
195
|
+
|
|
196
|
+
for (var i = 0; i < componentProps.length; i++) {
|
|
197
|
+
if(typeof this$1[componentProps[i]] !== 'undefined') {
|
|
198
|
+
value = this$1[componentProps[i]] + '';
|
|
199
|
+
renderImage = componentProps[i][0] === 'i' || value.indexOf('x') > 0;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return createElement(renderImage ? 'img' : 'span', {
|
|
204
|
+
directives: [{
|
|
205
|
+
name: renderImage ? 'dummy' : 'dummy-self',
|
|
206
|
+
value: value
|
|
207
|
+
}]
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
props: componentPropsObj
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
|
215
|
+
window.Vue.use(Plugin);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return Plugin;
|
|
219
|
+
|
|
220
|
+
}());
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-dummyy",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.1.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Placeholder Images and Dummy Text for Vue.js",
|
|
6
|
+
"main": "dist/vue-dummy.cjs.js",
|
|
7
|
+
"module": "dist/vue-dummy.es2015.js",
|
|
8
|
+
"jsdelivr": "dist/vue-dummy.js",
|
|
9
|
+
"unpkg": "dist/vue-dummy.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "npm update dummyjs --save && node ./build.js",
|
|
12
|
+
"dev": "npm run build && serve ./"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/vue-dummyy/vue-dummyy.git"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"vue",
|
|
23
|
+
"vue.js",
|
|
24
|
+
"dummy",
|
|
25
|
+
"placeholder",
|
|
26
|
+
"lorum",
|
|
27
|
+
"ipsum",
|
|
28
|
+
"test"
|
|
29
|
+
],
|
|
30
|
+
"author": "Paul Collett",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/vue-dummyy/vue-dummyy/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/vue-dummyy/vue-dummyy#readme",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"dummyjs": "^1.1.6",
|
|
38
|
+
"os-info-checker-es6": "^1.0.7"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"rollup": "^0.50.0",
|
|
42
|
+
"rollup-plugin-buble": "^0.16.0",
|
|
43
|
+
"rollup-plugin-commonjs": "^8.2.1",
|
|
44
|
+
"rollup-plugin-node-resolve": "^3.0.0",
|
|
45
|
+
"serve": "^6.2.0"
|
|
46
|
+
}
|
|
6
47
|
}
|