-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
144 lines (113 loc) · 3.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var express = require('express');
var formidable = require('formidable');
var app = express();
const bodyParser = require('body-parser');
var fs = require('fs');
var htmlToJson = require('html-to-json');
const fileUpload = require('express-fileupload');
app.use(fileUpload());
//otro config
app.use(express.static(__dirname + '/public'))
app.use(bodyParser.urlencoded({ extended: true }));
//config
app.set('appName', 'c#_to_python');
app.set('version', '1.0');
app.set('port', '3000');
app.set('view engine', 'ejs');
let ix = require('./intern.js');
var xm = "";
var sd=0;
let fls=[];
//rutas
app.get('/', function (req, res) {
if(fls.length==0){
var t=[fls.length+"","default",""];
fls.push(t);
}
res.render('index.ejs', {
texto: fls[sd][2],
pp:fls,
tit:fls[sd][1]
});
});
app.get('/doc', function (req, res) {
res.render('doc.ejs');
});
app.get('/o/:tt', function (req, res) {
var e=req.params.tt;
sd=e;
res.redirect('/');
});
app.get('/nuevo', function (req, res) {
if(fls[fls.length-1][1]!="default"){
var t=[fls.length+"","default",""];
fls.push(t);
sd=fls.length-1;
}
res.redirect('/');
});
app.post('/upl', function (req, res) {
//console.log(req.files.foo.data.toString('utf8'));
if(fls[fls.length-1][2]==""){
var t=[fls.length-1+"",req.files.foo.name,req.files.foo.data.toString('utf8')];
fls[fls.length-1]=t;
sd=fls.length-1;
}else{
var t=[fls.length+"",req.files.foo.name,req.files.foo.data.toString('utf8')];
sd=fls.length-1;
fls.push(t);
}
res.redirect("/");
});
app.post('/', function (req, res) {
var txt = req.body.texto;
ix.start_all(txt);
res.redirect('/compiled');
});
app.get('/compiled', function (req, res) {
let tokk = ix.lst.ret_arr();
let erx = ix.lst.ret_err();
let varx = ix.sintax.ret_var();
let pyx = ix.sintax.ret_py();
let htx = ix.sintax.ret_html();
ch(htx);
zzz(pyx, htx, xm);
res.render('compiled.ejs', {
tokens: tokk,
errores: erx,
variables: varx,
python: pyx,
ht: htx,
superjsx: xm
});
});
function zzz(c_py, c_ht, c_js){
fs.writeFile('./public/python.py', c_py, function (err) {
if (err) throw err;
//console.log('Saved!');
});
fs.writeFile('./public/rec_html.html', c_ht, function (err) {
if (err) throw err;
//console.log('Saved!');
});
fs.writeFile('./public/rec_json.json', c_js, function (err) {
if (err) throw err;
//console.log('Saved!');
});
}
app.listen(app.get('port'), function () {
console.log('Example app listening on port', app.get('port'));
});
function ch(opu){
var promise = htmlToJson.parse(opu, {
'text': function ($doc) {
return $doc.find('html').text();
}
}, function (err, result) {
xm=result;
//console.log(result);
});
promise.done(function (result) {
//Works as well
});
}