Componette

Componette

Machy8

Machy8 / Macdom v3.0.0

🍩 The best, highly customizable HTML preprocessor with many amazing features https://machy8.github.io/Macdom/.

download-cloud-line composer require machy8/macdom

Macdom

Build Status Coverage Status Packagist License Join the chat at https://gitter.im/Machy8/Macdom

  • For more information see WIKI (always up to date to the newest stable version)
  • Try it on CODEPEN (JavaScript version is always behind the php version so it may contain bugs and errors that have already been fixed in the PHP version)

Sample

Macdom

!5
html
    head
        utf-8
        viewport
        favicon includes/favicon.ico
        title Macdom example
    body
        h1 #title .titles .main-title Hello world
        nav
            @ a $http://www.[@].com $blank Link on -
            [google] .first-link Google
            [yahoo] Yahoo
            [github] Github	
        div #wrapper Some text <b>here</b>.
        https://www.code.jquery.com/jquery-1.12.0.min.js async

Result

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta content="width=device-width" name="viewport">
		<link rel="shortcut icon" href="includes/favicon.ico">
		<title>Macdom example</title>
	</head>
	<body>
		<h1 id="title" class="titles main-title">Hello world</h1>
		<nav>
			<a target="blank" href="http://www.google.com" class="first-link">Link on - Google</a>
			<a target="blank" href="http://www.yahoo.com">Link on - Yahoo</a>
			<a target="blank" href="http://www.github.com">Link on - Github</a>
		</nav>
		<div id="wrapper">
			Some text <b>here</b>.
		</div>
		<script async="" type="text/javascript" src="https://www.code.jquery.com/jquery-1.12.0.min.js"></script>
	</body>
</html>

Requirements

  • PHP 7.0+
  • If you use Nette Framework - v2.3+

Installation

1 - Download the Macdom using composer:

 composer require machy8/macdom

2 - Usage:

Typical:

$macdom = new Macdom\Engine;
$compiled = $macdom->compile($content);

Nette framework:

use Macdom\Bridges\Latte\FileLoader;
use Macdom\Engine;

/**
 * @var Engine
 */
private $macdom;

/**
 * @var FileLoader
 */
private $fileLoader;


public function __construct(Engine $macdom, FileLoader $fileLoader) {
	$this->macdom = $macdom;
	$this->fileLoader = $fileLoader;
}


protected function createTemplate()
{
	$template = parent::createTemplate();
	$this->fileLoader->setMacdom($this->macdom);
	$template->getLatte()->setLoader($this->fileLoader);
	return $template;
}

And add a config neon file with the following content (or try Composer synchronizer. It will do it for you automatically).

extensions:
    macdom: Macdom\Bridges\Nette\MacdomExtension
  
macdom:
    debugger: TRUE
  • v3.0.0 3.0.0

    • Completely redesigned version
    • See docs folder for changes
    • Requires PHP >= 7.0
    • If you use Nette framework >= 2.3
    • This version is incompatible with previous versions
  • v2.2.0 2.2.0

    • Fixes
      • macro selector is now replaced correctly
      • empty string in replicator is ignored
      • macros are detected properly in the replicator
    • New
      • string can be cleaned from both sides or only from left
      • is possible to add blank line on the end of the file
    • Other
      • Improved coding style
      • Renamed variables Elements, Macros, Setup, Replicator - now they start by lowercase letter
  • v2.1.0 2.1.0

    New Features

    • Script or css tag can by added through shortcut => script.js and style.css
    • New core macros - index-follow, no-index-follow
    • Added SKIP and SKIP-CONTENT selectors for skipping content
    • Is possible to add quick attributes via addQkAttributes()
    • Improved code connection in the replicator - by adding ‘|’ you can preserve the trailing space

    Other

    • Setup - code indentation options are now ‘spaces’, ‘tabs’, ‘combined’ instead of 1-3
    • Removed n:href support
    • Improved viewport Macro
    • Improved output code style

    Requirements

    • PHP >= 5.4.0
    • If you use Nette >= 2.3.0
  • v2.0.0 2.0.0

    • Changed directory structure
    • Modified setup
    • Added new options for setup
    • Added new tests
    • Various bugs fixed
    • Added selector for data-attribute
    • Better support for clean php
    • Better support for no-compile areas
    • Improved work with text
  • v1.3.0 1.3.0

    • Now is possible to use Macdom without Nette Framework
    • Added method for code compression
    • Various bugs fixed
    • Visual tests replaced by Nette tester tests
    • Improved coding style
    • Improved code annotations
  • v1.2 1.2

    • Added compileContent method.
    • Now is possible to compile selected content or a whole template even if you are not using Nette Framework.
  • v1.1 1.1

    Added

    ChangeLog

    • Macdom was separated on single components.
    • All classes has its own file.
    • Elements, elements settings and boolean attributes are now separated.
    • Is possible to choose which indent method you want to use.
    • Added methods for customization before compilation (is possible to add elements, macros, select indent method...).
    • Short selectors for classes are now synchronized with html class attributes.
    • Short id selector is now synchronized with html id selector.
    • Improved text connectors - text is now connected with a space according to conditions.

    Fixed issues

    • Detection of no compile area - now is detected even the close tag of no compile area
    • Adding close tags before html comments, text and content from no compile area.

    For more information visi WIKI

Componette Componette felix@nette.org