Skip to content

Commit

Permalink
Merge pull request #1365 from dreamsxin/tag-title-separator
Browse files Browse the repository at this point in the history
[NFR]Add Tag::setTitleSeparator
  • Loading branch information
Phalcon committed Oct 11, 2013
2 parents 536744d + 00a00f9 commit 5eb8985
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 5 deletions.
52 changes: 47 additions & 5 deletions ext/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ PHALCON_INIT_CLASS(Phalcon_Tag){

zend_declare_property_null(phalcon_tag_ce, SL("_displayValues"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_tag_ce, SL("_documentTitle"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_tag_ce, SL("_documentTitleSeparator"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_long(phalcon_tag_ce, SL("_documentType"), 11, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_tag_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_tag_ce, SL("_urlService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
Expand Down Expand Up @@ -1364,20 +1365,40 @@ PHP_METHOD(Phalcon_Tag, setTitle){

}

/**
* Set the title separator of view content
*
*<code>
* Phalcon\Tag::setTitleSeparator('-');
*</code>
*
* @param string $titleSeparator
*/
PHP_METHOD(Phalcon_Tag, setTitleSeparator){

zval *title_separator;

phalcon_fetch_params(0, 1, 0, &title_separator);

phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator"), title_separator TSRMLS_CC);

}

/**
* Appends a text to current document title
*
* @param string $title
*/
PHP_METHOD(Phalcon_Tag, appendTitle){

zval *title, *t0, *r0;
zval *title, *document_title, *document_title_separator, *r0;

phalcon_fetch_params(0, 1, 0, &title);

t0 = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitle") TSRMLS_CC);
document_title = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitle") TSRMLS_CC);
document_title_separator = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator") TSRMLS_CC);
ALLOC_INIT_ZVAL(r0);
concat_function(r0, t0, title TSRMLS_CC);
PHALCON_CONCAT_VVV(r0, document_title, document_title_separator, title);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentTitle"), r0 TSRMLS_CC);
zval_ptr_dtor(&r0);
}
Expand All @@ -1389,14 +1410,15 @@ PHP_METHOD(Phalcon_Tag, appendTitle){
*/
PHP_METHOD(Phalcon_Tag, prependTitle){

zval *title, *document_title, *r0;
zval *title, *document_title, *document_title_separator, *r0;

phalcon_fetch_params(0, 1, 0, &title);

document_title = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitle") TSRMLS_CC);
document_title_separator = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator") TSRMLS_CC);

ALLOC_INIT_ZVAL(r0);
concat_function(r0, title, document_title TSRMLS_CC);
PHALCON_CONCAT_VVV(r0, title, document_title_separator, document_title);
phalcon_update_static_property_ce(phalcon_tag_ce, SL("_documentTitle"), r0 TSRMLS_CC);
zval_ptr_dtor(&r0);
}
Expand Down Expand Up @@ -1429,6 +1451,26 @@ PHP_METHOD(Phalcon_Tag, getTitle){
}
}

/**
* Gets the current document title separator
*
* <code>
* echo Phalcon\Tag::getTitleSeparator();
* </code>
*
* <code>
* {{ get_title_separator() }}
* </code>
*
* @return string
*/
PHP_METHOD(Phalcon_Tag, getTitleSeparator){

zval *document_title_separator;
document_title_separator = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_documentTitleSeparator") TSRMLS_CC);
RETURN_ZVAL(document_title_separator, 1, 0);
}

/**
* Builds a LINK[rel="stylesheet"] tag
*
Expand Down
8 changes: 8 additions & 0 deletions ext/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ PHP_METHOD(Phalcon_Tag, textArea);
PHP_METHOD(Phalcon_Tag, form);
PHP_METHOD(Phalcon_Tag, endForm);
PHP_METHOD(Phalcon_Tag, setTitle);
PHP_METHOD(Phalcon_Tag, setTitleSeparator);
PHP_METHOD(Phalcon_Tag, appendTitle);
PHP_METHOD(Phalcon_Tag, prependTitle);
PHP_METHOD(Phalcon_Tag, getTitleSeparator);
PHP_METHOD(Phalcon_Tag, getTitle);
PHP_METHOD(Phalcon_Tag, stylesheetLink);
PHP_METHOD(Phalcon_Tag, javascriptInclude);
Expand Down Expand Up @@ -137,6 +139,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_settitle, 0, 0, 1)
ZEND_ARG_INFO(0, title)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_settitleseparator, 0, 0, 1)
ZEND_ARG_INFO(0, separator)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_tag_appendtitle, 0, 0, 1)
ZEND_ARG_INFO(0, title)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -230,9 +236,11 @@ PHALCON_INIT_FUNCS(phalcon_tag_method_entry){
PHP_ME(Phalcon_Tag, form, arginfo_phalcon_tag_form, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, endForm, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setTitle, arginfo_phalcon_tag_settitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, setTitleSeparator, arginfo_phalcon_tag_settitleseparator, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, appendTitle, arginfo_phalcon_tag_appendtitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, prependTitle, arginfo_phalcon_tag_prependtitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getTitle, arginfo_phalcon_tag_gettitle, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, getTitleSeparator, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, stylesheetLink, arginfo_phalcon_tag_stylesheetlink, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, javascriptInclude, arginfo_phalcon_tag_javascriptinclude, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Phalcon_Tag, image, arginfo_phalcon_tag_image, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
Expand Down
47 changes: 47 additions & 0 deletions unit-tests/TagTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
+------------------------------------------------------------------------+
*/

use Phalcon\Tag as Tag;

class TagTest extends PHPUnit_Framework_TestCase
{

public function testSetTitleSeparator()
{

Tag::setTitle('Title');
Tag::appendTitle('Class');

$this->assertEquals(Tag::getTitle(), '<title>TitleClass</title>'.PHP_EOL);

Tag::setTitle('Title');
Tag::setTitleSeparator('|');
Tag::appendTitle('Class');

$this->assertEquals(Tag::getTitle(), '<title>Title|Class</title>'.PHP_EOL);
$this->assertEquals(Tag::getTitleSeparator(), '|');

Tag::setTitle('Title');
Tag::setTitleSeparator('|');
Tag::prependTitle('Class');

$this->assertEquals(Tag::getTitle(), '<title>Class|Title</title>'.PHP_EOL);
}
}

0 comments on commit 5eb8985

Please sign in to comment.