PageRenderTime 25ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/sass/20130424-ead0ac1897/renderers/SassCompressedRenderer.php

https://github.com/vivid-planet/library
PHP | 113 lines | 40 code | 9 blank | 64 comment | 2 complexity | ebbb33ce5f0c205fe96f80d452cdc75e MD5 | raw file
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * SassCompressedRenderer class file.
  5. * @author Chris Yates <chris.l.yates@gmail.com>
  6. * @copyright Copyright (c) 2010 PBM Web Development
  7. * @license http://phamlp.googlecode.com/files/license.txt
  8. * @package PHamlP
  9. * @subpackage Sass.renderers
  10. */
  11. /**
  12. * SassCompressedRenderer class.
  13. * Compressed style takes up the minimum amount of space possible, having no
  14. * whitespace except that necessary to separate selectors and a newline at the
  15. * end of the file. It's not meant to be human-readable
  16. * @package PHamlP
  17. * @subpackage Sass.renderers
  18. */
  19. class SassCompressedRenderer extends SassRenderer {
  20. /**
  21. * Renders the brace between the selectors and the properties
  22. * @return string the brace between the selectors and the properties
  23. */
  24. protected function between() {
  25. return '{';
  26. }
  27. /**
  28. * Renders the brace at the end of the rule
  29. * @return string the brace between the rule and its properties
  30. */
  31. protected function end() {
  32. return '}';
  33. }
  34. /**
  35. * Returns the indent string for the node
  36. * @param SassNode the node to return the indent string for
  37. * @return string the indent string for this SassNode
  38. */
  39. protected function getIndent($node) {
  40. return '';
  41. }
  42. /**
  43. * Renders a comment.
  44. * @param SassNode the node being rendered
  45. * @return string the rendered comment
  46. */
  47. public function renderComment($node) {
  48. return '';
  49. }
  50. /**
  51. * Renders a directive.
  52. * @param SassNode the node being rendered
  53. * @param array properties of the directive
  54. * @return string the rendered directive
  55. */
  56. public function renderDirective($node, $properties) {
  57. return $node->directive . $this->between() . $this->renderProperties($node, $properties) . $this->end();
  58. }
  59. /**
  60. * Renders properties.
  61. * @param SassNode the node being rendered
  62. * @param array properties to render
  63. * @return string the rendered properties
  64. */
  65. public function renderProperties($node, $properties) {
  66. return join('', $properties);
  67. }
  68. /**
  69. * Renders a property.
  70. * @param SassNode the node being rendered
  71. * @return string the rendered property
  72. */
  73. public function renderProperty($node) {
  74. $node->important = $node->important ? '!important' : '';
  75. return "{$node->name}:{$node->value}{$node->important};";
  76. }
  77. /**
  78. * Renders a rule.
  79. * @param SassNode the node being rendered
  80. * @param array rule properties
  81. * @param string rendered rules
  82. * @return string the rendered directive
  83. */
  84. public function renderRule($node, $properties, $rules) {
  85. $selectors = $this->renderSelectors($node);
  86. if ($selectors) {
  87. return (!empty($properties) ? $selectors . $this->between() . $this->renderProperties($node, $properties) . $this->end() : '') . $rules;
  88. }
  89. }
  90. /**
  91. * Renders the rule's selectors
  92. * @param SassNode the node being rendered
  93. * @return string the rendered selectors
  94. */
  95. protected function renderSelectors($node) {
  96. $selectors = array();
  97. foreach ($node->selectors as $selector) {
  98. if (!$node->isPlaceholder($selector)) {
  99. $selectors[] = $selector;
  100. }
  101. }
  102. return join(',', $selectors);
  103. }
  104. }