Skip to content

Commit 6fc8943

Browse files
committed
v1.0.0
0 parents  commit 6fc8943

File tree

14 files changed

+11236
-0
lines changed

14 files changed

+11236
-0
lines changed

include.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<? if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();
2+
3+
use Bitrix\Main\Localization\Loc;
4+
5+
Loc::loadMessages(__FILE__);
6+
7+
$arComponentDescription = array(
8+
"NAME" => Loc::getMessage('PAF_LESS_DESC_NAME'),
9+
"DESCRIPTION" => Loc::getMessage('PAF_LESS_DESC_DESCRIPTION'),
10+
"PATH" => array(
11+
"ID" => "utility"
12+
),
13+
"AREA_BUTTONS" => array(
14+
array(
15+
'TITLE' => Loc::getMessage('PAF_LESS_DESC_AREA_BUTTONS_TITLE')
16+
),
17+
),
18+
"CACHE_PATH" => "Y",
19+
"COMPLEX" => "N"
20+
);
21+
?>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
3+
die();
4+
}
5+
6+
use \Bitrix\Main\Application as App;
7+
use \Bitrix\Main\Localization\Loc as Loc;
8+
9+
Loc::loadMessages(__FILE__);
10+
11+
$files = array();
12+
$context = App::getInstance()->getContext();
13+
$rootFolder = $context->getServer()->getDocumentRoot();
14+
if (isset($arCurrentValues["PATH"])
15+
&& is_dir($rootFolder . $arCurrentValues["PATH"])
16+
&& $handle = opendir($rootFolder . $arCurrentValues["PATH"])
17+
) {
18+
19+
while (false !== ($file = readdir($handle))) {
20+
if ($file != "." && $file != "..") {
21+
$files[$file] = $file;
22+
}
23+
}
24+
closedir($handle);
25+
}
26+
27+
$arComponentParameters = array(
28+
"GROUPS" => array(),
29+
"PARAMETERS" => array(
30+
31+
"PATH" => array(
32+
"PARENT" => "BASE",
33+
"NAME" => Loc::getMessage('PAF_LESS_PATH'),
34+
"TYPE" => "STRING",
35+
"MULTIPLE" => "N",
36+
"DEFAULT" => "",
37+
"REFRESH" => "Y",
38+
),
39+
40+
"FILES" => array(
41+
"PARENT" => "BASE",
42+
"NAME" => Loc::getMessage('PAF_LESS_FILES'),
43+
"TYPE" => "LIST",
44+
"MULTIPLE" => "Y",
45+
"DEFAULT" => "",
46+
"VALUES" => $files,
47+
),
48+
49+
"PATH_CSS" => array(
50+
"PARENT" => "BASE",
51+
"NAME" => Loc::getMessage('PAF_LESS_PATH_CSS'),
52+
"TYPE" => "STRING",
53+
"MULTIPLE" => "N",
54+
"DEFAULT" => "",
55+
"REFRESH" => "N",
56+
),
57+
58+
"COMPRESS" => array(
59+
"PARENT" => "BASE",
60+
"NAME" => Loc::getMessage('PAF_LESS_COMPRESS'),
61+
"TYPE" => "CHECKBOX",
62+
"DEFAULT" => "Y",
63+
),
64+
"SOURSEMAP" => array(
65+
"PARENT" => "BASE",
66+
"NAME" => Loc::getMessage('PAF_LESS_SOURSEMAP'),
67+
"TYPE" => "CHECKBOX",
68+
"DEFAULT" => "N",
69+
),
70+
71+
),
72+
);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
use \Bitrix\Main;
3+
use \Bitrix\Main\Localization\Loc as Loc;
4+
use \Bitrix\Main\SystemException as SystemException;
5+
use \Bitrix\Main\Page\Asset as Asset;
6+
use \Bitrix\Main\Application as App;
7+
8+
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) {
9+
die();
10+
}
11+
12+
class PafnutyLessComponent extends CBitrixComponent {
13+
14+
/**
15+
* Check Required Modules
16+
* @throws Exception
17+
*/
18+
protected function checkModules() {
19+
if (!Main\Loader::includeModule('pafnuty.less')) {
20+
throw new SystemException(Loc::getMessage('CVP_PAFNUTY_LESS_MODULE_NOT_INSTALLED'));
21+
}
22+
23+
}
24+
25+
/**
26+
* Load language file
27+
*/
28+
public function onIncludeComponentLang() {
29+
$this->includeComponentLang(basename(__FILE__));
30+
Loc::loadMessages(__FILE__);
31+
}
32+
33+
/**
34+
* Prepare Component Params
35+
*/
36+
public function onPrepareComponentParams($params) {
37+
38+
$params['COMPRESS'] = ($params['COMPRESS'] == 'Y');
39+
$params['SOURSEMAP'] = ($params['SOURSEMAP'] == 'Y');
40+
41+
$params['FILES'] = is_array($params['FILES']) ? $params['FILES'] : array('template_styles.less');
42+
43+
$params['PATH_TO_FILES'] = isset($params['PATH']) && strlen(trim($params['PATH']))
44+
? preg_replace(array('~^/~', '~/$~'), '/', trim($params['PATH']))
45+
: SITE_TEMPLATE_PATH . '/less/';
46+
47+
$params['PATH_TO_FILES_CSS'] = isset($params['PATH_CSS']) && strlen(trim($params['PATH_CSS']))
48+
? preg_replace(array('~^/~', '~/$~'), '/', trim($params['PATH_CSS']))
49+
: SITE_TEMPLATE_PATH . '/';
50+
51+
return $params;
52+
}
53+
54+
public function executeComponent() {
55+
56+
try {
57+
58+
$this->checkModules();
59+
60+
$context = App::getInstance()->getContext();
61+
62+
$rootFolder = $context->getServer()->getDocumentRoot();
63+
64+
$lessFolder = $this->arParams['PATH_TO_FILES'];
65+
$fileNames = $this->arParams['FILES'];
66+
$compress = $this->arParams['COMPRESS'];
67+
$sourceMap = $this->arParams['SOURSEMAP'];
68+
$cssFolder = $this->arParams['PATH_TO_FILES_CSS'];
69+
70+
$compile = new \Pafnuty\Less\lessCompiler($rootFolder, $lessFolder, $fileNames, $cssFolder, $compress, $sourceMap);
71+
72+
$file = $compile->compile();
73+
74+
if ($file['error']) {
75+
// Заменим виндовые слеши.
76+
$rootFolder = str_replace('\\', '/', $rootFolder);
77+
78+
/**
79+
* @todo Оптимизировать надо бы по хорошему этот момент
80+
*/
81+
Asset::getInstance()->addString('<style>.less-error-wrapper{position:fixed;z-index:1500;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.7)}.less-error-content{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:100%}.less-error{padding:40px;color:#666;background:#fff;font:400 17px/30px Consolas,Menlo,"DejaVu Sans Mono","Courier New",monospace,serif;margin:0;word-wrap:break-word;-webkit-box-shadow:0 0 30px rgba(0,0,0,.6);box-shadow:0 0 30px rgba(0,0,0,.6)}.less-error-header{font-size:24px;font-weight:700;margin-bottom:20px;text-align:center;color:#f75b5b}.less-error-content pre{line-height:1;border:0;background-color:transparent}</style>');
82+
83+
// Выведем текст ошибки
84+
$errorText = '<div class="less-error-wrapper"><div class="less-error-content"><div class="less-error"><div class="less-error-header">' . Loc::GetMessage('PAF_ERROR_LESS_COMPILE') . '</div><pre>' . str_replace($rootFolder, '', $file['error']) . '</pre></div></div></div>';
85+
echo $errorText;
86+
}
87+
88+
} catch (SystemException $e) {
89+
ShowError($e->getMessage());
90+
}
91+
92+
}
93+
94+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
$MESS['PAF_LESS_DESC_NAME'] = 'LESS Компилятор';
3+
$MESS['PAF_LESS_DESC_DESCRIPTION'] = 'Быстрый LESS-компилятор с кешированием и плюшками.';
4+
$MESS['PAF_LESS_DESC_AREA_BUTTONS_TITLE'] = 'Редактировать параметры компонента';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
$MESS['PAF_LESS_PATH'] = 'Путь от корня сайта к папаке с LESS файлами';
3+
$MESS['PAF_LESS_PATH_CSS'] = 'Путь от корня сайта к папке для скомпилированного CSS-файла';
4+
$MESS['PAF_LESS_FILES'] = 'Список файлов для компиляции';
5+
$MESS['PAF_LESS_COMPRESS'] = 'Минифицировать CSS файл';
6+
$MESS['PAF_LESS_SOURSEMAP'] = 'Генерировать SourseMap';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
$MESS['CVP_PAFNUTY_LESS_MODULE_NOT_INSTALLED'] = 'Компонент "pafnuty.less" не установлен.';
3+
$MESS['PAF_ERROR_LESS_COMPILE'] = 'Ошибка компиляции LESS!';

install/index.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
use \Bitrix\Main\Localization\Loc as Loc;
3+
4+
Loc::loadMessages(__FILE__);
5+
6+
class pafnuty_less extends CModule {
7+
var $MODULE_ID = 'pafnuty.less';
8+
var $MODULE_VERSION;
9+
var $MODULE_VERSION_DATE;
10+
var $MODULE_NAME;
11+
var $MODULE_DESCRIPTION;
12+
var $MODULE_CSS;
13+
var $strError = '';
14+
15+
function pafnuty_less() {
16+
$arModuleVersion = array();
17+
$path = str_replace("\\", "/", __FILE__);
18+
$path = substr($path, 0, strlen($path) - strlen("/index.php"));
19+
include $path . "/version.php";
20+
21+
$this->MODULE_VERSION = $arModuleVersion["VERSION"];
22+
$this->MODULE_VERSION_DATE = $arModuleVersion["VERSION_DATE"];
23+
$this->MODULE_NAME = Loc::getMessage("PAFNUTY_LESS_MODULE_NAME");
24+
$this->MODULE_DESCRIPTION = Loc::getMessage("PAFNUTY_LESS_MODULE_DESCRIPTION");
25+
26+
$this->PARTNER_NAME = GetMessage("PAFNUTY_LESS_PARTNER_NAME");
27+
$this->PARTNER_URI = GetMessage("PAFNUTY_LESS_PARTNER_URI");
28+
}
29+
30+
function GetModuleTasks() {
31+
return array();
32+
}
33+
34+
function InstallDB($arParams = array()) {
35+
global $DB, $DBType, $APPLICATION;
36+
37+
$this->InstallTasks();
38+
RegisterModule($this->MODULE_ID);
39+
CModule::IncludeModule($this->MODULE_ID);
40+
41+
return true;
42+
}
43+
44+
function UnInstallDB($arParams = array()) {
45+
global $DB, $DBType, $APPLICATION;
46+
$this->errors = false;
47+
48+
UnRegisterModule($this->MODULE_ID);
49+
50+
if ($this->errors !== false) {
51+
$APPLICATION->ThrowException(implode("<br>", $this->errors));
52+
return false;
53+
}
54+
return true;
55+
}
56+
57+
function InstallEvents() {
58+
return true;
59+
}
60+
61+
function UnInstallEvents() {
62+
return true;
63+
}
64+
65+
function InstallFiles($arParams = array()) {
66+
CopyDirFiles($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/" . $this->MODULE_ID . "/install/components/", $_SERVER["DOCUMENT_ROOT"] . "/bitrix/components", true, true);
67+
return true;
68+
}
69+
70+
function UnInstallFiles() {
71+
DeleteDirFiles($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/" . $this->MODULE_ID . "/install/components/", $_SERVER["DOCUMENT_ROOT"] . "/bitrix/components");
72+
return true;
73+
}
74+
75+
function DoInstall() {
76+
global $USER, $APPLICATION;
77+
78+
if ($USER->IsAdmin()) {
79+
if ($this->InstallDB()) {
80+
$this->InstallEvents();
81+
$this->InstallFiles();
82+
}
83+
$GLOBALS["errors"] = $this->errors;
84+
}
85+
}
86+
87+
function DoUninstall() {
88+
global $DB, $USER, $DOCUMENT_ROOT, $APPLICATION, $step;
89+
90+
if ($USER->IsAdmin()) {
91+
if ($this->UnInstallDB()) {
92+
$this->UnInstallEvents();
93+
$this->UnInstallFiles();
94+
}
95+
$GLOBALS["errors"] = $this->errors;
96+
}
97+
}
98+
}
99+
?>

install/version.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?
2+
$arModuleVersion = array(
3+
"VERSION" => "1.0.0",
4+
"VERSION_DATE" => "2015-12-01 02:00:00",
5+
);
6+
?>

lang/ru/install/index.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$MESS['PAFNUTY_LESS_MODULE_NAME'] = "LESS Компилятор";
3+
$MESS['PAFNUTY_LESS_MODULE_DESCRIPTION'] = "Быстрый LESS-компилятор с кешированием и плюшками.";
4+
$MESS['PAFNUTY_LESS_INSTALL_TITLE'] = "Установка компонента «LESS Компилятор»";
5+
$MESS['PAFNUTY_LESS_UNINSTALL_TITLE'] = "Удаление компонента «LESS Компилятор»";
6+
$MESS['PAFNUTY_LESS_PARTNER_NAME'] = "Павел Белоусов";
7+
$MESS['PAFNUTY_LESS_PARTNER_URI'] = "http://pafnuty.name";

0 commit comments

Comments
 (0)