Skip to content

Commit

Permalink
close #2, support online edit (#3)
Browse files Browse the repository at this point in the history
* feat: support online edit with Codepen and JSFiddle and CodeSandbox

* ci: only deploy docs in master branch
  • Loading branch information
BuptStEve authored Feb 13, 2019
1 parent 29a214f commit fecfd97
Show file tree
Hide file tree
Showing 17 changed files with 648 additions and 122 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
version: 2
jobs:
build:
branches:
only:
- master

docker:
# specify the version you desire here
- image: circleci/node:latest
Expand Down
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a href="https://www.npmjs.com/package/vuepress-plugin-demo-code"><img src="https://img.shields.io/npm/l/vuepress-plugin-demo-code.svg" alt="License"></a>
</p>

English | [简体中文](README_cn.md)
English | [简体中文](https://buptsteve.github.io/vuepress-plugin-demo-code/zh/)

> demo-code plugin for vuepress.
Expand All @@ -28,6 +28,17 @@ export default {

[Please click here to see the demo](https://buptsteve.github.io/vuepress-plugin-demo-code/example/)

## Features
* Only one source code
* Foldable code
* Online edit support
* ✔ Codepen
* ✔ JSFiddle
* ✔ CodeSandbox
* Designed for long code
* Sticky fold button
* Auto scroll to top when you fold code

## Install

* First, install [vuepress v1.x](https://github.com/vuejs/vuepress)
Expand Down Expand Up @@ -56,16 +67,46 @@ This plugin supports the following configurations.
module.exports = {
plugins: [
['demo-code', {
jsLibs: [
// umd
'https://unpkg.com/tua-storage/dist/TuaStorage.umd.js',
],
cssLibs: [
'https://unpkg.com/[email protected]/animate.min.css',
],
showText: 'show code',
hideText: 'hide',
styleStr: 'text-decoration: underline;',
minHeight: 200,
onlineBtns: {
codepen: true,
jsfiddle: true,
codesandbox: true,
},
codesandbox: {
deps: { 'lodash': 'latest' },
json: '',
query: '',
embed: '',
},
demoCodeMark: 'demo-code',
}]
],
}
```

### jsLibs
* Type: `Array`
* Default: `[]`

Js libraries for the demo.

### cssLibs
* Type: `Array`
* Default: `[]`

Css libraries for the demo.

### showText
* Type: `String`
* Default: `show code`
Expand All @@ -84,6 +125,20 @@ The display text of fold code button.

The height of the code when it is folded.

### onlineBtns
* Type: `Object`
* Default: `{ codepen: true, jsfiddle: true, codesandbox: true }`

Display online edit buttons.

### codesandbox
* Type: `Object`
* Default: `{ deps: {}, json: '', query: 'module=App.vue'', embed: '' },`

It passes [CodeSandbox options](https://codesandbox.io/docs/importing#define-api).

> `deps` is dependencies
### demoCodeMark
* Type: `String`
* Default: `demo`
Expand Down
100 changes: 0 additions & 100 deletions README_cn.md

This file was deleted.

4 changes: 4 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ module.exports = {
},
head: [
['link', { rel: 'icon', href: `/favicon.ico` }],
['link', { rel: 'stylesheet', href: `https://unpkg.com/[email protected]/animate.min.css` }],
],
plugins: [
[demoCode, {
cssLibs: [
'https://unpkg.com/[email protected]/animate.min.css',
],
showText: 'show more',
hideText: 'hide',
minHeight: 200,
Expand Down
55 changes: 55 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ export default {

[Please click here to see the demo](./example/)

## Features
* Only one source code
* Foldable code
* Online edit support
* ✔ Codepen
* ✔ JSFiddle
* ✔ CodeSandbox
* Designed for long code
* Sticky fold button
* Auto scroll to top when you fold code

## Install

* First, install [vuepress v1.x](https://github.com/vuejs/vuepress)
Expand Down Expand Up @@ -56,16 +67,46 @@ This plugin supports the following configurations.
module.exports = {
plugins: [
['demo-code', {
jsLibs: [
// umd
'https://unpkg.com/tua-storage/dist/TuaStorage.umd.js',
],
cssLibs: [
'https://unpkg.com/[email protected]/animate.min.css',
],
showText: 'show code',
hideText: 'hide',
styleStr: 'text-decoration: underline;',
minHeight: 200,
onlineBtns: {
codepen: true,
jsfiddle: true,
codesandbox: true,
},
codesandbox: {
deps: { 'lodash': 'latest' },
json: '',
query: '',
embed: '',
},
demoCodeMark: 'demo-code',
}]
],
}
```

### jsLibs
* Type: `Array`
* Default: `[]`

Js libraries for the demo.

### cssLibs
* Type: `Array`
* Default: `[]`

Css libraries for the demo.

### showText
* Type: `String`
* Default: `show code`
Expand All @@ -84,6 +125,20 @@ The display text of fold code button.

The height of the code when it is folded.

### onlineBtns
* Type: `Object`
* Default: `{ codepen: true, jsfiddle: true, codesandbox: true }`

Display online edit buttons.

### codesandbox
* Type: `Object`
* Default: `{ deps: {}, json: '', query: 'module=App.vue'', embed: '' },`

It passes [CodeSandbox options](https://codesandbox.io/docs/importing#define-api).

> `deps` is dependencies
### demoCodeMark
* Type: `String`
* Default: `demo`
Expand Down
36 changes: 30 additions & 6 deletions docs/example/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Eaxmple
# Example

## Common Usage

Just wrapper your demo code between `::: demo` and `:::`.Then you can generate runnable demo and code.
Just wrapper your demo code between `::: demo` and `:::`. Then you will get runnable demo and code.

### Usage Example

```md
::: demo
<template>
<button @click="onClick">Click me!</button>
<button class="animated shake infinite" @click="onClick">Click me!</button>
</template>

<script>
Expand All @@ -19,14 +19,20 @@ export default {
},
}
</script>

<style>
button {
color: blue;
}
</style>
:::
```

### Result

::: demo
<template>
<button @click="onClick">Click me!</button>
<button class="animated shake infinite" @click="onClick">Click me!</button>
</template>

<script>
Expand All @@ -36,6 +42,12 @@ export default {
},
}
</script>

<style>
button {
color: blue;
}
</style>
:::

## Code Language
Expand All @@ -45,16 +57,28 @@ You may notice that the top right corner of the display code shows `vue`(default

```md
::: demo html
<p>
<p class="common-html">
this is <span style="color: red;">common</span> html
</p>

<style>
.common-html {
color: green;
}
</style>
:::
```

### Result

::: demo html
<p>
<p class="common-html">
this is <span style="color: red;">common</span> html
</p>

<style>
.common-html {
color: green;
}
</style>
:::
Loading

0 comments on commit fecfd97

Please sign in to comment.