Skip to content

Commit

Permalink
Complete ServerSideRendering implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Jan 3, 2020
1 parent 06a1ba5 commit 3b31720
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 29 deletions.
10 changes: 10 additions & 0 deletions includes/validation/class-amp-css-length.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,14 @@ public function is_auto() {
public function get_unit() {
return $this->unit;
}


/**
* The numeral of the attribute.
*
* @return float
*/
public function get_numeral() {
return $this->numeral;
}
}
57 changes: 57 additions & 0 deletions optimizer/Error/CannotPerformServerSideRendering.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Amp\Optimizer\Error;

use Amp\Optimizer\Error;
use DOMElement;

final class CannotPerformServerSideRendering implements Error
{

use ErrorProperties;

/**
* Code to use for the error.
*
* @var string
*/
const CODE = 'CANNOT_PERFORM_SSR';

const INVALID_INPUT_WIDTH = 'Cannot perform serverside rendering, invalid input width: ';
const INVALID_INPUT_HEIGHT = 'Cannot perform serverside rendering, invalid input height: ';
const UNSUPPORTED_LAYOUT = 'Cannot perform serverside rendering, unsupported layout: ';

/**
* Instantiate a CannotPerformServerSideRendering object for an element with an invalid input width.
*
* @param DOMElement $element Element that has an invalid input width.
* @return self
*/
public static function fromInvalidInputWidth(DOMElement $element)
{
return new self(self::INVALID_INPUT_WIDTH . new ElementDump($element));
}

/**
* Instantiate a CannotPerformServerSideRendering object for an element with an invalid input height.
*
* @param DOMElement $element Element that has an invalid input height.
* @return self
*/
public static function fromInvalidInputHeight(DOMElement $element)
{
return new self(self::INVALID_INPUT_HEIGHT . new ElementDump($element));
}

/**
* Instantiate a CannotPerformServerSideRendering object for an element with an invalid input height.
*
* @param DOMElement $element Element that has an invalid input height.
* @param string $layout Resulting layout.
* @return self
*/
public static function fromUnsupportedLayout(DOMElement $element, $layout)
{
return new self(self::UNSUPPORTED_LAYOUT . new ElementDump($element) . " => {$layout}");
}
}
23 changes: 6 additions & 17 deletions optimizer/Error/CannotRemoveBoilerplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,13 @@ final class CannotRemoveBoilerplate implements Error
const AMP_AUDIO_STRING = 'Cannot remove boilerplate because the document contains an extension that needs to know the dimensions of the browser: ';
const UNSUPPORTED_LAYOUT_STRING = 'Cannot remove boilerplate because of an unsupported layout: ';

/**
* Instantiate a CannotRemoveBoilerplate object.
*
* @param string $message Message for the error.
*/
public function __construct($message)
{
$this->code = self::CODE;
$this->message = $message;
}

/**
* Instantiate a CannotRemoveBoilerplate object for attributes that require the boilerplate to be around.
*
* @param DOMElement $element Element that contains the attributes that need the boilerplate.
* @return self
*/
public static function from_attributes_requiring_boilerplate(DOMElement $element)
public static function fromAttributesRequiringBoilerplate(DOMElement $element)
{
return new self(self::ATTRIBUTES_STRING . new ElementDump($element));
}
Expand All @@ -50,7 +39,7 @@ public static function from_attributes_requiring_boilerplate(DOMElement $element
* @param DOMElement $element amp-experiment element.
* @return self
*/
public static function from_amp_experiment(DOMElement $element)
public static function fromAmpExperiment(DOMElement $element)
{
return new self(self::RENDER_DELAYING_SCRIPT_STRING . $element->tagName);
}
Expand All @@ -61,7 +50,7 @@ public static function from_amp_experiment(DOMElement $element)
* @param DOMElement $element amp-audio element.
* @return self
*/
public static function from_amp_audio(DOMElement $element)
public static function fromAmpAudio(DOMElement $element)
{
return new self(self::AMP_AUDIO_STRING . new ElementDump($element));
}
Expand All @@ -72,18 +61,18 @@ public static function from_amp_audio(DOMElement $element)
* @param DOMElement $element Element with an unsupported layout.
* @return self
*/
public static function from_unsupported_layout(DOMElement $element)
public static function fromUnsupportedLayout(DOMElement $element)
{
return new self(self::UNSUPPORTED_LAYOUT_STRING . new ElementDump($element));
}

/**
* Instantiate a CannotRemoveBoilerplate object for an element with an unsupported layout.
* Instantiate a CannotRemoveBoilerplate object for render-delaying script element.
*
* @param DOMElement $element Element with an unsupported layout.
* @return self
*/
public static function from_render_delaying_script(DOMElement $element)
public static function fromRenderDelayingScript(DOMElement $element)
{
$elementName = $element->hasAttribute('custom-element') ? $element->getAttribute('custom-element') : '<unknown>';

Expand Down
11 changes: 11 additions & 0 deletions optimizer/Error/ErrorProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
trait ErrorProperties
{

/**
* Instantiate an Error object.
*
* @param string $message Message for the error.
*/
public function __construct($message)
{
$this->code = self::CODE;
$this->message = $message;
}

/**
* Code of the error.
*
Expand Down
37 changes: 37 additions & 0 deletions optimizer/Layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Amp\Optimizer;

interface Layout
{

const NODISPLAY = 'nodisplay';
const FIXED = 'fixed';
const RESPONSIVE = 'responsive';
const FIXED_HEIGHT = 'fixed-height';
const FILL = 'fill';
const CONTAINER = 'container';
const FLEX_ITEM = 'flex-item';
const FLUID = 'fluid';
const INTRINSIC = 'intrinsic';

const VALID_LAYOUTS = [
self::NODISPLAY,
self::FIXED,
self::RESPONSIVE,
self::FIXED_HEIGHT,
self::FILL,
self::CONTAINER,
self::FLEX_ITEM,
self::FLUID,
self::INTRINSIC,
];

const SIZE_DEFINED_LAYOUTS = [
self::FIXED,
self::FIXED_HEIGHT,
self::RESPONSIVE,
self::FILL,
self::FLEX_ITEM,
];
}
Loading

0 comments on commit 3b31720

Please sign in to comment.