Artifact picker functionality for docs site
This commit is contained in:
parent
6f025b9a95
commit
27daced93e
4
docs/.vuepress/.artifacts.js
Normal file
4
docs/.vuepress/.artifacts.js
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
// this is a generated file, do not modify. To update it run 'collectArtifacts.js' script
|
||||
const artifacts = [{"id":"markwon","name":"Markwon","group":"ru.noties","description":"Core Markwon artifact that includes basic markdown parsing and rendering"},{"id":"markwon-ext-strikethrough","name":"Markwon-Ext-Strikethrough","group":"ru.noties"},{"id":"markwon-html-parser-impl","name":"Markwon","group":"ru.noties"},{"id":"markwon-syntax-highlight","name":"Markwon","group":"ru.noties"},{"id":"markwon-view","name":"Markwon-View","group":"ru.noties"}];
|
||||
export { artifacts };
|
122
docs/.vuepress/components/ArtifactPicker.vue
Normal file
122
docs/.vuepress/components/ArtifactPicker.vue
Normal file
@ -0,0 +1,122 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="artifact-container">
|
||||
<div v-for="artifact in artifacts" class="artifact" @click="toggleSelection(artifact)">
|
||||
<div class="artifact-header">
|
||||
<input
|
||||
type="checkbox"
|
||||
v-model="selected"
|
||||
:value="artifact.id"
|
||||
:id="artifact.id" />
|
||||
<strong><label :for="artifact.id">{{artifact.name}}</label></strong>
|
||||
</div>
|
||||
<div class="artifact-description" v-if="artifact.description">{{artifact.description}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="extra-class language-gradle selected-artifacts"
|
||||
v-if="selected.length > 0"
|
||||
@click="selectAll"
|
||||
>
|
||||
<div class="selected-artifact-script">
|
||||
<span class="token keyword">final def</span> markwon_version = <span class="token string">'latest_version'</span>
|
||||
</div>
|
||||
<br>
|
||||
<div class="selected-artifact-script" v-for="artifact in selectedArtifacts">
|
||||
<span>implementation </span><span class="token string">"{{artifact.group}}:{{artifact.id}}:</span><span>$markwon_version</span><span class="token string">"</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import {artifacts} from '../.artifacts.js';
|
||||
|
||||
if (!artifacts) {
|
||||
throw 'Artifacts not found. Use `collectArtifacts.js` script to obtain artificats metadata.'
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "ArtifactPicker",
|
||||
data() {
|
||||
return {
|
||||
artifacts,
|
||||
selected: []
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
selectAll(e) {
|
||||
let el = e.target;
|
||||
while (!el.classList.contains("selected-artifacts")) {
|
||||
el = el.parentElement;
|
||||
}
|
||||
|
||||
if (document.body.createTextRange) {
|
||||
const range = document.body.createTextRange();
|
||||
range.moveToElementText(el);
|
||||
range.select();
|
||||
} else if (window.getSelection) {
|
||||
const selection = window.getSelection();
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(el);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
}
|
||||
},
|
||||
toggleSelection(artifact) {
|
||||
const index = this.selected.indexOf(artifact.id)
|
||||
if (index < 0) {
|
||||
this.selected.push(artifact.id);
|
||||
} else {
|
||||
this.selected.splice(index, 1);
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
selectedArtifacts() {
|
||||
return this.artifacts.filter(a => this.selected.indexOf(a.id) >= 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.artifact-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-direction: row;
|
||||
}
|
||||
.artifact {
|
||||
flex: 1;
|
||||
border: 1px #ccc solid;
|
||||
background-color: #fafafa;
|
||||
padding: 0.5em;
|
||||
margin: 0.2em;
|
||||
border-radius: 0.25em;
|
||||
min-width: 10em;
|
||||
max-width: 10em;
|
||||
}
|
||||
.artifact-description {
|
||||
font-size: 0.85em;
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
.selected-artifacts {
|
||||
color: white;
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
|
||||
monospace;
|
||||
padding: 16px;
|
||||
text-align: left;
|
||||
word-spacing: normal;
|
||||
word-break: normal;
|
||||
word-wrap: normal;
|
||||
line-height: 1.5;
|
||||
-moz-tab-size: 4;
|
||||
hyphens: none;
|
||||
font-size: 0.85em;
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
.selected-artifact-script {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,3 @@
|
||||
div[class~=language-gradle]:before {
|
||||
content:"gradle"
|
||||
}
|
50
docs/collectArtifacts.js
Normal file
50
docs/collectArtifacts.js
Normal file
@ -0,0 +1,50 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const PROPERTIES_FILE_NAME = 'gradle.properties';
|
||||
const PROP_GROUP = 'GROUP';
|
||||
const PROP_DESCRIPTION = 'POM_DESCRIPTION';
|
||||
const PROP_ARTIFACT_NAME = 'POM_NAME';
|
||||
const PROP_ARTIFACT_ID = 'POM_ARTIFACT_ID';
|
||||
|
||||
const readProperties = (file) => fs.readFileSync(file, { encoding: 'utf-8' }, 'string')
|
||||
.split('\n')
|
||||
// filter-out empty lines
|
||||
.filter(s => s)
|
||||
.map(s => s.split('='))
|
||||
.reduce((a, s) => {
|
||||
a[s[0]] = s[1];
|
||||
return a;
|
||||
}, {});
|
||||
|
||||
const listDirectories = (folder) => fs.readdirSync(folder)
|
||||
.map(name => path.join(folder, name))
|
||||
.filter(f => fs.lstatSync(f).isDirectory());
|
||||
|
||||
const projectDir = path.resolve(__dirname, '../');
|
||||
|
||||
const projectProperties = readProperties(path.join(projectDir, PROPERTIES_FILE_NAME));
|
||||
|
||||
const projectGroup = projectProperties[PROP_GROUP]
|
||||
|
||||
const artifacts = listDirectories(projectDir)
|
||||
.map(dir => path.join(dir, PROPERTIES_FILE_NAME))
|
||||
.filter(f => fs.existsSync(f))
|
||||
.map(readProperties)
|
||||
.map(props => {
|
||||
return {
|
||||
id: props[PROP_ARTIFACT_ID],
|
||||
name: props[PROP_ARTIFACT_NAME],
|
||||
group: projectGroup,
|
||||
description: props[PROP_DESCRIPTION]
|
||||
}
|
||||
});
|
||||
|
||||
const artifactsFile = path.join(__dirname, '.vuepress', '.artifacts.js');
|
||||
const artifactsJs = `
|
||||
// this is a generated file, do not modify. To update it run 'collectArtifacts.js' script
|
||||
const artifacts = ${JSON.stringify(artifacts)};
|
||||
export { artifacts };
|
||||
`
|
||||
|
||||
fs.writeFileSync(artifactsFile, artifactsJs);
|
6
docs/package-lock.json
generated
6
docs/package-lock.json
generated
@ -5465,9 +5465,9 @@
|
||||
}
|
||||
},
|
||||
"linkify-it": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.0.3.tgz",
|
||||
"integrity": "sha1-2UpGSPmxwXnWT6lykSaL22zpQ08=",
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.1.0.tgz",
|
||||
"integrity": "sha512-4REs8/062kV2DSHxNfq5183zrqXMl7WP0WzABH9IeJI+NLm429FgE1PDecltYfnOoFDFlZGh2T8PfZn0r+GTRg==",
|
||||
"requires": {
|
||||
"uc.micro": "^1.0.1"
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"scripts": {
|
||||
"docs:build": "vuepress build"
|
||||
"docs:build": "node ./collectArtifacts.js && vuepress build"
|
||||
},
|
||||
"dependencies": {
|
||||
"markdown-it-task-lists": "^2.1.1",
|
||||
|
@ -1,3 +1,4 @@
|
||||
POM_NAME=Markwon
|
||||
POM_ARTIFACT_ID=markwon
|
||||
POM_PACKAGING=aar
|
||||
POM_DESCRIPTION=Core Markwon artifact that includes basic markdown parsing and rendering
|
Loading…
x
Reference in New Issue
Block a user