Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e9089a6

Browse files
update module
1 parent ffb3efb commit e9089a6

File tree

5 files changed

+140
-46
lines changed

5 files changed

+140
-46
lines changed

‎.gitignore‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port

‎README.md‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,15 @@ myConfig.data = {
3636
port : 2020,
3737
isDebug : true, //Сообшения сервера
3838
};
39-
//Конфигурация модуля Output
40-
myConfig.output = {
39+
40+
varoutput = require('output-view')({
4141
//Папка отображений
42-
dir : require('path').dirname(require.main.filename),
42+
dir : './',
4343
//Очищать код
44-
clear : false,
44+
clear : true,
4545
//Режим отладки
4646
isDebug : false,
47-
};
48-
49-
var output = require('output-view')(myConfig.output);
47+
});
5048

5149
var http = require('http');
5250
//Формируем задачу
@@ -55,7 +53,6 @@ var app = function(req, res) {
5553
console.log('\nПолучен запрос req.url', req.url);
5654
console.time('app');//Установим метку времени
5755
}
58-
req.output = output;
5956

6057
var rows =
6158
[
@@ -69,13 +66,13 @@ var app = function(req, res) {
6966
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
7067
/*
7168
res.write(
72-
req.output.view({
69+
output.view({
7370
text : 'Hello, World!',
7471
})
7572
);
7673
*/
7774
res.write(
78-
req.output.view({
75+
output.view({
7976
//Название файла
8077
file : '/test.php',
8178
//Переменные
@@ -92,9 +89,8 @@ var app = function(req, res) {
9289

9390
res.end();
9491

95-
if (myConfig.data.isDebug) {
96-
console.timeEnd('app');
97-
}
92+
//Выводим общее время
93+
if (myConfig.data.isDebug) console.timeEnd('app');
9894
};
9995
//Создаем и запускаем сервер для задачи
10096
var server = http.createServer(app);

‎_demo/server.js‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ myConfig.data = {
55
port : 2020,
66
isDebug : true, //Сообшения сервера
77
};
8-
//Конфигурация модуля Output
9-
myConfig.output = {
8+
9+
varoutput = require('output-view')({
1010
//Папка отображений
11-
dir : require('path').dirname(require.main.filename),
11+
dir : './',
1212
//Очищать код
1313
clear : true,
1414
//Режим отладки
1515
isDebug : false,
16-
};
17-
18-
var output = require('output-view')(myConfig.output);
16+
});
1917

2018
var http = require('http');
2119
//Формируем задачу
@@ -25,7 +23,6 @@ var app = function(req, res) {
2523
console.log('\nПолучен запрос req.url', req.url);
2624
console.time('app');
2725
}
28-
req.output = output;
2926

3027
var rows =
3128
[
@@ -39,13 +36,13 @@ var app = function(req, res) {
3936
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
4037
/*
4138
res.write(
42-
req.output.view({
39+
output.view({
4340
text : 'Hello, World!',
4441
})
4542
);
4643
*/
4744
res.write(
48-
req.output.view({
45+
output.view({
4946
//Название файла
5047
file : '/test.php',
5148
//Переменные
@@ -63,9 +60,7 @@ var app = function(req, res) {
6360
res.end();
6461

6562
//Выводим общее время
66-
if (myConfig.data.isDebug) {
67-
console.timeEnd('app');
68-
}
63+
if (myConfig.data.isDebug) console.timeEnd('app');
6964
};
7065
//Создаем и запускаем сервер для задачи
7166
var server = http.createServer(app);

‎index.js‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ var Output = function (config) {
33
var self = this;
44

55
//Формируем конфигурацию
6-
config = config || {};
6+
this.config = config || {};
77
//Расположение папки отображений относительно папки node_modules
8-
config.dir =config.dir==null ? require('path').dirname(require.main.filename) : config.dir;
8+
this.config.dir =this.config.dir||'./';
99
//Режим отладки
10-
config.isDebug = config.isDebug==null ? false : Boolean (config.isDebug);
10+
this.config.isDebug = this.config.isDebug==null ? false : Boolean (this.config.isDebug);
1111
//Очищать код
12-
config.clear = config.clear==null || config.isDebug ? false : Boolean (config.clear);
13-
14-
this.dir = config.dir==null ? require('path').dirname(require.main.filename) : config.dir;
12+
this.config.clear = this.config.clear==null || config.isDebug ? false : Boolean (this.config.clear);
1513

1614
this.error = function (text) {
1715
return '<div style="color:red">ERROR OUTPUT: <b>' + text + '</b></div>';
@@ -64,8 +62,8 @@ var Output = function (config) {
6462
params.data = params.data || {};
6563

6664
//Проверяем существование
67-
if (params.file && !require('fs').existsSync(self.dir + params.file)) {
68-
return self.error('Не найден файл "' + self.dir + params.file + '"');
65+
if (params.file && !require('fs').existsSync(self.config.dir + params.file)) {
66+
return self.error('Не найден файл "' + self.config.dir + params.file + '"');
6967
}
7068

7169
//Первоначальный код
@@ -86,9 +84,9 @@ var Output = function (config) {
8684
//Считывание файла или текста
8785
if (params.file) {
8886
try {
89-
input = require('fs').readFileSync(config.dir + params.file, 'utf8');
87+
input = require('fs').readFileSync(self.config.dir + params.file, 'utf8');
9088
} catch (e) {
91-
return self.error(['Ошибка чтения файла "' + self.dir + params.file + '"', e.toString()].join(': '));
89+
return self.error(['Ошибка чтения файла "' + self.config.dir + params.file + '"', e.toString()].join(': '));
9290
};
9391
} else {
9492
input = params.text + '';
@@ -112,11 +110,11 @@ var Output = function (config) {
112110
};
113111
};
114112

115-
if (config.isDebug) output += self.debug(['Входные данные params.data', JSON.stringify(params.data, null, 4)].join(': '));
113+
if (this.config.isDebug) output += self.debug(['Входные данные params.data', JSON.stringify(params.data, null, 4)].join(': '));
116114

117115
if (input) {
118116
//Разбираем код на блоки
119-
if (config.isDebug) output += self.debug(['Разбираем код на блоки...'].join(': '));
117+
if (this.config.isDebug) output += self.debug(['Разбираем код на блоки...'].join(': '));
120118

121119
//Извлекаем блок кода (с кодом html и php)
122120
var result = input.replace(self.re['html_php'], function (s, html, php) {
@@ -271,14 +269,14 @@ var Output = function (config) {
271269
return ''; //удаляем код блока HTML и PHP
272270
});
273271

274-
if (config.isDebug) output += self.debug(['Сформированы блоки', JSON.stringify(blocks, null, 4)].join(': '));
272+
if (this.config.isDebug) output += self.debug(['Сформированы блоки', JSON.stringify(blocks, null, 4)].join(': '));
275273

276274
//Перебор блоков (используем ТОЛЬКО цикл for для формирования переменных в пространстве окружения)
277-
if (config.isDebug) output += self.debug(['Перебор блоков...'].join(': '));
275+
if (this.config.isDebug) output += self.debug(['Перебор блоков...'].join(': '));
278276

279277
for (var i=0; i<blocks.length; i++) {
280278

281-
if (config.isDebug) output += self.debug(['block[' + i + ']=' + JSON.stringify(blocks[i], null, 4)].join(': '));
279+
if (this.config.isDebug) output += self.debug(['block[' + i + ']=' + JSON.stringify(blocks[i], null, 4)].join(': '));
282280
//if (config.isDebug) console.log(['DEBUG','block[' + i + ']=' + JSON.stringify(blocks[i], null, 4)].join(': '));
283281

284282
try {
@@ -451,7 +449,7 @@ var Output = function (config) {
451449
};
452450

453451
//Очистка кода
454-
if (config.clear) {
452+
if (this.config.clear) {
455453
//Удаление комментариев <!-- --> в html
456454
output = output.replace(self.re['comments_html'], '');
457455
//Поиск стилей
@@ -464,7 +462,6 @@ var Output = function (config) {
464462
output = output.replace(self.re['scripts'], function (s, a1, a2, a3) {
465463
//Удаление комментариев // (применять первым и осторожно! можно удалить http://)
466464
a2 = a2.replace(self.re['comments_slash'], '');
467-
//a2 = a2.replace(/(^|\s+|;)(?:\/\/[^\r\n]*?)(\r\n|$)/g, '1ドル2ドル');
468465
//Удаление комментариев /**/
469466
a2 = a2.replace(self.re['comments_stars'], '');
470467
return a1 + a2 + a3;

‎package.json‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"name": "output-view",
3-
"version": "1.0.5",
4-
"description": "PHP template for nodejs",
3+
"version": "1.0.6",
4+
"description": "PHP template preprocessor for nodejs",
55
"main": "index.js",
66
"dependencies": {},
77
"devDependencies": {},
8-
"scripts": {},
8+
"scripts": {
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
911
"repository": {
1012
"type": "git",
1113
"url": "git+https://github.com/German-Stepanov/nodejs-output-view.git"
@@ -16,7 +18,7 @@
1618
"template",
1719
"php"
1820
],
19-
"author": "german stepanov",
21+
"author": "German Stepanov",
2022
"license": "MIT",
2123
"bugs": {
2224
"url": "https://github.com/German-Stepanov/nodejs-output-view/issues"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /