Coder Social home page Coder Social logo

vedph / cadmus-previews Goto Github PK

View Code? Open in Web Editor NEW
0.0 7.0 0.0 39 KB

Preview templates for Cadmus, used as helpers for designing HTML output in the editor, based on XSLT.

License: GNU General Public License v3.0

XSLT 61.11% HTML 38.21% Batchfile 0.68%

cadmus-previews's Introduction

Cadmus Preview Templates

This project is just a collection of templates used to build preview configurations for the Cadmus editor. As such, it can be used as a sample to help you build your own preview. All what you need is knowing XSLT and a bit of JSON; your favorite XML editor; and an XSLT processor.

You can open the project with Oxygen, or just use the files in each folder. Each folder is related to a specific part or fragment, and is named accordingly from its ID.

For more documentation on preview, see Cadmus migration documentation.

Quick Start

To create a preview:

(1) choose the part or fragment you want to build the preview for, and create a folder named after its ID.

(2) in the folder, create a sample.xml file to contain sample data for the chosen part or fragment (file names are just conventions, you can use whatever name you prefer). This can be copied from the JSON content of each part or layer part in the Cadmus MongoDB database, or just created by hand. In both cases, you should ensure that you adjust JSON for preview, manually performing the operations which will then be automatic in the system:

  • for fragment parts, pick a single fragment from the fragments array, and wrap it into { "root": {...} }.
  • for any other parts, just wrap into { "root": {...} } the JSON content.

(3) in the folder, create a go.xslt XSLT file to generate your preview transforming sample.xml. The XSLT skeleton typically is as follows. Note that this template includes html and body, and CSS inside html's head, just to let you see the output of your script in a complete HTML document.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Cadmus preview - ID -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="1.0">
    <xsl:output media-type="text/html" method="html" omit-xml-declaration="yes" encoding="UTF-8"/>
    <!-- TODO optional templates for root's descendants here... -->
    <xsl:template match="root">
        <html>
            <head>
                <style type="text/css">
                    .pv-flex-row {
                        display: flex;
                        gap: 8px;
                        align-items: center;
                        flex-wrap: wrap;
                    }
                    .pv-flex-row * {
                        flex: 0 0 auto;
                    }
                    /* TODO other styles here... prefix them according to ID */
                </style>
            </head>
            <body>
            <!-- TODO your templates / <xsl:apply-templates/> here... -->
            </body>
        </html>
    </xsl:template>
    <!-- fallback -->
    <xsl:template match="*"/>

</xsl:stylesheet>

(4) if using Oxygen, update the transform scenarios so that you apply go.xslt to sample.xml.

Note that these templates are built for no dependencies, so you just need a text editor to work. This implies that you will eventually have to take into account filters, but you won't see their effects. For instance, your XSLT template might output a mock <_md> element just to let a Markdown filter replace it with the conversion of its content into HTML; yet, if using only simple XSLT transforms you will just see the mock element.

(5) once you have completed the script, you should remove head, move the styles into your Cadmus app CSS, and unwrap the contents of html and body. In the end, the preview script should just generate an HTML fragment, usually rooted under some element like div. To add your preview:

  • in the app frontend, just add your styles to preview-styles.css.
  • in the API backend, add your preview configuration to preview-profile.json. Here you should have all the filters used by your renderers, and a JSON renderer for each preview type. For instance:
{
  "RendererFilters": [
    TODO: add your filters here, like these ones...
    {
      "Keys": "markdown",
      "Id": "it.vedph.renderer-filter.markdown",
      "Options": {
        "MarkdownOpen": "<_md>",
        "MarkdownClose": "</_md>",
        "Format": "html"
      }
    },
    {
      "Keys": "token-extractor",
      "Id": "it.vedph.renderer-filter.mongo-token-extractor",
      "Options": {
        "LocationPattern": "<location>([^<]+)</location>",
        "TextTemplate": "<span class=\"apparatus-lemma\">{text}</span>",
        "TextCutting": true,
        "Mode": 3,
        "Limit": 80,
        "MinusLimit": 5,
        "PlusLimit": 5
      }
    }
  ],
  "JsonRenderers": [
    {
      "Keys": "TODO: your part ID: partID or partID|fragmentID",
      "Id": "it.vedph.json-renderer.xslt",
      "Options": {
        "FilterKeys": [
          TODO: add your filter keys here...
          "token-extractor"
        ],
        "Xslt": "...TODO: paste your minimized script here..."
      }
    }
  ],
  "TextPartFlatteners": [
    {
      "Keys": "it.vedph.token-text",
      "Id": "it.vedph.text-flattener.token"
    }
  ]
}

To minify your XSLT you can use any tool like this web minifier. Please ensure to properly escape the XSLT code when placing it in the JSON configuration: any " should be escaped as \".

cadmus-previews's People

Contributors

myrmex avatar

Watchers

 avatar Federico Boschetti avatar Paolo Monella avatar angelodel80 avatar Holger Essler avatar Linda avatar Tiziana Mancinelli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.