String border = createStringOfLength(nodeLength, '=') + ' ' + createStringOfLength(commentLength, '=') + ' ' + createStringOfLength(typeLength, '=') + ' ' + createStringOfLength(defaultLength, '='); configSection.append(padToLength("Node", nodeLength + 1)).append(padToLength("Comment", commentLength + 1)).append(padToLength("Type", typeLength + 1)).append(padToLength("Default", defaultLength + 1)).append('\n'); configSection.append(border).append('\n'); for(ConfigValue<?> configValue : provider.getConfigurationNodes()) { configValue.serializeDefault(node); configSection.append(padToLength(configValue.getKey(), nodeLength + 1)).append(padToLength(configValue.getComment(), commentLength + 1)).append(padToLength(configValue.getTypeToken().getRawType().getSimpleName(), typeLength + 1)).append(padToLength(node.getString("null"), defaultLength + 1)).append('\n'); input = PERMS_PATTERN.matcher(input).replaceAll(Matcher.quoteReplacement(generatePermissionsSection(Arrays.asList(provider.getPermissionNodes())))); while(importMatcher.find()) { String fileDir = importMatcher.group(1); File file = new File(new File(getRootDirectory(), "templates/" + provider.getTemplatePath() + ".rst").getParentFile(), fileDir + ".rst"); input = input.replace("%IMPORT " + fileDir + '%', makeReplacements(loadFile(file), provider));
public static void generateDocumentation(DocumentationProvider provider) { File docFile = new File(getRootDirectory(), "source/" + provider.getPath() + ".rst"); docFile.getParentFile().mkdirs(); File template = new File(getRootDirectory(), "templates/" + provider.getTemplatePath() + ".rst"); if (!template.exists()) { CraftBookAPI.inst().getLogger().warn("Failed to find template for " + provider.getPath()); return; } String output = makeReplacements(loadFile(template), provider); try(PrintWriter writer = new PrintWriter(docFile)) { writer.write(output); } catch(IOException e) { CraftBookAPI.inst().getLogger().error("An IO Exception occured.", e); } }
public static String generatePermissionsSection(List<PermissionNode> nodes) { StringBuilder permissionsSection = new StringBuilder(); if(nodes.size() > 0) { permissionsSection.append("Permissions\n"); permissionsSection.append("===========\n\n"); int nodeLength = "Node".length(), descriptionLength = "Description".length(), defaultRoleLength = "Default Role".length(); for(PermissionNode permissionNode : nodes) { if(permissionNode.getNode().length() > nodeLength) nodeLength = permissionNode.getNode().length(); if(permissionNode.getDescription().length() > descriptionLength) descriptionLength = permissionNode.getDescription().length(); if(permissionNode.getDefaultRole().length() > defaultRoleLength) defaultRoleLength = permissionNode.getDefaultRole().length(); } String border = createStringOfLength(nodeLength, '=') + ' ' + createStringOfLength(descriptionLength, '=') + ' ' + createStringOfLength(defaultRoleLength, '='); permissionsSection.append(border).append('\n'); permissionsSection.append(padToLength("Node", nodeLength + 1)).append(padToLength("Description", descriptionLength + 1)).append(padToLength("Default Role", defaultRoleLength + 1)).append('\n'); permissionsSection.append(border).append('\n'); for(PermissionNode permissionNode : nodes) { permissionsSection.append(padToLength(permissionNode.getNode(), nodeLength + 1)).append(padToLength(permissionNode.getDescription(), descriptionLength + 1)).append(padToLength(permissionNode.getDefaultRole(), defaultRoleLength + 1)).append('\n'); } permissionsSection.append(border).append('\n'); } return permissionsSection.toString(); }
input = IC_PERMISSIONS_PATTERN.matcher(input).replaceAll(Matcher.quoteReplacement(DocumentationGenerator.generatePermissionsSection(Lists.newArrayList(permissionNode)))); input = IC_CONFIGURATION_PATTERN.matcher(input).replaceAll(Matcher.quoteReplacement("")); String icHeader = createStringOfLength(modelId.length(), '=') + '\n' + modelId + '\n' + createStringOfLength(modelId.length(), '=');
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { for (ModuleWrapper module : CraftBookPlugin.spongeInst().moduleController.getModules()) { if(!module.isEnabled()) continue; try { Mechanic mechanic = (Mechanic) ((SpongeModuleWrapper) module).getModuleUnchecked(); if(mechanic instanceof DocumentationProvider) DocumentationGenerator.generateDocumentation((DocumentationProvider) mechanic); } catch (ModuleNotInstantiatedException e) { CraftBookPlugin.spongeInst().getLogger().error("Failed to generate docs for module: " + module.getName(), e); } } DocumentationGenerator.generateDocumentation(CraftBookPlugin.spongeInst().getConfig()); return CommandResult.success(); } }
@Override public String performCustomConversions(String input) { StringBuilder headTable = new StringBuilder(); headTable.append("Mob Head Drops\n"); headTable.append("=================\n\n"); headTable.append("HeadDrops supports all mob heads in the base game, as well as many more.\n\n"); int mobTypeLength = "Mob".length(), headImageLength = "Image".length(); for(Map.Entry<EntityType, GameProfile> entry : mobSkullMap.entrySet()) { if(entry.getKey().getName().length() > mobTypeLength) mobTypeLength = entry.getKey().getName().length(); if((".. image:: https://minotar.net/helm/" + entry.getValue().getName().orElse("") + "/64.png").length() > headImageLength) headImageLength = (".. image:: https://minotar.net/helm/" + entry.getValue().getName().orElse("") + "/64.png").length(); } String border = createStringOfLength(mobTypeLength, '=') + ' ' + createStringOfLength(headImageLength, '='); headTable.append(border).append('\n'); headTable.append(padToLength("Mob", mobTypeLength + 1)).append(padToLength("Image", headImageLength + 1)).append('\n'); headTable.append(border).append('\n'); for(Map.Entry<EntityType, GameProfile> entry : mobSkullMap.entrySet()) { headTable.append(padToLength(entry.getKey().getName(), mobTypeLength + 1)) .append(padToLength(".. image:: https://minotar.net/helm/" + entry.getValue().getName().orElse("") + "/64.png", headImageLength + 1)).append('\n'); } headTable.append(border).append('\n'); return HEAD_DROPS_TABLE_PATTERN.matcher(input).replaceAll(Matcher.quoteReplacement(headTable.toString())); }
Mechanic mechanic = (Mechanic) ((SpongeModuleWrapper) module).getModuleUnchecked(); if(mechanic instanceof DocumentationProvider) DocumentationGenerator.generateDocumentation((DocumentationProvider) mechanic); } catch (ModuleNotInstantiatedException e) { logger.error("Failed to generate docs for module: " + module.getName(), e); DocumentationGenerator.generateDocumentation(config);
String border = createStringOfLength(idLength, '=') + ' ' + createStringOfLength(shorthandLength, '=') + ' ' + createStringOfLength(nameLength, '=') + ' ' + createStringOfLength(descriptionLength, '=') + ' ' + createStringOfLength(familiesLength, '=') + ' ' + createStringOfLength(stLength, '='); icTable.append(padToLength("IC ID", idLength + 1)) .append(padToLength("Shorthand", shorthandLength + 1)) .append(padToLength("Name", nameLength + 1)) .append(padToLength("Description", descriptionLength + 1)) .append(padToLength("Family", familiesLength + 1)) .append(padToLength("Self Triggering", stLength + 1)) .append('\n'); icTable.append(border).append('\n'); for(ICType<? extends IC> icType : ICManager.getICTypes()) { icTable.append(padToLength(":doc:`" + icType.getModel() + '`', idLength + 1)) .append(padToLength(icType.getShorthand(), shorthandLength + 1)) .append(padToLength(icType.getName(), nameLength + 1)) .append(padToLength(icType.getDescription(), descriptionLength + 1)) .append(padToLength(icType.getDefaultPinSet(), familiesLength + 1)) .append(padToLength((SelfTriggeringIC.class.isAssignableFrom(icType.getFactory().createInstance(null).getClass()) ? "Yes" : "No"), stLength + 1)) .append('\n');