Skip to content

Commit

Permalink
added template for foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Aug 26, 2015
1 parent 80d59ba commit ca527fe
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml export-ignore
/.scrutinizer.yml export-ignore
/.styleci.yml export-ignore
/tests export-ignore
142 changes: 0 additions & 142 deletions coverage.clover

This file was deleted.

8 changes: 3 additions & 5 deletions example.php → examples/default.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php
session_start();

require_once 'vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';

flash()->error(['Invalid email!', 'Invalid username!'])
->warning('Warning message.')
->info('Info message.')
->success('Success message!');

$messages = flash();
?>

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<title>Test Bootstrap 3 default template.</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
Expand All @@ -24,7 +22,7 @@
<br/>

<div class="container" style="width: 600px;">
<?= $messages ?>
<?= flash() ?>
</div>

<!-- Latest compiled and minified JavaScript -->
Expand Down
36 changes: 36 additions & 0 deletions examples/foundation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
session_start();

require_once __DIR__ . '/../vendor/autoload.php';

flash()->error(['Invalid email!', 'Invalid username!'])
->warning('Warning message.')
->info('Info message.')
->success('Success message!');

flash()->setTemplate(new \Tamtamchik\SimpleFlash\Templates\FoundationTemplate());

?>

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Foundation 3 default template.</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/css/foundation.min.css">
</head>
<body>

<br/>

<div class="row" style="width: 600px;">
<?= flash() ?>
</div>

<!-- Latest compiled and minified JavaScript -->
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/js/foundation.min.js"></script>

</body>
</html>
79 changes: 79 additions & 0 deletions src/BaseTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Tamtamchik\SimpleFlash;

abstract class BaseTemplate implements TemplateInterface
{
protected $prefix = '<p>';
protected $postfix = '</p>';
protected $wrapper = '<div class="alert alert-%s" role="alert">%s</div>';

/**
* @param $message - message text
*
* @return string
*/
public function wrapMessage($message)
{
return $this->getPrefix() . $message . $this->getPostfix();
}

/**
* @param $messages - message text
* @param $type - message type: success, info, warning, danger
*
* @return string
*/
public function wrapMessages($messages, $type)
{
return sprintf($this->getWrapper(), ($type == 'error') ? 'danger' : $type, $messages);
}

/**
* @return string
*/
public function getPrefix()
{
return $this->prefix;
}

/**
* @param string $prefix
*/
public function setPrefix($prefix)
{
$this->prefix = $prefix;
}

/**
* @return string
*/
public function getPostfix()
{
return $this->postfix;
}

/**
* @param string $postfix
*/
public function setPostfix($postfix)
{
$this->postfix = $postfix;
}

/**
* @param string $wrapper
*/
public function setWrapper($wrapper)
{
$this->wrapper = $wrapper;
}

/**
* @return string
*/
public function getWrapper()
{
return $this->wrapper;
}
}
81 changes: 6 additions & 75 deletions src/Templates/DefaultTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,15 @@

namespace Tamtamchik\SimpleFlash\Templates;

use Tamtamchik\SimpleFlash\TemplateInterface;
use Tamtamchik\SimpleFlash\BaseTemplate;

/**
* Class DefaultTemplate.
* Class FoundationTemplate.
* Use default Bootstrap 3 markdown for flash messages.
*/
class DefaultTemplate implements TemplateInterface
class DefaultTemplate extends BaseTemplate
{
private $prefix = '<p>';
private $postfix = '</p>';
private $wrapper = '<div class="alert alert-%s" role="alert">%s</div>';

/**
* @param $message - message text
*
* @return string
*/
public function wrapMessage($message)
{
return $this->getPrefix() . $message . $this->getPostfix();
}

/**
* @param $messages - message text
* @param $type - message type: success, info, warning, danger
*
* @return string
*/
public function wrapMessages($messages, $type)
{
return sprintf($this->getWrapper(), ($type == 'error') ? 'danger' : $type, $messages);
}

/**
* @return string
*/
public function getPrefix()
{
return $this->prefix;
}

/**
* @param string $prefix
*/
public function setPrefix($prefix)
{
$this->prefix = $prefix;
}

/**
* @return string
*/
public function getPostfix()
{
return $this->postfix;
}

/**
* @param string $postfix
*/
public function setPostfix($postfix)
{
$this->postfix = $postfix;
}

/**
* @param string $wrapper
*/
public function setWrapper($wrapper)
{
$this->wrapper = $wrapper;
}

/**
* @return string
*/
public function getWrapper()
{
return $this->wrapper;
}
// Fully use base template designed for Bootstrap 3 markdown.
// In order to create your template extend \Tamtamchik\SimpleFlash\BaseTemplate and
// override protected $prefix, $postfix and $wrapper variables.
}
Loading

0 comments on commit ca527fe

Please sign in to comment.