In-Portal Developers Guide

This is a wiki-based Developers Guide for In-Portal Open Source CMS. The purpose of this guide is to provide advanced users, web developers and programmers with documentation on how to expand, customize and improve the functionality and the code the In-Portal software. Please consider contributing to our documentation writing effort.

K4:Реорганизация тэгов

From In-Portal Developers Guide

Jump to: navigation, search
m (1 версия)
Current revision (13:03, 16 March 2009) (view source)
 
Line 1: Line 1:
{{toc | category = Библиотека тэгов | sortkey = 001.001}}
{{toc | category = Библиотека тэгов | sortkey = 001.001}}
-
На данным момент интерпретатор шаблонов (template parser) поддерживает 2 набора тэгов:
 
-
* совместимые с XML правилами
 
-
* не совместимые с XML правилами
 
-
Отныне настоятельно рекомендуется использовать XML совместимые тэги, т.к. в последствии просто будет выключена поддержка всех остальных тэгов. Ниже приведена таблица совместимости между тэгами старого образца и нового:
+
Currently, the template parser supports to sets of tags:
 +
* compatible with XML rules
 +
* incompatible with XML rules
 +
 
 +
It's strongly recommended to use XML compatible tags because support for non-compatible tags will eventually be turned off. The below table shows compatibility between older style tags and new style:
{| class="prettytable"
{| class="prettytable"
-
! тэги старого образца || тэги нового образца
+
! old style || new style
|-
|-
|
|
Line 45: Line 46:
|}
|}
-
Для того, чтобы заменить подавляющее большинство тэгов нужно в корне проекта выполнить команду:
+
In order to replace the majority of the old tags, the following command must be executed in the root directory of the project:
<source lang="bash">
<source lang="bash">
find ./ -type f -name "*.tpl" | xargs \
find ./ -type f -name "*.tpl" | xargs \
Line 56: Line 57:
     -e "s/\(<inp2:[^>]*\)\$prefix_\([^\"]*\)/\1{\$prefix}_\2/g"
     -e "s/\(<inp2:[^>]*\)\$prefix_\([^\"]*\)/\1{\$prefix}_\2/g"
</source>
</source>
-
После это может потребоваться руками заменить тэги вида:
+
Next, it may be necessary to manually change tags of the following style:
-
* <code><inp2:m_if ... /></code> на <code><inp2:m_if></code>
+
* <code><inp2:m_if ... /></code> to <code><inp2:m_if></code>
-
* <code><inp2:m_DefineElement /></code> на <code><inp2:m_DefineElement></code>
+
* <code><inp2:m_DefineElement /></code> to <code><inp2:m_DefineElement></code>
-
Для атрибутов тэгов требуется выполнять следующие преобразования:
+
For attribute tags, the following changes would need to be made:
{| class="prettytable"
{| class="prettytable"
-
! атрибуты старого образца || атрибуты нового образца
+
! old style attributes || new style attributes
|-
|-
| block || render_as
| block || render_as
Line 72: Line 73:
|}
|}
-
XML совместимые тэги так-же улучшают читабельность шаблона, например:
+
XML compatible tags also increase the readability of templates, for example:
<source lang="xml">
<source lang="xml">
<inp2:p_ListProducts render_as="product_elem" row_start_render_as="row_start_elem" />
<inp2:p_ListProducts render_as="product_elem" row_start_render_as="row_start_elem" />
</source>
</source>
-
Эта конструкция проста и понятна, т.к. сразу ястно что здесь происходит. А из названия тэга DefineElement понятно, что это только декларация и результат не будет виден здесь, а будет использоваться в другом месте.
+
This structure is simple and intuitive because one understands immediately what's going on. From the tag name DefineElement it's inferred that it's only a declaration and the result/output won't be seen here, and instead will be used somewhere else.
As for IF we should use:
As for IF we should use:
Пожалуйста начинайте пересматривать код в ваших шаблонах. Лучше не заменять название атрибутов совсем, а пользоваться следующей конструкцией:
Пожалуйста начинайте пересматривать код в ваших шаблонах. Лучше не заменять название атрибутов совсем, а пользоваться следующей конструкцией:
 +
