Browse Source

v0.0.2 pre-alpha

tags/0.1.0
angel koilov 11 years ago
parent
commit
3fe445c5a7
17 changed files with 189 additions and 21 deletions
  1. +2
    -1
      .gitignore
  2. +3
    -0
      README.md
  3. +0
    -0
      composer.json
  4. +16
    -1
      phpunit.xml
  5. +5
    -5
      src/Potaka/BbCode/BbCode.php
  6. +0
    -0
      src/Potaka/BbCode/Exception.php
  7. +14
    -14
      src/Potaka/BbCode/Tag/Bold.php
  8. +0
    -0
      src/Potaka/BbCode/Tag/Exception.php
  9. +28
    -0
      src/Potaka/BbCode/Tag/Italic.php
  10. +32
    -0
      src/Potaka/BbCode/Tag/SimpleTag.php
  11. +2
    -0
      src/Potaka/BbCode/Tag/Tag.php
  12. +33
    -0
      src/Potaka/BbCode/Tag/Underline.php
  13. +5
    -0
      tests/Potaka/BbCode/BbCodeTest.php
  14. +16
    -0
      tests/Potaka/BbCode/Tag/BoldTest.php
  15. +17
    -0
      tests/Potaka/BbCode/Tag/ItalicTest.php
  16. +16
    -0
      tests/Potaka/BbCode/Tag/UnderlineTest.php
  17. +0
    -0
      tests/bootstrap.php

+ 2
- 1
.gitignore View File

@@ -1,4 +1,5 @@
/nbproject/private/
/vendor/
/composer.lock
/nbproject/
/nbproject/
/tmp/

+ 3
- 0
README.md View File

@@ -1,4 +1,7 @@
bbcode
======
v0.0.2 pre-alpha
added tags for Bold, Italic & Underline

v0.0.1 pre-alpha
not ready to use. Active development!

+ 0
- 0
composer.json View File


+ 16
- 1
phpunit.xml View File

@@ -2,7 +2,7 @@
backupStaticAttributes="false"
bootstrap="./tests/bootstrap.php"
cacheTokens="false"
colors="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
@@ -21,7 +21,22 @@
<testsuites>
<testsuite name="My Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="tmp/report" charset="UTF-8" highlight="false" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
<!-- <log type="testdox-html" target="tmp/testdox.html"/>-->
</logging>
<filter>
<blacklist>
<directory>vendor</directory>
</blacklist>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>


+ 5
- 5
src/Potaka/BbCode/BbCode.php View File

