Skip to content

Commit

Permalink
Merge pull request #18 from ARCANEDEV/patch-site_name
Browse files Browse the repository at this point in the history
Adding the setSiteName method
  • Loading branch information
arcanedev-maroc authored Oct 27, 2016
2 parents 8531a90 + b02b1b9 commit cf9c4d8
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ checks:
tools:
external_code_coverage:
timeout: 1200
runs: 12
runs: 8
php_code_sniffer:
enabled: true
config:
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ php:
- 7.0
- 7.1
- nightly
- hhvm

matrix:
allow_failures:
Expand All @@ -29,5 +28,5 @@ script:
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ] && [ "$TRAVIS_PHP_VERSION" != "7.1" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ] && [ "$TRAVIS_PHP_VERSION" != "7.1" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SEO Helper [![Packagist License][badge_license]](LICENSE.md) [![For PHP][badge_php]][link-github-repo]

[![Travis Status][badge_build]][link-travis]
[![HHVM Status][badge_hhvm]][link-hhvm]
[![Coverage Status][badge_coverage]][link-scrutinizer]
[![Scrutinizer Code Quality][badge_quality]][link-scrutinizer]
[![SensioLabs Insight][badge_insight]][link-insight]
Expand Down Expand Up @@ -54,7 +53,6 @@ If you discover any security related issues, please email arcanedev.maroc@gmail.
[badge_php]: https://img.shields.io/badge/PHP-Framework%20agnostic-4F5B93.svg?style=flat-square
[badge_license]: https://img.shields.io/packagist/l/arcanedev/seo-helper.svg?style=flat-square
[badge_build]: https://img.shields.io/travis/ARCANEDEV/SEO-Helper.svg?style=flat-square
[badge_hhvm]: https://img.shields.io/hhvm/arcanedev/seo-helper.svg?style=flat-square
[badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/SEO-Helper.svg?style=flat-square
[badge_quality]: https://img.shields.io/scrutinizer/g/ARCANEDEV/SEO-Helper.svg?style=flat-square
[badge_insight]: https://img.shields.io/sensiolabs/i/73e1a779-7ca7-4a75-b6d3-452d7852187e.svg?style=flat-square
Expand All @@ -69,6 +67,5 @@ If you discover any security related issues, please email arcanedev.maroc@gmail.
[link-contributors]: https://github.com/ARCANEDEV/SEO-Helper/graphs/contributors
[link-packagist]: https://packagist.org/packages/arcanedev/seo-helper
[link-travis]: https://travis-ci.org/ARCANEDEV/SEO-Helper
[link-hhvm]: http://hhvm.h4cc.de/package/arcanedev/seo-helper
[link-scrutinizer]: https://scrutinizer-ci.com/g/ARCANEDEV/SEO-Helper/?branch=master
[link-insight]: https://insight.sensiolabs.com/projects/73e1a779-7ca7-4a75-b6d3-452d7852187e
4 changes: 2 additions & 2 deletions _docs/4-Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1135,11 +1135,10 @@ use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;

class Controller extends BaseController
{
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests, Seoable;
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, Seoable;
}
```

Expand All @@ -1154,6 +1153,7 @@ class PagesController extends Controller
{
$this->seo()
->setTitle('My awesome title')
->setSiteName('My Company Name')
->setDescription('My awesome description')
->setKeywords(['this', 'package', 'is', 'awesome']);

Expand Down
155 changes: 155 additions & 0 deletions _docs/5-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
3. [Helpers](#3-helpers)
* [Meta](#meta)
4. [Managers](#3-manager)
* [SEO Helper](#seo-helper)
* [SEO Meta](#seo-meta)
* [SEO Open Graph](#seo-open-graph)
* [SEO Twitter Card](#seo-twitter-card)
Expand Down Expand Up @@ -728,6 +729,151 @@ interface Meta extends Renderable

## 4. Managers

### SEO Helper

```php
<?php namespace Arcanedev\SeoHelper\Contracts;

/**
* Interface SeoHelper
*
* @package Arcanedev\SeoHelper\Contracts
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
interface SeoHelper extends Renderable
{
/* ------------------------------------------------------------------------------------------------
| Getters & Setters
| ------------------------------------------------------------------------------------------------
*/
/**
* Get SeoMeta instance.
*
* @return \Arcanedev\SeoHelper\Contracts\SeoMeta
*/
public function meta();

/**
* Set SeoMeta instance.
*
* @param \Arcanedev\SeoHelper\Contracts\SeoMeta $seoMeta
*
* @return self
*/
public function setSeoMeta(SeoMeta $seoMeta);

/**
* Get SeoOpenGraph instance.
*
* @return \Arcanedev\SeoHelper\Contracts\SeoOpenGraph
*/
public function openGraph();

/**
* Get SeoOpenGraph instance (alias).
*
* @see openGraph()
*
* @return \Arcanedev\SeoHelper\Contracts\SeoOpenGraph
*/
public function og();

/**
* Get SeoOpenGraph instance.
*
* @param \Arcanedev\SeoHelper\Contracts\SeoOpenGraph $seoOpenGraph
*
* @return self
*/
public function setSeoOpenGraph(SeoOpenGraph $seoOpenGraph);

/**
* Get SeoTwitter instance.
*
* @return \Arcanedev\SeoHelper\Contracts\SeoTwitter
*/
public function twitter();

/**
* Set SeoTwitter instance.
*
* @param \Arcanedev\SeoHelper\Contracts\SeoTwitter $seoTwitter
*
* @return self
*/
public function setSeoTwitter(SeoTwitter $seoTwitter);

/**
* Set title.
*
* @param string $title
* @param string|null $siteName
* @param string|null $separator
*
* @return self
*/
public function setTitle($title, $siteName = null, $separator = null);
/**
* Set description.
*
* @param string $description
*
* @return self
*/
public function setDescription($description);

/**
* Set keywords.
*
* @param array|string $keywords
*
* @return self
*/
public function setKeywords($keywords);

/**
* Set the site name.
*
* @param string $siteName
*
* @return self
*/
public function setSiteName($siteName);

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Enable the OpenGraph.
*
* @return self
*/
public function enableOpenGraph();

/**
* Disable the OpenGraph.
*
* @return self
*/
public function disableOpenGraph();

/**
* Enable the Twitter Card.
*
* @return self
*/
public function enableTwitter();

/**
* Disable the Twitter Card.
*
* @return self
*/
public function disableTwitter();
}
```

### SEO Meta

```php
Expand Down Expand Up @@ -807,6 +953,15 @@ interface SeoMeta extends Renderable
*/
public function setTitle($title, $siteName = null, $separator = null);

/**
* Set the site name.
*
* @param string $siteName
*
* @return self
*/
public function setSiteName($siteName);

/**
* Set the description content.
*
Expand Down
2 changes: 1 addition & 1 deletion config/seo-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| ------------------------------------------------------------------------------------------------
*/
'title' => [
'default' => 'Default title',
'default' => config('app.name', 'Laravel'),
'site-name' => '',
'separator' => '-',
'first' => true,
Expand Down
9 changes: 9 additions & 0 deletions src/Contracts/SeoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ public function setDescription($description);
*/
public function setKeywords($keywords);

/**
* Set the site name.
*
* @param string $siteName
*
* @return self
*/
public function setSiteName($siteName);

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions src/Contracts/SeoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public function webmasters(WebmastersContract $webmasters);
*/
public function setTitle($title, $siteName = null, $separator = null);

/**
* Set the site name.
*
* @param string $siteName
*
* @return self
*/
public function setSiteName($siteName);

/**
* Set the description content.
*
Expand Down
6 changes: 4 additions & 2 deletions src/Entities/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public function getSiteName()
*/
public function setSiteName($siteName)
{
$this->siteName = $siteName;
if ( ! is_null($siteName))
$this->siteName = $siteName;

return $this;
}
Expand All @@ -158,7 +159,8 @@ public function getSeparator()
*/
public function setSeparator($separator)
{
$this->separator = trim($separator);
if ( ! is_null($separator))
$this->separator = trim($separator);

return $this;
}
Expand Down
18 changes: 16 additions & 2 deletions src/SeoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,25 @@ public function setSeoTwitter(SeoTwitterContract $seoTwitter)
*/
public function setTitle($title, $siteName = null, $separator = null)
{
$this->meta()->setTitle($title, $siteName, $separator);
$this->meta()->setTitle($title, null, $separator);
$this->openGraph()->setTitle($title);
$this->openGraph()->setSiteName($siteName);
$this->twitter()->setTitle($title);

return $this->setSiteName($siteName);
}

/**
* Set the site name.
*
* @param string $siteName
*
* @return self
*/
public function setSiteName($siteName)
{
$this->meta()->setSiteName($siteName);
$this->openGraph()->setSiteName($siteName);

return $this;
}

Expand Down
21 changes: 14 additions & 7 deletions src/SeoMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,22 @@ private function analytics(AnalyticsContract $analytics)
*/
public function setTitle($title, $siteName = null, $separator = null)
{
$this->title->set($title);
$this->title->set($title)
->setSeparator($separator);

if ( ! is_null($siteName)) {
$this->title->setSiteName($siteName);
}
return $this->setSiteName($siteName);
}

if ( ! is_null($separator)) {
$this->title->setSeparator($separator);
}
/**
* Set the site name.
*
* @param string $siteName
*
* @return self
*/
public function setSiteName($siteName)
{
$this->title->setSiteName($siteName);

return $this;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/SeoHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ public function it_can_set_and_render_title()
}
}

/** @test */
public function it_can_set_and_render_site_name()
{
$title = 'My Application';
$siteName = 'ARCANEDEV';
$expectations = [
"<title>{$title} - {$siteName}</title>",
'<meta property="og:title" content="' . $title . '">',
'<meta property="og:site_name" content="' . $siteName . '">',
'<meta name="twitter:title" content="' . $title . '">',
];

$this->seoHelper->setSiteName($siteName)
->setTitle($title);

foreach ($expectations as $expected) {
$this->assertContains($expected, $this->seoHelper->render());
$this->assertContains($expected, (string) $this->seoHelper);
}
}

/** @test */
public function it_can_set_and_render_description()
{
Expand Down

0 comments on commit cf9c4d8

Please sign in to comment.