This is an additional concept to markdown, where you can inject your custom tags to parse. All tags must be an instance of luya\tag\BaseTag and implement the parse($value, $sub) method in order to convert the input to your tag. Read more in the Guide [[concept-tags.md]]. The identifier of the tag is not related to your tag, so you can configure the same tag as different names with multiple purposes. To inject a created tag just use: php TagParser::inject('tagname', ['class' => 'path\to\TagClass']); To parse text with or without markdown use: php TagParser::convert('Hello tagnamevalue'); TagParser::convertWithMarkdown('**Hello** tagnamevalue');
Since: 1.0.0-rc1
Author: Basil Suter (basil@nadar.io)
Inheritance: extends yii\base\Object
Example #1
0
 public function testInjectTag()
 {
     TagParser::inject('foo', ['class' => LinkTag::class]);
     $tags = TagParser::getInstantiatedTagObjects();
     $this->arrayHasKey('foo', $tags);
     $this->assertInstanceOf('luya\\tag\\tags\\LinkTag', $tags['foo']);
 }
 public function getText()
 {
     $text = $this->getVarValue('text');
     if ($this->getVarValue('textType')) {
         return TagParser::convertWithMarkdown($text);
     }
     return $text;
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function onAfterFind($event)
 {
     if ($this->nl2br) {
         $event->sender->setAttribute($this->name, nl2br($event->sender->getAttribute($this->name)));
     }
     if ($this->markdown) {
         $event->sender->setAttribute($this->name, TagParser::convertWithMarkdown($event->sender->getAttribute($this->name)));
     }
 }
Example #4
0
 /**
  * Before bootstrap run process.
  *
  * @see \luya\base\BaseBootstrap::beforeRun()
  */
 public function beforeRun($app)
 {
     foreach ($app->tags as $name => $config) {
         TagParser::inject($name, $config);
     }
     foreach ($this->getModules() as $id => $module) {
         foreach ($module->urlRules as $rule) {
             $this->_urlRules[isset($rule['position']) ? $rule['position'] : UrlRule::POSITION_AFTER_LUYA][] = $rule;
         }
         foreach ($module->apis as $alias => $class) {
             $this->_apis[$alias] = $class;
         }
         foreach ($module->tags as $name => $config) {
             TagParser::inject($name, $config);
         }
     }
 }
Example #5
0
 public function getTableData()
 {
     $table = [];
     $i = 0;
     foreach ($this->getVarValue('table', []) as $key => $row) {
         ++$i;
         if ($this->getCfgValue('header', 0) == 1 && $i == 1) {
             continue;
         }
         if ($this->getCfgValue('parseMarkdown', false)) {
             foreach ($row as $k => $v) {
                 $row[$k] = TagParser::convertWithMarkdown($v);
             }
         }
         $table[] = $row;
     }
     return $table;
 }
 public function getTags()
 {
     return TagParser::getInstantiatedTagObjects();
 }
Example #7
0
 /**
  * Render the NavItem content and set several view specific data.
  *
  * @param integer $navItemId
  * @param string $appendix
  * @param boolean|integer $setNavItemTypeId To get the content of a version this parameter will change the database value from the nav item Model
  * to this provided value
  *
  * @throws NotFoundHttpException
  * @throws MethodNotAllowedHttpException
  */
 public function renderItem($navItemId, $appendix = null, $setNavItemTypeId = false)
 {
     $model = NavItem::find()->where(['id' => $navItemId])->with('nav')->one();
     if (!$model) {
         throw new NotFoundHttpException('The requested nav item could not found.');
     }
     Yii::$app->urlManager->contextNavItemId = $navItemId;
     Yii::$app->set('page', ['class' => 'luya\\cms\\frontend\\components\\Page', 'model' => $model]);
     $currentMenu = Yii::$app->menu->current;
     $event = new BeforeRenderEvent();
     $event->menu = $currentMenu;
     foreach ($model->nav->getProperties() as $property) {
         $object = $property->getObject();
         $object->trigger($object::EVENT_BEFORE_RENDER, $event);
         if (!$event->isValid) {
             throw new MethodNotAllowedHttpException('Your are not allowed to see this page.');
             return Yii::$app->end();
         }
     }
     if ($setNavItemTypeId !== false && !empty($setNavItemTypeId)) {
         $model->nav_item_type_id = $setNavItemTypeId;
     }
     $typeModel = $model->getType();
     if (!$typeModel) {
         throw new NotFoundHttpException("The requestd nav item could not be found with the paired type, maybe this version does not exists for this Type.");
     }
     $typeModel->setOptions(['navItemId' => $navItemId, 'restString' => $appendix]);
     $content = $typeModel->getContent();
     if ($content instanceof Response) {
         return Yii::$app->end(0, $content);
     }
     // it seems to be a json response as it is an array
     if (is_array($content)) {
         return $content;
     }
     // https://github.com/luyadev/luya/issues/863 - if context controller is not false and the layout variable is not empty, the layout file will be displayed
     // as its already renderd by the module controller itself.
     if ($typeModel->controller !== false && !empty($typeModel->controller->layout)) {
         $this->layout = false;
     }
     if ($this->view->title === null) {
         if (empty($model->title_tag)) {
             $this->view->title = $model->title;
         } else {
             $this->view->title = $model->title_tag;
         }
     }
     $this->view->registerMetaTag(['name' => 'og:title', 'content' => $this->view->title], 'fbTitle');
     $this->view->registerMetaTag(['name' => 'og:type', 'content' => 'website'], 'ogType');
     if (!empty($model->description)) {
         $this->view->registerMetaTag(['name' => 'description', 'content' => $model->description], 'metaDescription');
         $this->view->registerMetaTag(['name' => 'og:description', 'content' => $model->description], 'fbDescription');
     }
     if (!empty($model->keywords)) {
         $this->view->registerMetaTag(['name' => 'keywords', 'content' => implode(", ", $currentMenu->keywords)], 'metyKeywords');
     }
     if ($this->module->enableTagParsing) {
         $content = TagParser::convert($content);
     }
     if (Yii::$app->has('adminuser') && !Yii::$app->adminuser->isGuest && $this->module->overlayToolbar === true) {
         $this->view->registerCssFile('https://fonts.googleapis.com/icon?family=Material+Icons');
         $this->getView()->on(View::EVENT_BEGIN_BODY, [$this, 'renderToolbar'], ['content' => $content]);
     }
     return $content;
 }