Home

Awesome

html-strings-affixer

CLI tool that finds texts in HTML and replaces it with suffixed and prefixed string. Originally developed to replace strings with localization function in blade file:
<p>Some nice string</p> -> <p>{{ __('Some nice string') }}</p>
But can be used in any file which contains html (".jsx", ".vue", ".twig") with same purpose. Of course, prefix and suffix are customizable

JavaScript version is already available here (hsa-js)

Quick start

Check out a little article on Medium about the tool.

Navigation

Installation

Composer

It is already available in composer now, you can require it:
composer require maestroerror/html-strings-affixer --dev.
After installation it is accessible by:

Linux/Unix

Step 1: Download
Download binary file with wget https://github.com/MaestroError/html-strings-affixer/releases/latest/download/hsa

Step 2: Make it executable
Run in directory with downloaded file chmod a+x ./hsa (Use sudo if permission is required)

Step 3: Execution
You can move it in directory where you need to use and just execute with ./hsa [command] [-args] or Make it available viw command line.

Step 4: Command line (optional)
Find your bin folder (/usr/bin, /usr/sbin or ~/bin), or make it with cd ~/ && mkdir bin and Symlink (ln -s $~/path/to/directory/hsa ~/bin/hsa) or move/copy binary file in bin directory. After it you can use app in cli with "hsa" command. Try: hsa check

Windows

Download binary file or Zip. Get "hsa.exe" file in needed directory and run with ".\hsa.exe"

MacOS

Download an archive, Unzip it, get "hsamac" or "hsamacm1" file in needed directory, give to it executable permissions and run with ./hsamac or ./hsamacm1

From source

If you have golang installed, you can clone this repo and run go install or go build for binary file

Features

Config file

You need to create "affixer.json" file in directory, from where you will run html-strings-affixer. You can find an example in bin folder of this repository (bin/affixer-example.json).
Alternativly you can run app without config file in your working directory and it will offer you to create one from example

JSON object and descriptions

    // Scanning
    *(string) "folder" - just folder to scan
    *(array) "file_types" - Parses file only with given extensions
    (array) "ignore_names" - ignores files and folders with given names

    // Parse
    (array) "ignore" - ignores strings which contains given character (Group of characters not allowed, only single characters)
    (array) "warnings" - Warns about strings which contains given characters (not replaces)
    (array) "methods" - Uses only given parse methods. Available: text, placeholder, alt, title, hashtag

    // Replace
    *(string) "prefix" - Prefix to set
    *(string) "suffix" - Suffix to set
    (bool) "force" - If true, git status check is ignored

    // Report
    (bool) "detailed" - if true, detailed report will be displayed
    (bool) "warn_as_Table" - if true, warnings will be displayed as table
    (bool) "report" - if true, warnings will be saved as JSON file

    // Log
    (string) "log_folder" - folder to store logs

Commands

Available commands:

Some configs you can pass as arguments, use hsa [command] --help to read more about command.

Replace command options

Check command options

Usage

It is recommended to use tool with config file, where you can specify all needed info and use all features, that tool is providing. If you already have configured file you can easily run:

~$ ./vendor/bin/hsa check
# AND/OR
~$ ./vendor/bin/hsa replace

In this usage guide, we will cover some CLI use cases, but you can use them alongside with config file, because options provided from command line has higher priority. They re-write all passed options while specific run, but all other configs provided by JSON file stays same.

Just Affix it!

For example, you can: Easily affix all html strings with @lang directive in templates folder. To do so, run:

./vendor/bin/hsa replace -folder="resources/views" -allowed=".blade.php" -prefix="@lang('" -suffix="')"

in another words:

hsa replace -folder="[Path/To/Your/Folder]" -allowed="[Allowed, File, Extensions]" -prefix="[StringToPrepend]" -suffix="[StringToAppend]"

Note: Keep in mind that "@" character is not a part of default ignore or warning chars, you need to specify it via config file

Force replace

If you use git and have uncommitted changes, it is recommended to first commit or stash them and after run replace command, so hsa will ask you about it on every run. If you already tested the tool and you know what are you doing, you can use -force parameter to skip that prompt.

./vendor/bin/hsa replace -folder="views" -force

Note: For now, HSA has not UNDO command, so be careful while running replace

Work with one file

Sometimes you will need to perform some commands only on single file, to reduce memory usage, get smaller printed information and/or avoid unwanted changes. For that purpose you can use option -file:

./vendor/bin/hsa replace -file="resources/view/contact.blade.php"

Too many warning

Sometimes with large project there are too many warning to check them via terminal. For such cases -report option could be helpful, it will generate JSON file with all warnings in it:

./vendor/bin/hsa check -report

Note that -report option is availabe for both, replace and check commands. Also, it can be set via JSON file as report: true.

Executables

There are several executables for different platforms, choose your one and use it. They are working the exactly same way, you are changing just the executable file name in command.

Note: I am planning to create single command, which will work for any platform, but for now, it is as it is :smile:

Support

Support Our Work? 🌟 You can help us keep the code flowing by making a small donation. Every bit of support goes a long way in maintaining and improving our open-source contributions. Click the button below to contribute. Thank you for your generosity!

<img src="https://github.com/MaestroError/resources/blob/maestro/buymeamilk/green-2.png" width="300px">

Or use QR code:

<img src="https://github.com/MaestroError/resources/blob/maestro/buymeamilk/qr-code.png" width="135px">



To Do




Updated 21/09/2023:


Upcoming

Resources