/**
* Dialog for preformat code insertation
* @author Roman Ozana <ozana@omdesign.cz>
*/
var omPreDialog = (function ($) {
var _modal = _decDictionary = _options = {};
var _editor, _encRegex, _node;
var _tags = {
precode: { open: '<pre><code>', close: '</code></pre>' },
pre: { open: '<pre>', close: '</pre>'},
code: { open: '<code>', close: '</code>' }
};
var _encoding = { '<': 'lt', '>': 'gt', '"': 'quot', '&': 'amp' };
/**
* Wrap code with tags
* @param string code
* @param wrapper
* @return {*}
* @private
*/
var _wrapCode = function _wrapCode(code, wrapper) {
return _tags[wrapper].open + code + _tags[wrapper].close;
}
/**
* Encode common HTML elements
* @param text
* @return {*|void}
* @private
*/
var _processCode = function _processCode(content, spaces) {
content = content.replace(_encRegex, function (char) {
return '&' + _encoding[char] + ';';
});
// replace tab with spaces
if (spaces) content = content.replace(/\t/g, ' ');
return content;
}
return {
getModalBody: function () {
var style = 'float:left;margin-right:8px;';
return [
{
type: 'textbox',
name: 'omCode',
label: '',
value: this.getContent(),
multiline: true,
autofocus: true,
minWidth: 820,
minHeight: 420
},
{
type: 'container',
style: "height:32px",
items: [
{
type: 'listbox',
name: 'omCodeWrapper',
style: style,
value: this.getCodeWrapper(),
values: [
{text: '<pre><code>', value: 'precode'},
{text: '<pre>', value: 'pre'},
{text: '<code>', value: 'code'}
]
},
{name: 'omSpaces', type: 'checkbox', checked: true, text: 'nahradit taby mezerama', style: style + 'margin-top: 6px'}
]
}
]
},
init: function () {
// Dinamically init the decoding dictionary and the encoding regex
var char_list = '';
for (var ch in _encoding) {
char_list += ch;
_decDictionary[ _encoding[ch] ] = ch
}
_encRegex = new RegExp('[' + char_list + ']', 'g');
},
open: function (editor, url) {
_editor = editor;
_node = editor.selection.getNode(); // current node
_modal = editor.windowManager.open({
id: 'omPreDialog_wrapper',
title: 'Vložit preformátovaný kód',
pading: 0,
dialogClass: 'wp-dialog',
zIndex: 99999,
body: this.getModalBody(),
onsubmit: function (e) {
if (e.data.omCode) {
console.log(e.data);
omPreDialog.updateContent(
e.data.omCode,
e.data.omCodeWrapper,
e.data.omSpaces
)
} else {
e.preventDefault();
}
}
}
);
},
getCodeWrapper: function () {
if (_editor.selection.getContent() || _node.nodeName == 'CODE') return 'code';
if (_node.nodeName == 'PRE') return 'pre';
if (_node.nodeName == 'CODE' && _node.parentNode.nodeName == 'PRE') return 'precode';
},
getContent: function () {
if (_node.nodeName == 'PRE' || _node.nodeName == 'CODE') {
return _editor.selection.getNode().innerText;
}
if (_editor.selection.getContent()) return _editor.selection.getContent();
},
updateContent: function (code, wrapper, spaces) {
var code = _wrapCode(_processCode(code, spaces), wrapper); // handle code
// have some tags? select them
if (_node.nodeName == 'PRE' || _node.nodeName == 'CODE') {
if (_node.nodeName == 'CODE' && _node.parentNode.nodeName == 'PRE') {
_editor.selection.select(_node.parentNode);
} else {
_editor.selection.select(_node);
}
}
// split paragraph to two new when
if (_node.nodeName == 'CODE' && _node.parentNode.nodeName == 'P' && wrapper != 'code') _node.remove();
if (_editor.selection.getContent()) {
return _editor.selection.setContent(code);
}
// just insert new one
return _editor.execCommand('mceInsertContent', false, code);
}
};
})(jQuery);
const babel = require('@babel/core')
const log = require('@ui5/logger').getLogger('ui5-task-babel')
const _wrapCode = code => `(function() {\n'use strict';\n\n${code}\n})()`
/**
* Custom UI5 task for transpiling code using babel.
*
* @param {Object} parameters Parameters
* @param {DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {AbstractReader} parameters.dependencies Reader or Collection to read dependency files
* @param {Object} parameters.options Options
* @param {string} parameters.options.projectName Project name
* @param {string} [parameters.options.configuration] Task configuration if given in ui5.yaml
* @returns {Promise<undefined>} Promise resolving with undefined once data has been written
*/
module.exports = async ({ workspace, options }) => {
// get options / defaults
const { configuration = {} } = options
const { enabled = true, debug = false, wrap = true, files = ['**/*.js'] } = configuration
// skip task
if (!enabled) {
return
}
// match resources
const resources = await workspace.byGlob(files)
// transform resources concurrently
await Promise.all(resources.map(async resource => {
if (debug) {
log.info(`Transforming file: ${resource.getPath()}`)
}
const code = await resource.getString()
const result = await babel.transformAsync(code)
const transformed = wrap ? _wrapCode(result.code) : result.code
resource.setString(transformed)
await workspace.write(resource)
}))
}
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// @ts-check
const Documentation = require('./documentation');
const { visitAll } = require('../markdown');
/**
* @param {Documentation.MarkdownNode[]} nodes
* @param {number} maxColumns
*/
function renderXmlDoc(nodes, maxColumns = 80, prefix = '/// ') {
if (!nodes)
return [];
const renderResult = _innerRenderNodes(nodes, maxColumns);
const doc = [];
_wrapInNode('summary', renderResult.summary, doc);
_wrapInNode('remarks', renderResult.remarks, doc);
return doc.map(x => `${prefix}${x}`);
}
function _innerRenderNodes(nodes, maxColumns = 80, wrapParagraphs = true) {
const summary = [];
const remarks = [];
const handleListItem = (lastNode, node) => {
if (node && node.type === 'li' && (!lastNode || lastNode.type !== 'li'))
summary.push(`<list type="${node.liType}">`);
else if (lastNode && lastNode.type === 'li' && (!node || node.type !== 'li'))
summary.push('</list>');
};
let lastNode;
visitAll(nodes, node => {
// handle special cases first
if (_nodeShouldBeIgnored(node))
return;
if (node.text && node.text.startsWith('extends: ')) {
remarks.push('Inherits from ' + node.text.replace('extends: ', ''));
return;
}
handleListItem(lastNode, node);
if (node.type === 'text') {
if (wrapParagraphs)
_wrapInNode('para', _wrapAndEscape(node, maxColumns), summary);
else
summary.push(..._wrapAndEscape(node, maxColumns));
} else if (node.type === 'code' && node.codeLang === 'csharp') {
_wrapInNode('code', _wrapCode(node.lines), summary);
} else if (node.type === 'li') {
_wrapInNode('item><description', _wrapAndEscape(node, maxColumns), summary, '/description></item');
} else if (node.type === 'note') {
_wrapInNode('para', _wrapAndEscape(node, maxColumns), remarks);
}
lastNode = node;
});
handleListItem(lastNode, null);
return { summary, remarks };
}
function _wrapCode(lines) {
let i = 0;
let out = [];
for (let line of lines) {
line = line.replace(/[&]/g, '&').replace(/</g, '<').replace(/>/g, '>');
if (i < lines.length - 1)
line = line + "<br/>";
out.push(line);
i++;
}
return out;
}
function _wrapInNode(tag, nodes, target, closingTag = null) {
if (nodes.length === 0)
return;
if (!closingTag)
closingTag = `/${tag}`;
if (nodes.length === 1) {
target.push(`<${tag}>${nodes[0]}<${closingTag}>`);
return;
}
target.push(`<${tag}>`);
target.push(...nodes);
target.push(`<${closingTag}>`);
}
/**
*
* @param {Documentation.MarkdownNode} node
*/
function _wrapAndEscape(node, maxColumns = 0) {
const lines = [];
const pushLine = text => {
if (text === '')
return;
text = text.trim();
lines.push(text);
};
let text = node.text;
text = text.replace(/\[([^\]]*)\]\((.*?)\)/g, (match, linkName, linkUrl) => {
return `<a href="${linkUrl}">${linkName}</a>`;
});
text = text.replace(/(?<!`)\[(.*?)\]/g, (match, link) => `<see cref="${link}"/>`);
text = text.replace(/`([^`]*)`/g, (match, code) => `<c>${code.replace(/</g, '<').replace(/>/g, '>')}</c>`);
text = text.replace(/ITimeoutError/, 'TimeoutException');
text = text.replace(/Promise/, 'Task');
const words = text.split(' ');
let line = '';
for (let i = 0; i < words.length; i++) {
line = line + ' ' + words[i];
if (line.length >= maxColumns) {
pushLine(line);
line = '';
}
}
pushLine(line);
return lines;
}
/**
*
* @param {Documentation.MarkdownNode} node
*/
function _nodeShouldBeIgnored(node) {
if (!node
|| (node.text === 'extends: [EventEmitter]'))
return true;
return false;
}
/**
* @param {Documentation.MarkdownNode[]} nodes
*/
function renderTextOnly(nodes, maxColumns = 80) {
const result = _innerRenderNodes(nodes, maxColumns, false);
return result.summary;
}
module.exports = { renderXmlDoc, renderTextOnly }
Accelerate Your Automation Test Cycles With LambdaTest
Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.