Skip to content

Commit

Permalink
Support text field appendix
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jan 29, 2024
1 parent 11c9ed5 commit 6f24bbb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ hr {
top: 1px;
}

.appendix-textfield {
text-align: left;
padding: 10px;
}

.appendix .inputs {
display: inline-block;
vertical-align: middle;
Expand Down
3 changes: 3 additions & 0 deletions bin/generate-infobook-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {InfoBookAppendixHandlerCraftingRecipe} from "../lib/infobook/appendix/In
import {InfoBookAppendixHandlerSmeltingRecipe} from "../lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe";
import {InfoBookAppendixHandlerImage} from "../lib/infobook/appendix/InfoBookAppendixHandlerImage";
import {InfoBookAppendixHandlerKeybinding} from "../lib/infobook/appendix/InfoBookAppendixHandlerKeybinding";
import {InfoBookAppendixHandlerTextfield} from "../lib/infobook/appendix/InfoBookAppendixHandlerTextfield";
import {IInfoBook} from "../lib/infobook/IInfoBook";
import {IInfobookPlugin} from "../lib/infobook/IInfobookPlugin";
import {InfoBookInitializer} from "../lib/infobook/InfoBookInitializer";
Expand Down Expand Up @@ -75,6 +76,8 @@ async function create() {
new InfoBookAppendixHandlerImage(resourceLoader.getResourceHandler()));
infoBookInitializer.registerAppendixHandler('keybinding',
new InfoBookAppendixHandlerKeybinding(resourceLoader.getResourceHandler()));
infoBookInitializer.registerAppendixHandler('textfield',
new InfoBookAppendixHandlerTextfield(resourceLoader.getResourceHandler()));

// Load plugins
const assetsPaths = [];
Expand Down
30 changes: 30 additions & 0 deletions lib/infobook/appendix/InfoBookAppendixHandlerTextfield.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {ResourceHandler} from "../../resource/ResourceHandler";
import {ISerializeContext} from "../../serialize/HtmlInfoBookSerializer";
import {IFileWriter} from "../IFileWriter";
import {IInfoAppendix} from "../IInfoAppendix";
import {IInfoBookAppendixHandler} from "./IInfoBookAppendixHandler";

/**
* Handles text field appendices.
*/
export class InfoBookAppendixHandlerTextfield implements IInfoBookAppendixHandler {

private readonly resourceHandler: ResourceHandler;

constructor(resourceHandler: ResourceHandler) {
this.resourceHandler = resourceHandler;
}

public createAppendix(data: any): IInfoAppendix {
const contents = data._
.replace(/ /g, ' ')
.replace(/\n/g, '<br \>');
const scale = data.$.scale || 1;
return {
toHtml: (context: ISerializeContext, fileWriter: IFileWriter) => {
return `<div class="appendix-textfield" style="font-size: ${scale}em">${contents}</div>`;
},
};
}

}

0 comments on commit 6f24bbb

Please sign in to comment.