PHP Class Apple_Exporter\Components\Component

It provides several helper methods, such as get/set_setting and register_style.
Since: 0.2.0
Show file Open project: alleyinteractive/apple-news Class Usage Examples

Public Properties

Property Type Description
$anchor_position integer Anchorable components are anchored to the previous element that appears in the position specified. If the previous element is an advertisement, attaches to the next instead of the previous element.
$needs_layout_if_anchored boolean Right now, the only component that sets this to false is the body, as it doesn't need a special layout for anchoring, it just flows around anchored components.

Protected Properties

Property Type Description
$can_be_anchor_target boolean Whether this component can be an anchor target.
$json array JSON for this component.
$layouts Component_Layouts Layouts for this component.
$settings Settings Settings for this component.
$styles Component_Text_Styles Styles for this component.
$text string Text for this component.
$workspace Workspace Workspace for this component.

Public Methods

Method Description
__construct ( string $text, Workspace $workspace, Settings $settings, Component_Text_Styles $styles, Component_Layouts $layouts, Markdown $markdown = null ) Constructor.
anchor ( ) Sets the anchor layout for this component
can_be_anchor_target ( ) : boolean Check if it's can_be_anchor_target and it hasn't been anchored already.
get_anchor_position ( ) : integer Get the anchor position.
get_component_name ( ) : string Gets the name of this component from the class name.
get_json ( string $name ) : mixed Get a JSON value
is_anchor_target ( ) : boolean All components that are anchor target have an UID. Return whether this component is an anchor target.
node_matches ( DomNode $node ) : mixed Given a DomNode, if it matches the component, return the relevant node to work on. Otherwise, return null.
set_anchor_position ( integer $position ) Set the anchor position.
set_json ( string $name, mixed $value ) Set a JSON value.
to_array ( ) : array Transforms HTML into an array that describes the component using the build function.
uid ( ) : string Get the current UID.

Protected Methods

Method Description
build ( string $text ) This function is in charge of transforming HTML into a Article Format valid array.
bundle_source ( string $filename, string $source ) Calls the current workspace bundle_source method to allow for different implementations of the bundling technique.
clean_html ( string $html ) : string Use PHP's HTML parser to generate valid HTML out of potentially broken input.
find_text_alignment ( ) : string Some components follow this rule: 1. If the body is centered, text here should be centered too 2. Otherwise, align left
get_setting ( string $name ) : mixed Gets an exporter setting.
maybe_bundle_source ( string $source, string $filename = null ) : string Maybe bundles the source based on current settings.
node_has_class ( DomNode $node, string $classname ) : boolean Check if a node has a class.
register_full_width_layout ( string $name, array $spec ) Register a new layout which will be displayed as full-width, so no need to specify columnStart and columnSpan in the layout specs. This is useful because when the body is centered, the full-width layout spans the same columns as the body.
register_layout ( string $name, array $spec ) Using the layouts service, register a new layout.
register_style ( string $name, array $spec ) Using the style service, register a new style.
remote_file_exists ( DomNode $node ) : boolean Check if the remote file exists for this node.
set_setting ( string $name, mixed $value ) : boolean Sets an exporter setting.

Method Details

__construct() public method

Constructor.
public __construct ( string $text, Workspace $workspace, Settings $settings, Component_Text_Styles $styles, Component_Layouts $layouts, Markdown $markdown = null )
$text string
$workspace Workspace
$settings Settings
$styles Component_Text_Styles
$layouts Component_Layouts
$markdown Markdown

anchor() public method

Sets the anchor layout for this component
Since: 0.6.0
public anchor ( )

build() abstract protected method

This function is in charge of transforming HTML into a Article Format valid array.
abstract protected build ( string $text )
$text string

bundle_source() protected method

Calls the current workspace bundle_source method to allow for different implementations of the bundling technique.
protected bundle_source ( string $filename, string $source )
$filename string The name of the file to be created
$source string The path or URL of the resource which is going to be bundled

can_be_anchor_target() public method

Check if it's can_be_anchor_target and it hasn't been anchored already.
public can_be_anchor_target ( ) : boolean
return boolean

