0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-08 18:22:40 +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

@@ -10,7 +10,7 @@ orbs:
jobs: jobs:
build: build:
docker: docker:
- image: cimg/node:20.17.0 - image: cimg/node:20.18.0
- image: mongo:4.4 - image: mongo:4.4
working_directory: ~/homebrewery working_directory: ~/homebrewery

View File

@@ -6,6 +6,7 @@ const _ = require('lodash');
const cx = require('classnames'); const cx = require('classnames');
import { loadHistory } from '../../utils/versionHistory.js'; import { loadHistory } from '../../utils/versionHistory.js';
import { brewSnippetsToJSON } from '../../../../shared/helpers.js';
//Import all themes //Import all themes
const ThemeSnippets = {}; const ThemeSnippets = {};
@@ -114,6 +115,9 @@ const Snippetbar = createClass({
oldSnippets = _.keyBy(compiledSnippets, 'groupName'); oldSnippets = _.keyBy(compiledSnippets, 'groupName');
} }
const userSnippetsasJSON = brewSnippetsToJSON(this.props.brew.title, this.props.brew.snippets, this.props.snippetsBundle);
compiledSnippets.push(userSnippetsasJSON);
return compiledSnippets; return compiledSnippets;
}, },

View File

@@ -61,6 +61,7 @@ const EditPage = createClass({
currentEditorCursorPageNum : 1, currentEditorCursorPageNum : 1,
currentBrewRendererPageNum : 1, currentBrewRendererPageNum : 1,
displayLockMessage : this.props.brew.lock || false, displayLockMessage : this.props.brew.lock || false,
snippetsBundle : {},
themeBundle : {} themeBundle : {}
}; };
}, },
@@ -440,6 +441,7 @@ const EditPage = createClass({
reportError={this.errorReported} reportError={this.errorReported}
renderer={this.state.brew.renderer} renderer={this.state.brew.renderer}
userThemes={this.props.userThemes} userThemes={this.props.userThemes}
snippets={this.props.snippets}
snippetBundle={this.state.themeBundle.snippets} snippetBundle={this.state.themeBundle.snippets}
updateBrew={this.updateBrew} updateBrew={this.updateBrew}
onCursorPageChange={this.handleEditorCursorPageChange} onCursorPageChange={this.handleEditorCursorPageChange}

View File

@@ -3,8 +3,8 @@
"description": "Create authentic looking D&D homebrews using only markdown", "description": "Create authentic looking D&D homebrews using only markdown",
"version": "3.16.0", "version": "3.16.0",
"engines": { "engines": {
"npm": "^10.2.x", "npm": "^10.8.x",
"node": "^20.17.x" "node": "^20.18.x"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -170,6 +170,12 @@ const api = {
`\`\`\`\n\n` + `\`\`\`\n\n` +
`${text}`; `${text}`;
} }
if(brew.snippets !== undefined) {
text = `\`\`\`snippets\n` +
`${brew.snippets || ''}\n` +
`\`\`\`\n\n` +
`${text}`;
}
const metadata = _.pick(brew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme']); const metadata = _.pick(brew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme']);
text = `\`\`\`metadata\n` + text = `\`\`\`metadata\n` +
`${yaml.dump(metadata)}\n` + `${yaml.dump(metadata)}\n` +

View File

@@ -1,6 +1,65 @@
const _ = require('lodash'); const _ = require('lodash');
const yaml = require('js-yaml'); const yaml = require('js-yaml');
const request = require('../client/homebrew/utils/request-middleware.js'); 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)=>{ const splitTextStyleAndMetadata = (brew)=>{
brew.text = brew.text.replaceAll('\r\n', '\n'); brew.text = brew.text.replaceAll('\r\n', '\n');
@@ -55,4 +114,5 @@ module.exports = {
splitTextStyleAndMetadata, splitTextStyleAndMetadata,
printCurrentBrew, printCurrentBrew,
fetchThemeBundle, fetchThemeBundle,
brewSnippetsToJSON
}; };