{"id":20838746,"url":"https://github.com/royalicing/glaze","last_synced_at":"2025-05-08T21:29:52.648Z","repository":{"id":62498306,"uuid":"10467549","full_name":"RoyalIcing/glaze","owner":"RoyalIcing","description":"Display HTML elements conveniently with escaping of attributes, text, URLs, email addresses.","archived":false,"fork":false,"pushed_at":"2015-05-05T03:07:22.000Z","size":528,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-08T21:29:47.776Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RoyalIcing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-04T00:02:52.000Z","updated_at":"2023-11-16T16:00:17.000Z","dependencies_parsed_at":"2022-11-02T11:46:54.909Z","dependency_job_id":null,"html_url":"https://github.com/RoyalIcing/glaze","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2Fglaze","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2Fglaze/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2Fglaze/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2Fglaze/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RoyalIcing","download_url":"https://codeload.github.com/RoyalIcing/glaze/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253153097,"owners_count":21862310,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T01:11:26.553Z","updated_at":"2025-05-08T21:29:52.584Z","avatar_url":"https://github.com/RoyalIcing.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Glaze\n=====\n\n### *[French and Viennese pastry chefs originally invented the idea of glazing cakes as a way of preserving them—the glaze sealed off the cakes from the air and prevented them from growing stale.](http://www.epicurious.com/articlesguides/howtocook/primers/cakesfrostings)*\n\n**When displaying anything on the web it must be properly prepared for HTML.** Any text, any URL, and any HTML element’s attributes and contents must be *escaped* before they are displayed.\n\nNormally people use functions like `htmlspecialchars()`, or they even madly paste text into their source code and manually change characters like `\u0026` into `\u0026amp;` and `\u003e` into `\u0026gt;`.\n\nWell there’s these things called computers and you can avoid all that manual work and use much more powerful functions with baking-inspired names.\n\n## Glaze preserves the content you want to display.\n\nJust tell it what you want to display and let it worry about the HTML writing and escaping part. It works with nested HTML elements, attributes, text, URLs, and email addresses. My aim is to make it easier to read and write than the usual PHP ways, whilst also taking care of escaping everything by default.\n\n\n## Whole elements\n\nEscaped elements in one line.\n\n```php\nuse BurntCaramel\\Glaze;\nuse BurntCaramel\\Glaze\\Prepare as GlazePrepare;\nuse BurntCaramel\\Glaze\\Serve as GlazeServe;\n\nGlazeServe::element('h1#siteTitle', 'Title');\n// No need to escape the \u0026\nGlazeServe::element('h2.tagline', 'The home of examples \u0026 more');\nGlazeServe::element('p.any.classes.you.need', 'Blah blah blah blah');\n\n/* Displays: */?\u003e\n\u003ch1 id=\"siteTitle\"\u003e\nTitle\n\u003c/h1\u003e\n\u003ch2 class=\"tagline\"\u003e\nThe home of examples \u0026amp; more\n\u003c/h2\u003e\n\u003cp class=\"any classes you need\"\u003e\nBlah blah blah blah\n\u003c/p\u003e\n```\n\nOr use associated array version, to specify any attributes you like:\n\n```php\nGlazeServe::element(array(\n\t'tagName' =\u003e 'a',\n\t'href' =\u003e 'http://www.infinitylist.com/',\n\t'class' =\u003e 'externalLink'\n), 'Adventure \u0026 creative videos.');\n\n/* Displays: */?\u003e\n\u003ca href=\"http://www.infinitylist.com/\" class=\"externalLink\"\u003eAdventure \u0026amp; creative videos.\u003c/a\u003e\n```\n\nSelf closing elements are also handled.\n\n```php\nGlazeServe::element(array(\n\t'tagName' =\u003e 'meta',\n\t'name' =\u003e 'description',\n\t'content' =\u003e 'Site description as seen by search engines'\n));\n\n/* Displays: */?\u003e\n\u003cmeta name=\"description\" content=\"Site description as seen by search engines\"\u003e\n```\n\n\n## Class attributes\n\nSay you want to display an HTML element’s class names where some are optional.\n\n```php\n$classNames = array('post');\n\nif (isArticle()):\n\t$classNames[] = 'article';\n\t\n\tif (isFeatureArticle()):\n\t\t$classNames[] = 'feature';\n\tendif;\nendif;\n```\n\nYou could juggle `if` statements and PHP open/close tags:\n\n```php\n?\u003e\n\u003cdiv\u003c?php\nif (!empty($classNames)):\n?\u003e class=\"\u003c?= implode(' ', $classNames); ?\u003e\"\u003c?php\nendif;\n?\u003e\u003e\n\n\u003c?php/* Displays: */?\u003e\n\u003cdiv class=\"post article feature\"\u003e\n```\n\nOr use Glaze, passing a string or array:\n\n```php\n// The -Checking method makes sure that if `$classNames` is empty, then nothing will be displayed.\n?\u003e\n\u003cdiv\u003c?php GlazeServe::attributeChecking('class', $classNames); ?\u003e\u003e\n\n\u003c?php/* Displays: */?\u003e\n\u003cdiv class=\"post article feature\"\u003e\n```\n\n\n## Check values for attributes before displaying\n\nUsing JSON from a web API, for example.\n\n```php\n$info = array(\n\t'itemID' =\u003e 'fddf3tq3tt3t3',\n\t'published' =\u003e false,\n\t'genreIdentifier' =\u003e 'thriller',\n\t'salesCount' =\u003e 56,\n\t'selected' =\u003e true,\n\t'authorName' =\u003e 'John Smith',\n\t'itemDescription' =\u003e array(\n\t\t'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',\n\t\t'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',\n\t\t'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'\n\t)\n);\n\n// Build a list of classes using an array, don't fuss with appending to a string\n$classNamesArray = array('item', 'book');\n$classNamesArray[] = !empty($info['published']) ? 'published' : 'upcoming';\n$classNamesArray[] = 'genre-' .$info['genreIdentifier']; // e.g. 'genre-thriller'\n\n$bookItemDiv = GlazePrepare::element('div');\n{\n\t$bookItemDiv-\u003esetAttribute('id', \"bookItem-{$info['itemID']}\");\n\t\n\t// Lets you use an array of strings for class attributes.\n\t$bookItemDiv-\u003eaddClassNames($classNamesArray);\n\t\n\t// Only display the attribute if variable reference $info['salesCount'] is present.\n\t$bookItemDiv-\u003esetAttributeChecking('data-sales-count', $info['salesCount']);\n\t$bookItemDiv-\u003esetAttributeChecking('data-sales-count-nope', $info['salesCount_NOPE']);\n\t\n\t// Only displays the attribute, with the value 'selected', if $info['selected'] is true.\n\t$bookItemDiv-\u003esetAttributeChecking('selected', $info['selected'], 'selected');\n\t$bookItemDiv-\u003esetAttributeChecking('selected-nope', $info['selected_NOPE'], 'selected');\n\t\n\t// Will display:\n\t$bookItemDiv-\u003eappendNewElement('h5.authorName',\n\t\tGlaze\\check($info['authorName'])\n\t);\n\t// Will not display, as key 'authorName_NOPE' does not exist.\n\t$bookItemDiv-\u003eappendNewElement('h5.authorName',\n\t\tGlaze\\check($info['authorName_NOPE'])\n\t);\n\t\n\t// Will display:\n\t$bookItemDiv-\u003eappendNewElement('p.description',\n\t\tGlazePrepare::contentSeparatedBySoftLineBreaks(\n\t\t\tGlaze\\check($info['itemDescription'])\n\t\t)\n\t);\n\t// Will not display, as key 'itemDescription_NOPE' does not exist.\n\t$bookItemDiv-\u003eappendNewElement('p.description',\n\t\tGlazePrepare::contentSeparatedBySoftLineBreaks(\n\t\t\tGlaze\\check($info['itemDescription_NOPE'])\n\t\t)\n\t);\n}\n$bookItemDiv-\u003eserve();\n```\n\nDisplays:\n```html\n\u003cdiv id=\"bookItem-fddf3tq3tt3t3\" class=\"item book upcoming genre-thriller\" data-sales-count=\"56\" selected=\"selected\"\u003e\n\u003ch5 class=\"authorName\"\u003e\nJohn Smith\n\u003c/h5\u003e\n\u003cp class=\"description\"\u003e\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\u003cbr\u003e\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\u003cbr\u003e\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n\u003c/p\u003e\n\u003c/div\u003e\n```\n\n### Using already escaped information\n\n```php\n$escapedText = 'Bangers \u0026amp; Mash';\nGlazeServe::attribute('alt', $escapedText, Glaze\\TYPE_PREGLAZED);\n\n/* Displays: */?\u003e\n alt=\"Bangers \u0026amp; Mash\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyalicing%2Fglaze","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froyalicing%2Fglaze","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyalicing%2Fglaze/lists"}