clean_html() protected static method

Use PHP's HTML parser to generate valid HTML out of potentially broken input.
protected static clean_html ( string $html ) : string
$html string
return string

find_text_alignment() protected method

This method returns either 'center' or 'left', as needed.
Since: 0.8.0
protected find_text_alignment ( ) : string
return string

get_anchor_position() public method

Get the anchor position.
public get_anchor_position ( ) : integer
return integer

get_component_name() public method

Gets the name of this component from the class name.
public get_component_name ( ) : string
return string

get_json() public method

Get a JSON value
public get_json ( string $name ) : mixed
$name string
return mixed

get_setting() protected method

Gets an exporter setting.
Since: 0.4.0
protected get_setting ( string $name ) : mixed
$name string
return mixed

is_anchor_target() public method

All components that are anchor target have an UID. Return whether this component is an anchor target.
Since: 0.6.0
public is_anchor_target ( ) : boolean
return boolean

maybe_bundle_source() protected method

Returns the URL to use based on current setings.
protected maybe_bundle_source ( string $source, string $filename = null ) : string
$source string The path or URL of the resource which is going to be bundled
$filename string The name of the file to be created
return string The URL to use for this asset in the JSON

node_has_class() protected static method

Check if a node has a class.
protected static node_has_class ( DomNode $node, string $classname ) : boolean
$node DomNode
$classname string
return boolean

node_matches() public static method

Given a DomNode, if it matches the component, return the relevant node to work on. Otherwise, return null.
public static node_matches ( DomNode $node ) : mixed
$node DomNode
return mixed

register_full_width_layout() protected method

Register a new layout which will be displayed as full-width, so no need to specify columnStart and columnSpan in the layout specs. This is useful because when the body is centered, the full-width layout spans the same columns as the body.
protected register_full_width_layout ( string $name, array $spec )
$name string
$spec array

register_layout() protected method

Using the layouts service, register a new layout.
Since: 0.4.0
protected register_layout ( string $name, array $spec )
$name string
$spec array

register_style() protected method

Using the style service, register a new style.
Since: 0.4.0
protected register_style ( string $name, array $spec )
$name string
$spec array

remote_file_exists() protected static method

Check if the remote file exists for this node.
protected static remote_file_exists ( DomNode $node ) : boolean
$node DomNode
return boolean

set_anchor_position() public method

Set the anchor position.
public set_anchor_position ( integer $position )
$position integer

set_json() public method

Set a JSON value.
public set_json ( string $name, mixed $value )
$name string
$value mixed

set_setting() protected method

Sets an exporter setting.
Since: 0.4.0
protected set_setting ( string $name, mixed $value ) : boolean
$name string
$value mixed
return boolean

to_array() public method

Transforms HTML into an array that describes the component using the build function.
public to_array ( ) : array
return array

uid() public method

Get the current UID.
public uid ( ) : string
return string

Property Details

$anchor_position public property

Anchorable components are anchored to the previous element that appears in the position specified. If the previous element is an advertisement, attaches to the next instead of the previous element.
Since: 0.6.0
public int $anchor_position
return integer

$can_be_anchor_target protected property

Whether this component can be an anchor target.
Since: 0.6.0
protected bool $can_be_anchor_target
return boolean

$json protected property

JSON for this component.
Since: 0.2.0
protected array $json
return array

$layouts protected property

Layouts for this component.
Since: 0.4.0
protected Component_Layouts $layouts
return Component_Layouts

$needs_layout_if_anchored public property

Right now, the only component that sets this to false is the body, as it doesn't need a special layout for anchoring, it just flows around anchored components.
Since: 0.6.0
public bool $needs_layout_if_anchored
return boolean

$settings protected property

Settings for this component.
Since: 0.4.0
protected Settings $settings
return Settings

$styles protected property

Styles for this component.
Since: 0.4.0
protected Component_Text_Styles $styles
return Component_Text_Styles

$text protected property

Text for this component.
Since: 0.2.0
protected string $text
return string

$workspace protected property

Workspace for this component.
Since: 0.2.0
protected Workspace $workspace
return Workspace