@@ -9,14 +9,14 @@ namespace Potaka\BbCode;
*/
class BbCode {

protected $parsers = array();
protected $tags = array();

public function addTag(bbCode\Tag\Tag $tag) {
$this->parsers[] = $tag;
public function addTag(Tag\Tag $tag) {
$this->tags[] = $tag;
}

public function getParsers() {
return $this->parsers;
public function getTags() {
return $this->tags;
}

}

+ 0
- 0
src/Potaka/BbCode/Exception.php View File


+ 14
- 14
src/Potaka/BbCode/Tag/Bold.php View File

@@ -7,22 +7,22 @@ namespace Potaka\BbCode\Tag;
*
* @author po_taka <angel.koilov@gmail.com>
*/
class Bold implements Tag {
class Bold extends SimpleTag {

/**
*
* @param string $string
* @return string
* @throws Potaka\bbCode\Tag\Exception
*/
public function format($string) {
$string = (string) $string;
$formattedString = preg_replace('#\[b\](.*?)\[/b\]#', '<strong>$1</strong>', $string);
if ($formattedString === null) {
throw new Exception("{$string} regexp failed");
}
public function getCloseHtmlTag() {
return '</b>';
}

public function getClosetag() {
return '[/b]';
}

public function getOpenHtmlTag() {
return '<b>';
}

return $formattedString;
public function getOpentag() {
return '[b]';
}

}

+ 0
- 0
src/Potaka/BbCode/Tag/Exception.php View File


+ 28
- 0
src/Potaka/BbCode/Tag/Italic.php View File

@@ -0,0 +1,28 @@
<?php

namespace Potaka\BbCode\Tag;

/**
* Description of Italic
*
* @author po_taka <angel.koilov@gmail.com>
*/
class Italic extends SimpleTag {

public function getCloseHtmlTag() {
return '</i>';
}

public function getClosetag() {
return '[/i]';
}

public function getOpenHtmlTag() {
return '<i>';
}

public function getOpentag() {
return '[i]';
}

}

+ 32
- 0
src/Potaka/BbCode/Tag/SimpleTag.php View File

@@ -0,0 +1,32 @@
<?php

namespace Potaka\BbCode\Tag;

/**
* Description of SimpleTag
*
* @author po_taka <angel.koilov@gmail.com
*/
abstract class SimpleTag implements Tag {

public function format($string) {

$string = (string) $string;
$openTag = preg_quote($this->getOpenTag(), '#');
$closeTag = preg_quote($this->getClosetag(), '#');
$formattedString = preg_replace("#{$openTag}(.*?){$closeTag}#", "{$this->getOpenHtmlTag()}$1{$this->getCloseHtmlTag()}", $string);
if ($formattedString === null) {
throw new Exception("{$string} regexp failed");
}

return $formattedString;
}

abstract function getOpenTag();

abstract function getClosetag();

abstract function getOpenHtmlTag();

abstract function getCloseHtmlTag();
}

+ 2
- 0
src/Potaka/BbCode/Tag/Tag.php View File

@@ -9,4 +9,6 @@ namespace Potaka\BbCode\Tag;
interface Tag {

public function format($string);

public function getOpentag();
}

+ 33
- 0
src/Potaka/BbCode/Tag/Underline.php View File

@@ -0,0 +1,33 @@
<?php

namespace Potaka\BbCode\Tag;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of Underline
*
* @author potaka
*/
class Underline extends SimpleTag {

public function getOpentag() {
return '[u]';
}

public function getClosetag() {
return '[/u]';
}

public function getOpenHtmlTag() {
return '<u>';
}

public function getCloseHtmlTag() {
return '</u>';
}

}

+ 5
- 0
tests/Potaka/BbCode/BbCodeTest.php View File

@@ -9,6 +9,11 @@ class BbCodeTest extends PHPUnit_Framework_TestCase {

public function testAddingTag() {
$bbCode = new Potaka\BbCode\BbCode();
$tagBb = new Potaka\BbCode\Tag\Bold();

$bbCode->addTag($tagBb);

$this->assertEquals(array($tagBb), $bbCode->getTags());
}

}

+ 16
- 0
tests/Potaka/BbCode/Tag/BoldTest.php View File

@@ -0,0 +1,16 @@
<?php

/**
* Description of BoldTest
*
* @author po_taka <angel.koilov@gmail.com
*/
class BoldTest extends PHPUnit_Framework_TestCase{
public function testToHtml() {
$tag = new Potaka\BbCode\Tag\Bold();
$bbCode = '[b]bold[/b]';
$html = $tag->format($bbCode);
$this->assertEquals($html, '<b>bold</b>');
}
}

+ 17
- 0
tests/Potaka/BbCode/Tag/ItalicTest.php View File

@@ -0,0 +1,17 @@
<?php

/**
* Description of BoldTest
*
* @author po_taka <angel.koilov@gmail.com
*/
class ItalicTest extends PHPUnit_Framework_TestCase {

public function testToHtml() {
$tag = new Potaka\BbCode\Tag\Italic();
$bbCode = '[i]i[/i]';
$html = $tag->format($bbCode);
$this->assertEquals($html, '<i>i</i>');
}

}

+ 16
- 0
tests/Potaka/BbCode/Tag/UnderlineTest.php View File

@@ -0,0 +1,16 @@
<?php

/**
* Description of BoldTest
*
* @author po_taka <angel.koilov@gmail.com
*/
class UnerlineTest extends PHPUnit_Framework_TestCase{
public function testToHtml() {
$tag = new Potaka\BbCode\Tag\Underline();
$bbCode = '[u]u[/u]';
$html = $tag->format($bbCode);
$this->assertEquals($html, '<u>u</u>');
}
}

+ 0
- 0
tests/bootstrap.php View File


Loading…
Cancel
Save