UNPKG

2.59 kBMarkdownView Raw
1# github-embed
2
3**in development**
4
5The tool allows to embed code from Github and keep embedding always up to date.
6
7*Currently this project isn't promoted and not tested because of embedding complexity. It's used only for my own purposes for now. If you have some ideas how to make embedding easier, let me know.*
8
9```
10npm i -D github-embed
11```
12
13```js
14const githubEmbed()
15```
16
17![](http://i.imgur.com/LmUAogr.png)
18
19## Getting started
20
21As the first step you need to do is to create ``.gh-embed.json`` somewhere in your repo (usually in root). This file means embedding settings file and it must contain valid JSON. It's made to keep file paths always up to date: when you change file structure of a project, you need to change the only gh-embed file, you don't need to worry about all places where your code is embedded. This is the main idea of this tool.
22
23The second step to fill ``.gh-embed.json`` by settings described below.
24
25The third step is to add a script to a page:
26```js
27githubEmbed(node, pathToSettings);
28```
29Where ``node`` is a mount node (``Node`` instance, ``jQuery`` instance, selector) and ``pathToSettings`` is a path to ``.gh-embed.json``.
30
31Example:
32```js
33githubEmbed('.embed', 'https://github.com/matreshkajs/examples/blob/gh-pages/treeview/.gh-embed.json');
34```
35
36## .gh-embed.json
37
38The file needs to contain a key ``"embed"`` which contains an array of embedded files (other top-level settings can be added later). An item of this array should include the following keys:
39
40``path: STRING`` - a path to embedded file relative to root of the repo (required).
41``type: STRING`` - a type of the file you need to embed (programming language).
42``label: STRING`` - what to display in navigation. By default it's a name of embedded file.
43``active: BOOLEAN`` - is the item shown by default
44
45There is one more thing: you can add to your embedding list any webpage. It could be useful if you want to show how does your web tool works. You need to set type option as ``"htmlpage"`` and assign weppagee URL to ``"url"`` property
46
47
48```js
49{
50 "linenums": true,
51 "embed": [{
52 "type": "htmlpage",
53 "url": "//matreshkajs.github.io/matreshka_examples/treeview/"
54 }, {
55 "type": "js",
56 "label": "app.js",
57 "path": "treeview/js/app.js"
58 }, {
59 "type": "js",
60 "label": "tree.class.js",
61 "path": "treeview/js/tree.class.js"
62 }, {
63 "type": "js",
64 "label": "tree-leaf.class.js",
65 "path": "treeview/js/tree-leaf.class.js"
66 }]
67}
68```
69
70
71## Todo
72- Semantic-release
73- Deploy bundle on github
74- Deploy CSS file on npm
75- App error handling
76- Allow to use an object instead of external file
77- Eslint