dev-lucid / html
A library for building HTML.
Installs: 38
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Language:JavaScript
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: ^5.0
- tedivm/jshrink: ^1.1
Suggests
- twbs/bootstrap: dev-v4-dev
This package is not auto-updated.
Last update: 2025-02-05 19:22:35 UTC
README
A library for building HTML.
Basic Usage
# in Javascript! var factory = new lucid.html.factory(); var myAnchor = factory.build('anchor', 'http://google.com', 'google'); console.log(myAnchor.render());
# in PHP! # (this assumes you've configured an autoloader to find this class) $factory = new \Lucid\Html\Factory(); $myAnchor = $factory->build('anchor', 'http://google.com', 'google'); echo($myAnchor->render());
Both of these code samples will log/echo this:
<a href="http://google.com">google</a>
Building and Testing
Building all tags and running tests
There's one main script that does pretty much everything you'll need to do to change the source, package it up, and test it:
bin/make
This does the following:
- Builds all tags (See sections below)
- Packages up all Javascript files (See sections below)
- Loads the final javascript files in node just to do one final syntax check
- Runs all unit tests
This library uses phpunit to run unit tests, but additionally runs javascript tests through phpunit by calling node.js through shell_exec. So in order to run unit tests, you must install node. You will also have to use composer before running tests as the tests use composer's autoloader.
Building Tags
Every tag in the library is generated using a json file that describes the tag. To generate the javascript tag for the base anchor tag,
bin/makeTagJavascript.php ./src/Base/meta/anchor.json
# This will generate ./src/Base/tags/anchor.js
To generate the PHP tag for the base anchor tag,
bin/makeTagPHP.php ./src/Base/meta/anchor.json
# This will generate ./src/Base/tags/anchor.php
To build all tags in a meta folder:
bin/makeAllTags ./src/Base/meta
# this builds everything!
Packing up Javascript files for distribution
bin/makeJsDist.php
This will generate four files:
- ./dist/lucid.html.buildBaseTagsOnly.js
- ./dist/lucid.html.buildBaseTagsOnly.min.js (this is the same as the previous file, but minified)
- ./dist/lucid.html.buildBootstrap.js
- ./dist/lucid.html.buildBootstrap.min.js (this is the same as the previous file, but minified)
In a project, only one of those 4 files needs to be included.