InlineCss.php 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @package Grav\Common\Assets
  4. *
  5. * @copyright Copyright (c) 2015 - 2021 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. /**
  11. * Class InlineCss
  12. * @package Grav\Common\Assets
  13. */
  14. class InlineCss extends BaseAsset
  15. {
  16. /**
  17. * InlineCss constructor.
  18. * @param array $elements
  19. * @param string|null $key
  20. */
  21. public function __construct(array $elements = [], $key = null)
  22. {
  23. $base_options = [
  24. 'asset_type' => 'css',
  25. 'position' => 'after'
  26. ];
  27. $merged_attributes = Utils::arrayMergeRecursiveUnique($base_options, $elements);
  28. parent::__construct($merged_attributes, $key);
  29. }
  30. /**
  31. * @return string
  32. */
  33. public function render()
  34. {
  35. return '<style' . $this->renderAttributes(). ">\n" . trim($this->asset) . "\n</style>\n";
  36. }
  37. }