private function register_view_macro() { $watcher = $this; HTML::macro('watcherScript', function ($timeout = 3000, array $additionalFolders = array(), array $otherConfigs = array()) use($watcher) { $otherConfigsString = ''; foreach ($otherConfigs as $key => $value) { if (is_array($value)) { $value = serialize($value); } $otherConfigsString .= ' data-' . $key . '=\'' . $value . '\''; } if ($watcher->watcher_enabled) { return '<script src="/watchpoller.js" id="pollscript" data-additionalfolders=\'' . serialize($additionalFolders) . '\' data-timeout="' . $timeout . '" ' . $otherConfigsString . '></script>'; } }); }
<?php use Illuminate\Support\Facades\HTML; HTML::macro('meta', function ($attr = [], $content = null) { /** * [$HtmlBuilder description] * @var Illuminate */ $HtmlBuilder = new Illuminate\Html\HtmlBuilder(); if (!is_array($attr) && !is_null($content)) { return '<meta name="' . $attr . '" content="' . $content . '" />' . PHP_EOL; } else { return '<meta' . $HtmlBuilder->attributes($attr) . ' />' . PHP_EOL; } }); HTML::macro('fbog', function ($property, $content) { /** * Facebook Open Graph Meta Tags */ return '<meta property="og:' . $property . '" content="' . $content . '" />' . PHP_EOL; }); HTML::macro('meta_twitter', function ($name, $content) { /** * Twitter Meta Tags */ return '<meta name="twitter:' . $property . '" content="' . $content . '" />' . PHP_EOL; });
<?php /** Setting up for Namespacing **/ use Illuminate\Support\Facades\HTML; // Inspired by: http://forums.laravel.io/viewtopic.php?id=827 HTML::macro('nav_item', function ($url, $text, $a_attr = array(), $active_class = 'active', $li_attrs = array()) { $href = HTML::link($url, $text, $a_attr); $response = ''; if (Request::is($url) || Request::is($url . '/*')) { if (isset($li_attrs['class'])) { $li_attrs['class'] .= ' ' . $active_class; } else { $li_attrs['class'] = $active_class; } } return '<li ' . HTML::attributes($li_attrs) . '>' . $href . '</li>'; });
<?php use Illuminate\Support\Facades\HTML; HTML::macro('moment', function ($timestamp = null, $duration = null, $durationFormat = 'seconds', $fromNow = false) { if (!is_null($timestamp) && is_null($duration) && !$fromNow) { return sprintf('{{ moment(\'%s\').format(\'lll\') }}', $timestamp); } elseif (!is_null($timestamp) && is_null($duration) && $fromNow) { return sprintf('{{ moment(\'%s\').fromNow() }}', $timestamp); } elseif (is_null($timestamp) && !is_null($duration) && !$fromNow) { return sprintf('{{ momentDuration(%u, \'%s\') }}', (int) $duration, $durationFormat); } }); HTML::macro('faicon', function ($icon, $openSpan = false) { if ($openSpan) { return sprintf('<i class="fa %s"></i><span>', $icon); } return sprintf('<i class="fa %s"></i>', $icon); }); HTML::macro('ionicon', function ($icon, $openSpan = false) { if ($openSpan) { return sprintf('<i class="ion %s"></i><span>', $icon); } return sprintf('<i class="ion %s"></i>', $icon); });