0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-29 22:02:46 +00:00

Partial implementation

This commit is contained in:
David Bolack
2024-11-01 14:02:27 -05:00
parent bb057ba057
commit 4448410c3e
6 changed files with 75 additions and 3 deletions

View File

@@ -1,6 +1,65 @@
const _ = require('lodash');
const yaml = require('js-yaml');
const request = require('../client/homebrew/utils/request-middleware.js');
const dedent = require('dedent');
// Convert the templates from a brew to a Snippets Structure.
const brewSnippetsToJSON = (menuTitle, userBrewSnippets, themeBundleSnippets)=>{
const textSplit = /^\\page/gm;
const mpAsSnippets = [];
// Snippets from Themes first.
if(themeBundleSnippets) {
for (let themes of themeBundleSnippets) {
const userSnippets = [];
for (let snips of themes.snippets.split(textSplit)) {
const name = snips.split('\n')[0];
if(name.length != 0) {
userSnippets.push({
name : name,
icon : '',
gen : snips.split('\n').slice(0),
});
}
}
if(userSnippets.length > 0) {
mpAsSnippets.push({
name : themes.name,
icon : '',
gen : '',
subsnippets : userSnippets
});
}
}
}
// Local Snippets
if(userBrewSnippets) {
const userSnippets = [];
for (let snips of userBrewSnippets.split(textSplit)) {
let name = mp.split('\n')[0];
if(name.length != 0) {
userSnippets.push({
name : name,
icon : '',
gen : snips.split('\n').slice(0),
});
}
}
if(userSnippets.length) {
mpAsSnippets.push({
name : menuTitle,
icon : '',
subsnippets : userSnippets
});
}
}
return {
groupName : 'Brew Snippets',
icon : 'fas fa-th-list',
view : 'text',
snippets : mpAsSnippets
};
};
const splitTextStyleAndMetadata = (brew)=>{
brew.text = brew.text.replaceAll('\r\n', '\n');
@@ -55,4 +114,5 @@ module.exports = {
splitTextStyleAndMetadata,
printCurrentBrew,
fetchThemeBundle,
brewSnippetsToJSON
};