Yii2-imperavi-widget 启动与配置指南

Yii2-imperavi-widget 启动与配置指南

yii2-imperavi-widget Imperavi Redactor widget for Yii 2 yii2-imperavi-widget 项目地址: https://gitcode.com/gh_mirrors/yi/yii2-imperavi-widget

项目目录结构及介绍

该项目是一个为Yii 2框架提供的Imperavi Redactor WYSIWYG编辑器插件的封装。Imperavi Redactor是一个高质量的富文本编辑器。Yii社区购买了OEM许可证,因此你可以免费与Yii一起使用Imperavi Redactor。

项目的目录结构如下:

yii2-imperavi-widget/
├── src/                 # 源代码目录
│   ├── ImperaviRedactor.php   # 主插件类
│   ├── actions/           # 行为类目录
│   │   ├── GetImagesAction.php
│   │   ├── GetFilesAction.php
│   │   └── UploadFileAction.php
│   ├── assets/           # 资源目录
│   │   └── imperavi/
│   ├── tests/            # 测试目录
│   │   └── functional/
│   ├── README.md         # 项目说明文件
│   ├── LICENSE.md        # 许可证文件
│   ├── CHANGELOG.md      # 更新日志
│   ├── CONTRIBUTING.md   # 贡献指南
│   ├── UPGRADE.md        # 升级指南
│   └── composer.json     # Composer配置文件
├── .gitattributes        # Git属性配置
├── .gitignore            # Git忽略文件配置
├── .scrutinizer.yml      # Scrutinizer代码质量检查配置
└── .travis.yml           # Travis CI配置

项目的启动文件介绍

启动文件是项目的入口点,通常位于src/ImperaviRedactor.php。这个文件定义了主插件类ImperaviRedactor,它是整个插件的核心。

<?php

namespace vova07\imperavi;

use yii\base\Widget;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\View;

/**
 * Class ImperaviRedactor
 * @package vova07\imperavi
 */
class ImperaviRedactor extends Widget
{
    public $selector;
    public $settings = [];
    public $options = [];
    public $htmlOptions = [];

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();
        if ($this->selector === null) {
            $this->selector = '#' . $this->getId();
        }
        $this->registerClientScript();
    }

    /**
     * @inheritdoc
     */
    public function run()
    {
        echo Html::textarea($this->name, $this->value, $this->htmlOptions);
    }

    protected function registerClientScript()
    {
        $view = $this->getView();
        ImperaviRedactorAssets::register($view);
        $id = $this->getId();
        $js = [];
        $options = Json::encode($this->clientOptions);
        $js[] = "jQuery('{$this->selector}').redactor($options);";
        $view->registerJs(implode("\n", $js));
    }

    protected function getClientOptions()
    {
        return ArrayHelper::merge([
            'lang' => 'ru',
            'minHeight' => 200,
            'plugins' => ['clips', 'fullscreen'],
            'clips' => [
                ['Lorem ipsum...', 'Lorem...'],
                ['red', '<span class="label-red">red</span>'],
                ['green', '<span class="label-green">green</span>'],
                ['blue', '<span class="label-blue">blue</span>'],
            ],
        ], $this->settings);
    }
}

项目的配置文件介绍

项目的配置文件主要是composer.json,它用于描述项目的依赖关系以及项目的基本信息。以下是composer.json文件的一个示例:

{
    "name": "vova07/yii2-imperavi-widget",
    "description": "Imperavi Redactor Widget for Yii 2",
    "type": "yii2-extension",
    "keywords": ["yii2", "extension", "imperavi", "redactor", "widget", "editor"],
    "license": "BSD-3-Clause",
    "authors": [
        {
            "name": "Vladimir Kozlov",
            "email": "semancik@gmail.com"
        }
    ],
    "require": {
        "yiisoft/yii2": "^2.0",
        "bower-asset/imperavi-redactor": "10.2.5"
    },
    "autoload": {
        "psr-4": {"vova07\\imperavi\\": "src/"}
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/vova07/yii2-imperavi-widget.git"
        }
    ],
    "extra": {
        "bootstrap": "vova07\\imperavi\\ImperaviRedactor"
    }
}

以上就是Yii2-imperavi-widget项目的启动和配置指南,希望对你有所帮助。

yii2-imperavi-widget Imperavi Redactor widget for Yii 2 yii2-imperavi-widget 项目地址: https://gitcode.com/gh_mirrors/yi/yii2-imperavi-widget

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郑微殉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值