Please start reviewing the code in your templates. It's not always best to replace attribute names, using the following structure instead:
<source lang="php">
<source lang="php">
$param_value = $this->SelectParam($params, 'new_attribute_name,old_attribute_name,other_attribute_name');
$param_value = $this->SelectParam($params, 'new_attribute_name,old_attribute_name,other_attribute_name');
</source>
</source>
-
которая вернёт атрибут, только если он передан.
+
which will return an attribute, only if one's passed.
-
По любым вопросам касательно этого документа обращайтесь к [[User:Kostja|Косте]]
+
Kostja can help with any questions about this article.

Current revision

Библиотека тэгов Библиотека тэгов
Статьи в этой категории
  • Реорганизация тэгов

Currently, the template parser supports to sets of tags:

  • compatible with XML rules
  • incompatible with XML rules

It's strongly recommended to use XML compatible tags because support for non-compatible tags will eventually be turned off. The below table shows compatibility between older style tags and new style:

old style new style
<inp2:m_block name="some_elem"/>
	element content
<inp2:m_blockend/>
<inp2:m_DefineElement name="some_elem">
	element content
</inp2:m_DefineElement>
<inp2:m_if prefix="prefix" function="Tag" param1="1" param2="2"/>
	true case
<inp2:m_else/>
	false case
<inp2:m_endif/>
<inp2:m_if check="prefix_Tag" param1="1" param2="2">
	true case
<inp2:m_else/>
	false case
</inp2:m_if>
<inp2:m_ParseBlock name="..."/>
<inp2:m_RenderElement name="..."/>

In order to replace the majority of the old tags, the following command must be executed in the root directory of the project:

find ./ -type f -name "*.tpl" | xargs \
sed -i -e "s/<inp2:m_blockend[^\/>]*[\/]*>/<\/inp2:m_DefineElement>/g" \
    -e "s/<inp2:m_block \(.*\)\/>/<inp2:m_DefineElement \1>/g" \
    -e "s/<inp2:m_if\(.*\)prefix=\"\(.*\)\"\(.*\)function=\"\(.*\)\"\([^\/>]*\)[\/]*>/<inp2:m_if\1check=\"\2_\4\"\3\5>/g" \
    -e "s/<inp2:m_endif[ ]*\/>/<\/inp2:m_if>/g" \
    -e "s/<inp2:m_ParseBlock\([^>]*\)>/<inp2:m_RenderElement\1>/g" \
    -e "s/\(<inp2:[^>]*\)\$PrefixSpecial_\([^\"]*\)/\1{\$PrefixSpecial}_\2/g" \
    -e "s/\(<inp2:[^>]*\)\$prefix_\([^\"]*\)/\1{\$prefix}_\2/g"

Next, it may be necessary to manually change tags of the following style:

  • <inp2:m_if ... /> to <inp2:m_if>
  • <inp2:m_DefineElement /> to <inp2:m_DefineElement>


For attribute tags, the following changes would need to be made:

old style attributes new style attributes
block render_as
block_* *_render_as
*_block *_render_as

XML compatible tags also increase the readability of templates, for example:

<inp2:p_ListProducts render_as="product_elem" row_start_render_as="row_start_elem" />

This structure is simple and intuitive because one understands immediately what's going on. From the tag name DefineElement it's inferred that it's only a declaration and the result/output won't be seen here, and instead will be used somewhere else.

As for IF we should use:

Пожалуйста начинайте пересматривать код в ваших шаблонах. Лучше не заменять название атрибутов совсем, а пользоваться следующей конструкцией: Please start reviewing the code in your templates. It's not always best to replace attribute names, using the following structure instead:

$param_value = $this->SelectParam($params, 'new_attribute_name,old_attribute_name,other_attribute_name');

which will return an attribute, only if one's passed. Kostja can help with any questions about this article.