Skip to content

Commit d12ec19

Browse files
committed
add samples directory for creating sample playgrounds (wip)
1 parent 0d558a4 commit d12ec19

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

build/build-samples.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
const {parseComponent} = require('vue-template-compiler');
4+
5+
const samplesPath = path.resolve(__dirname, '../samples');
6+
const files = fs.readdirSync(samplesPath);
7+
8+
const samples = files.filter(file => file.endsWith('.vue')).map((name) => {
9+
const contents = fs.readFileSync(path.resolve(samplesPath, name));
10+
const sfc = parseComponent(contents.toString());
11+
return {
12+
name: name.replace('.vue', ''),
13+
files: [
14+
{key: 'app.js', contents: sfc.script.content},
15+
{key: 'app.css', contents: sfc.styles[0].content},
16+
]
17+
}
18+
});
19+
20+
const out = path.resolve(__dirname, '../static/samples.json');
21+
fs.writeFileSync(out, JSON.stringify(samples, null, 2));

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"dev": "node build/index.js --dev",
88
"build": "node build/index.js",
99
"build:css": "tailwind build src/styles.css -c ./tailwind.js -o static/styles.css",
10-
"build:js": "babel src -d static"
10+
"build:js": "babel src -d static",
11+
"build:samples": "node build/build-samples.js"
1112
},
1213
"keywords": [],
1314
"author": "Igor Randjelovic",
@@ -47,6 +48,7 @@
4748
"remark-squeeze-paragraphs": "^3.0.1",
4849
"table-of-contents-json": "^1.2.0",
4950
"tailwindcss": "^0.4.0",
50-
"vfile-reporter": "^4.0.0"
51+
"vfile-reporter": "^4.0.0",
52+
"vue-template-compiler": "^2.5.13"
5153
}
5254
}

samples/absolute-layout-grid.vue

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<script>
2+
const Vue = require("./nativescript-vue");
3+
4+
new Vue({
5+
template: `
6+
<AbsoluteLayout backgroundColor="#3c495e">
7+
<Label text="10,10" left="10" top="10" width="100" height="100" backgroundColor="#43b883"/>
8+
<Label text="120,10" left="120" top="10" width="100" height="100" backgroundColor="#43b883"/>
9+
<Label text="10,120" left="10" top="120" width="100" height="100" backgroundColor="#43b883"/>
10+
<Label text="120,120" left="120" top="120" width="100" height="100" backgroundColor="#43b883"/>
11+
</AbsoluteLayout>
12+
`,
13+
}).$start();
14+
</script>
15+
16+
<style>
17+
/*
18+
In NativeScript, the app.css file is where you place CSS rules that
19+
you would like to apply to your entire application. Check out
20+
http://docs.nativescript.org/ui/styling for a full list of the CSS
21+
selectors and properties you can use to style UI components.
22+
23+
/*
24+
In many cases you may want to use the NativeScript core theme instead
25+
of writing your own CSS rules. For a full list of class names in the theme
26+
refer to http://docs.nativescript.org/ui/theme.
27+
The imported CSS rules must precede all other types of rules.
28+
*/
29+
@import 'nativescript-theme-core/css/core.light.css';
30+
31+
label {
32+
font-size: 15;
33+
padding: 10;
34+
color: white;
35+
}
36+
</style>

static/samples.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"name": "absolute-layout-grid",
4+
"files": [
5+
{
6+
"key": "app.js",
7+
"contents": "\nconst Vue = require(\"./nativescript-vue\");\n\nnew Vue({\n template: `\n <AbsoluteLayout backgroundColor=\"#3c495e\">\n <Label text=\"10,10\" left=\"10\" top=\"10\" width=\"100\" height=\"100\" backgroundColor=\"#43b883\"/>\n <Label text=\"120,10\" left=\"120\" top=\"10\" width=\"100\" height=\"100\" backgroundColor=\"#43b883\"/>\n <Label text=\"10,120\" left=\"10\" top=\"120\" width=\"100\" height=\"100\" backgroundColor=\"#43b883\"/>\n <Label text=\"120,120\" left=\"120\" top=\"120\" width=\"100\" height=\"100\" backgroundColor=\"#43b883\"/>\n </AbsoluteLayout>\n `,\n}).$start();\n"
8+
},
9+
{
10+
"key": "app.css",
11+
"contents": "\n/*\nIn NativeScript, the app.css file is where you place CSS rules that\nyou would like to apply to your entire application. Check out\nhttp://docs.nativescript.org/ui/styling for a full list of the CSS\nselectors and properties you can use to style UI components.\n\n/*\nIn many cases you may want to use the NativeScript core theme instead\nof writing your own CSS rules. For a full list of class names in the theme\nrefer to http://docs.nativescript.org/ui/theme.\nThe imported CSS rules must precede all other types of rules.\n*/\n@import 'nativescript-theme-core/css/core.light.css';\n\nlabel {\n font-size: 15;\n padding: 10;\n color: white;\n}\n"
12+
}
13+
]
14+
}
15+
]

0 commit comments

Comments
 (0)