Skip to content

Commit

Permalink
Merge pull request #521 from RabotaRu/v3.10.0
Browse files Browse the repository at this point in the history
v3.10.0
  • Loading branch information
rpiontik committed Apr 9, 2024
2 parents 1d883d0 + da097ed commit de24af6
Show file tree
Hide file tree
Showing 15 changed files with 383 additions and 16 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ gantt
section Q3 2023
Iaas reverce tool :done, 2023-07-01, 92d
MVP Framework SEAF :done, 2023-07-01, 92d
MVP mutators :active, 2023-07-01, 150d
POC mutators :done, 2023-07-01, 150d
section Q4 2023
Framework SEAF :active, 2023-10-01, 92d
Time Machine :active, 2023-11-01, 90d
Public metamodel repository :active, 2023-10-01, 90d
section Q1 2024
Process Disigner tool :2024-01-01, 90d
Architectire Commutiny tool :2024-01-01, 90d
Framework SEAF :done, 2023-10-01, 92d
Time Machine :active, 2023-11-01, 250d
Public metamodel repository :active, 2023-10-01, 200d
section Q2 2024
MVP mutators :active, 2024-01-01, 200d
Process Disigner tool :2024-06-01, 90d
Architectire Commutiny tool :2024-06-01, 90d
click plugins href "https://dochub.info/docs/dochub.plugins.intro"
click smartants href "https://dochub.info/docs/dochub.smartants"
Expand Down Expand Up @@ -119,7 +120,7 @@ DocHub умеет находить проблемы в описании архи

## <a name="extmetamodel"></a> Расширяемая матамодель

Матемодель DocHub может быть расширена по вашему желанию. Есть возможность как модифицировать
Метамодель DocHub может быть расширена по вашему желанию. Есть возможность как модифицировать
уже существующие сущности, так и создавать собственные.

Познакомиться с идеей ближе можно в статье [Код архитектуры — это жидкость](https://habr.com/ru/post/701050/).
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"plugins/html",
"plugins/markaper",
"plugins/charts",
"plugins/devtool"
"plugins/devtool",
"plugins/svg"
]
}
169 changes: 169 additions & 0 deletions plugins/svg/components/SVGDocument.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<template>
<div v-if="showData" class="svg-image" v-html="content" />
<div v-else>
<p>Ключи не найдены в шаблоне:</p>
<li v-for="item in validate_result.not_found_in_svg" v-bind:key="item">
{{ item }}
</li>
<p>Ключи не найдены в результате запроса:</p>
<li v-for="item in validate_result.not_found_in_source" v-bind:key="item">
{{ item }}
</li>
</div>
</template>

<script>
import mustache from 'mustache';
export default {
name: 'SVGDocument',
props: {
// Требуем обязательно передавать профайл документа
profile: {
type: Object,
required: true
},
// Требуем обязательно передавать функцию получения контента
getContent: {
type: Function,
required: true
},
// Требуем обязательно передавать функцию доступа к Data Lake
pullData: {
type: Function,
required: true
},
// Требуем обязательно сообщать путь к объекту описывающему документ в коде
path: {
type: String,
required: true
},
// Запрашиваем параметры рендеринга
params: {
type: Object,
default: null
},
// Признак рендеринга для печати
toPrint: {
type: Boolean,
default: false
}
},
data() {
return {
showData: true,
// Обработчик события обновления
refresher: null,
// Здесь будет храниться контент из полученного SVG файла
content: '',
validate_result: {
not_found_in_svg : [],
not_found_in_source: []
},
data: null
};
},
watch: {
profile() {
// При изменении переметров, генерируем событие обновления
this.onRefresh();
}
},
mounted() {
// При монтировании компонента в DOM, генерируем событие обновления
this.onRefresh();
},
methods: {
// Функция обновления контента документа с учетом параметров содержащихся в "this.profile"
doRefresh() {
if (this.profile) {
this.pullData(this.profile.source)
.then( (data) => {
this.data = data;
})
.then( () => this.getContent(this.profile.template) )
// Если все хорошо, рендерим HTML "как есть"
.then((response) => {
if (this.params.check) {
this.showData = false;
this.checkTemplate(response.data, this.data);
} else {
this.showData = true;
this.content = mustache.render(response.data, this.data);
}
})
// Если что-то пошло не так, генерируем HTML с ошибкой
.catch((error) => {
this.content = `<div style="color:#fff; background-color: #f00">Ошибка выполнения запроса: <br> ${error}</div>`;
});
} else {
this.data = null;
this.content = '';
}
},
checkTemplate(template, data){
const ast = mustache.parse(template);
const res = this.validate_result;
res.not_found_in_svg = [];
res.not_found_in_source = [];
const keys_in_template = {};
// Формат структуры: ast - массив
// элементы массива:
// массив из 4 частей:
// 0 - тип части
// 1 - троковая константа / имя переменной
// 2 - смещение в файле начала фрагмента
// 3 - смещение в файле конца фрагмента
ast.map( (el) => {
const tp = el[0];
const vr = el[1];
if ( tp != 'name' ) return;
/* В шаблоне может быть несколько ссылок на один и тот же параметр, исключаем дубли */
if ( keys_in_template[vr] == 1 ) return;
keys_in_template[vr] = 1;
if ( vr in data) return;
res.not_found_in_source.push(vr);
} );
Object.keys(data).map( (el) => {
if ( el in keys_in_template ) return;
res.not_found_in_svg.push(el);
});
},
// Обработчик события обновления
onRefresh() {
// Если обработчик уже запущен, останавливаем его
if (this.refresher) clearTimeout(this.refresher);
// Для исключения избыточных обращений к Data Lake откладывам обноление на 50мс
this.refresher = setTimeout(this.doRefresh, 50);
}
}
};
</script>

