Git Product home page Git Product logo

hexty's Introduction

Hexty

A minimalistic tool for text replacement in HTML.

Install

npm i bolighed-hexty -D

Example

There is a working example in the example folder.

Let's create the config file. It will contains the config object and the files list, both constants must be exported, like in the example.

For example in this case the index.html page will use the index.texts.js file.

textly.config.js

const path = require('path');

const files = [
    {
        path: path.resolve(__dirname, "./index.html"),
        text_path: path.resolve(__dirname, "./index.texts.js")
    }
];

module.exports = files;

or text_path could be also an object

const path = require('path');
const { texts, texts2 } = require("./index.texts.js");

const files = [
    {
        path: path.resolve(__dirname, "./index.html"),
        text_path: texts
    }
];

module.exports = files;

Let's create the index.texts.js file, which is a map of placeholder and text files

index.texts.js

const texts = {
    "message-text": "Hello World in a text",
    "message-html": "<h2>Something else in good old html</h2>",
    "another-section-html": "<h2>another section</h2>",
    "message-md": "### hello this is markdown ++"
}

module.exports = texts;

The html tags with attribute data-textly having values matching the keys in index.texts.js. It is important if your text contains HTML your key must finish with -html and if contains Markdown it must finish -md. Placeholder ending with -x will not be checked.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <h1>Texty example</h1>
    <p data-hexty="message-text">Hello World in a text</p>
    <p data-hexty="message-text">Hello World in a text</p>
    <li data-hexty="message-html" class="plum"><h2>Something else in good old html</h2></li>
    <li data-hexty="message-html" class="plum"><h2>Something else in good old html</h2></li>
    <li data-hexty="message-md" class="plum"><h3>hello this is markdown ++</h3></li>
    <li data-hexty="message-md" class="plum"><h3>hello this is markdown ++</h3></li>
</body>

</html>

At last, let's create the index.js file that glues everything together.

index.js

const config = require('./hexty.config');
require('bolighed-hexty')(config);

If there are some errors they will be displayed like so

Hexty error

otherwise

Hexty success

CLI usage

You can use the tool from the command line like so:

hexty --config hexty.config.js

hexty's People

Contributors

pmcalabrese avatar

Watchers

James Cloos avatar  avatar ab avatar Pyconsult.dk avatar Simon Lyngby Kokkendorff 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.