Css.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * @package Grav\Common\Assets
  4. *
  5. * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\Assets;
  9. use Grav\Common\Utils;
  10. class Css extends BaseAsset
  11. {
  12. public function __construct(array $elements = [], $key = null)
  13. {
  14. $base_options = [
  15. 'asset_type' => 'css',
  16. 'attributes' => [
  17. 'type' => 'text/css',
  18. 'rel' => 'stylesheet'
  19. ]
  20. ];
  21. $merged_attributes = Utils::arrayMergeRecursiveUnique($base_options, $elements);
  22. parent::__construct($merged_attributes, $key);
  23. }
  24. public function render()
  25. {
  26. if (isset($this->attributes['loading']) && $this->attributes['loading'] === 'inline') {
  27. $buffer = $this->gatherLinks( [$this], self::CSS_ASSET);
  28. return "<style>\n" . trim($buffer) . "\n</style>\n";
  29. }
  30. return '<link href="' . trim($this->asset) . $this->renderQueryString() . '"' . $this->renderAttributes() . ">\n";
  31. }
  32. }