Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #210 from facebook/feature/caption-small-font
Browse files Browse the repository at this point in the history
Added small font size to Caption element
  • Loading branch information
everton-rosario authored Apr 27, 2017
2 parents 6037341 + 3aa8987 commit c1fec30
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Facebook/InstantArticles/Elements/Caption.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
class Caption extends FormattedText
{
// Font size
const SIZE_SMALL = 'op-small';
const SIZE_MEDIUM = 'op-medium';
const SIZE_LARGE = 'op-large';
const SIZE_XLARGE = 'op-extra-large';
Expand Down Expand Up @@ -72,7 +73,7 @@ class Caption extends FormattedText
private $credit;

/**
* @var string text Size. Values: "op-medium"|"op-large"|"op-extra-large"
* @var string text Size. Values: "op-small"|"op-medium"|"op-large"|"op-extra-large"
*/
private $fontSize;

Expand Down Expand Up @@ -161,6 +162,7 @@ public function withCredit($credit)
/**
* The Fontsize that will be used.
*
* @see Caption::SIZE_SMALL
* @see Caption::SIZE_MEDIUM
* @see Caption::SIZE_LARGE
* @see Caption::SIZE_XLARGE
Expand All @@ -176,7 +178,8 @@ public function withFontsize($font_size)
[
Caption::SIZE_XLARGE,
Caption::SIZE_LARGE,
Caption::SIZE_MEDIUM
Caption::SIZE_MEDIUM,
Caption::SIZE_SMALL
]
);
$this->fontSize = $font_size;
Expand Down Expand Up @@ -301,6 +304,7 @@ public function getCredit()
/**
* @return string the Font size.
*
* @see Caption::SIZE_SMALL
* @see Caption::SIZE_MEDIUM
* @see Caption::SIZE_LARGE
* @see Caption::SIZE_XLARGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static function createFrom($configuration)
Caption::ALIGN_CENTER,
Caption::ALIGN_RIGHT,

Caption::SIZE_SMALL,
Caption::SIZE_MEDIUM,
Caption::SIZE_LARGE,
Caption::SIZE_XLARGE,
Expand Down Expand Up @@ -90,6 +91,9 @@ public function apply($transformer, $container_of_caption, $node)
$caption->withTextAlignment(Caption::ALIGN_RIGHT);
}

if ($this->getProperty(Caption::SIZE_SMALL, $node)) {
$caption->withFontsize(Caption::SIZE_SMALL);
}
if ($this->getProperty(Caption::SIZE_MEDIUM, $node)) {
$caption->withFontsize(Caption::SIZE_MEDIUM);
}
Expand Down
1 change: 1 addition & 0 deletions src/Facebook/InstantArticles/Transformer/Rules/H1Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static function createFrom($configuration)
Caption::ALIGN_CENTER,
Caption::ALIGN_RIGHT,

Caption::SIZE_SMALL,
Caption::SIZE_MEDIUM,
Caption::SIZE_LARGE,
Caption::SIZE_XLARGE
Expand Down
18 changes: 17 additions & 1 deletion tests/Facebook/InstantArticles/Elements/CaptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testRenderWithPosition()
$this->assertEquals($expected, $rendered);
}

public function testRenderWithFontSize()
public function testRenderWithLargeFontSize()
{
$caption =
Caption::create()
Expand All @@ -101,6 +101,22 @@ public function testRenderWithFontSize()
$this->assertEquals($expected, $rendered);
}

public function testRenderWithSmallFontSize()
{
$caption =
Caption::create()
->appendText('Small Caption Title')
->withFontsize(Caption::SIZE_SMALL);

$expected =
'<figcaption class="op-small">'.
'Small Caption Title'.
'</figcaption>';

$rendered = $caption->render();
$this->assertEquals($expected, $rendered);
}

public function testRenderWithTextAlignment()
{
$caption =
Expand Down

0 comments on commit c1fec30

Please sign in to comment.