Coder Social home page Coder Social logo

laravel-assets's Introduction

Laravel Assets

Build Status StyleCI

Установка

Для установки пакета вы можете выполнить консольную комманду

composer require kodicms/laravel-assets

Или добавить пакет в composer.json

{
  "require": {
    ...
    "kodicms/laravel-assets": "~2.0"
    ...
  }
}

Добавить в загрузку сервис провайдер

'providers' => [
  ...
  KodiCMS\Assets\AssetsServiceProvider::class,
  ...
],
'aliases' => [
  ...
  'Assets' => KodiCMS\Assets\Facades\Assets::class,
  'PackageManager' => KodiCMS\Assets\Facades\PackageManager::class,
  'Meta' => KodiCMS\Assets\Facades\Meta::class,
  ...
]

Использование

Формирование пакетов

PackageManager::add('jquery')
	->js(null, 'https://code.jquery.com/jquery-2.1.4.min.js');

PackageManager::add('jquery-ui')
	->js(null, 'https://code.jquery.com/ui/1.11.4/jquery-ui.min.js', 'jquery')
	->css(null, 'https://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css');

PackageManager::add('custom')
	->js(null, '...')
	->js('custom.second.js', '...', 'custom')
	->css(null, '...')
	->css('custom.second.css', '...');

Добабление данных в вывод

Формировать мета данные для вывода можно не только в шаблоне, но и непосредственно коде приложения

use KodiCMS\Assets\Contracts\SocialMediaTagsInterface;

class Article extends Model implements SocialMediaTagsInterface
{
	...
}

use Meta;

class ArticleController extends Controller
{
	public function show($articleId)
    {
        $article = Article::find($articleId);

        Meta::loadPackage('jquery')
        	->addSocialTags($article);

		Meta::addCss('style', url('css/style.css'));
		Meta::addJs('scripts', url('js/scripts.js'), 'jquery');

		Meta::addJsElixir();
		...
    }
}

Вывод

Для вывода css и js в шаблон сайта используется класс Meta.

<!DOCTYPE html>
<html lang="en">
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
	{!!
		Meta::setFavicon('favicon.ico')
			// Подключение файлов из пакетов
			->loadPackage('jquery', 'jquery-ui', 'custom')

			// Meta title
			->setTitle('Hello world')
		    ->setMetaDescription('Meta description')
		    ->setMetaKeywords('Meta keywords')
		    ->setMetaRobots('Meta robots')

		    // Alternative meta title
			->setMetaData(MetaDataInterface $data)

			// Social tags
		    ->addSocialTags(SocialMediaTagsInterface $socialTags)

		    // Custom tag
		    ->addMeta([
				'property' => 'og:title',
				'content'  => 'Title',
				'name' => 'og:title'
			])

			->render()
	!!}
</head>

Вывод списка пакетов

php artisan assets:packages

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.