<style scoped>
h2 {
margin-top: 24px;
}
td {
padding: 6px;
;
}
.space {
padding: 12px;
}
.label {
width: 20%;
}
.svg-image {
padding: 12px;
margin: 12px;
border: solid 1px #ccc;
}</style>
3 changes: 3 additions & 0 deletions plugins/svg/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import svg from './components/SVGDocument.vue';

DocHub.documents.register('svg', svg);
13 changes: 13 additions & 0 deletions plugins/svg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "dochub-plugin-svg",
"version": "1.0.0",
"description": "SVG document with templating support",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "I.Ermolin",
"license": "MIT",
"dependencies": {
}
}
36 changes: 35 additions & 1 deletion public/documentation/docs/manual/plugins/root.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,41 @@ docs:
head1:
type: test
source: examples/example.html

dochub.plugins.svg_file:
title: Пример использования SVG
type: svg
template: templates/test.svg
source: >
(
{
"component1": "Название компонента 1",
"line1_text1": "Текст для стрелки"
}
)
dochub.plugins.svg_file_error:
title: Проверка svg
type: svg
template: templates/test.svg
source: >
(
{
"component1": "Название компонента 1",
/* Намеренно допускаем ошибки */
/* Описываем несуществующие параметры */
/* и не указываем необходимые line1_text1 */
"component2": "Название компонента 2"
}
)
dochub.plugins.svg_inline:
title: Проверка вставки svg объекта
type: markdown
source: svg_inline.md
location: DocHub/Руководство/Плагины/Примеры/SVG

dochub.plugins.devtool_new:
location: DocHub/Руководство/Плагины/Примеры/DevTool
type: devtool

66 changes: 66 additions & 0 deletions public/documentation/docs/manual/plugins/svg_inline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Шаблонизация SVG файлов


Оригинальный шаблон:
![Шаблон](templates/test.svg)

Результат применения данных к шаблону:
```yaml
docs:
dochub.plugins.svg_file:
title: Проверка svg
type: svg
location: DocHub/Руководство/Плагины/Примеры/SVG/Пример svg
template: templates/test.svg
source: >
(
{
"component1": "Название компонента 1",
"line1_text1": "Текст для стрелки"
}
)
```

Результат:
```
![svg-документ](@document/dochub.plugins.svg_file)
```

![svg-документ](@document/dochub.plugins.svg_file)


# Проверка заполнения параметров в шаблоне

Есть возможность проверять корректность заполнения шаблона. Например:

```yaml
dochub.plugins.svg_file_error:
title: Проверка svg
type: svg
template: templates/test.svg
source: >
(
{
"component1": "Название компонента 1",
"component2": "Название компонента 2"
}
)
```

В примере намеренно допущены ошибки:
1. Указан несуществующий в шаблоне параметр "component2";
2. Не указан необходимый параметр "line1_text1".


Для выполнения проверки указывается специальный параметр check=1.

```
![svg-документ](@document/dochub.plugins.svg_file_error?check=1)
```

В результате будет список не найденных параметров в самом шаблоне и в запросе:

![svg-документ](@document/dochub.plugins.svg_file_error?check=1)



0 comments on commit de24af6

Please sign in to comment.