-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.py
More file actions
340 lines (289 loc) · 12.3 KB
/
function.py
File metadata and controls
340 lines (289 loc) · 12.3 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# Author: Jesús Daza
# Nick: jedahee
# Email: jdaza.her@gmail.com
# Details: Script that contain the functionallity (Function class)
# Description: This script can create the structure folder or templates for projects
# with technologies like Bootstrap 5, Tailwind,
# HTML / CSS / JS, JQuery (Normal version, Mobile version, UI version)
# IMPORT
# ------
# External
# --------
import sys
import os
import platform
import webbrowser
class Function():
# Constructor
def __init__(self, folder_name, file_name, path):
# Attributes
# ----------
self.folder_name = "new_folder"
self.file_name = "new_file"
if platform.system() == "Linux":
self.path = "/home"
elif platform.system() == "Windows":
self.path = "C:/"
self.options = {
1: "Select project",
2: "Set folder name and file name",
3: "Create template",
0: "Exit"
}
self.projects = {
"Bootstrap": {
"(last) version_0": "5.1.3",
},
"Tailwind": {},
"HTML": {
"preprocessor_0": "CSS",
"preprocessor_1": "SCSS",
"preprocessor_2": "Less",
},
"JQuery": {
"version_0": "Normal",
"version_1": "Mobile",
"version_2": "UI",
},
}
# Method: Create a folder in the path specified
def create_folder(self):
try:
os.mkdir(self.path + "/" + self.folder_name)
return True;
except (PermissionError):
print("\n ERROR: Permission denied, can not create project in this path > " + self.path + " \n")
return False;
# Method: Create the template of the selected project
def create_template(self, project, version):
if (self.create_folder() == True):
if project == "Bootstrap":
self.create_html_bootstrap(version)
self.create_css()
self.create_js()
elif project == "Tailwind":
self.create_html_tailwind()
self.create_css()
self.create_js()
elif project == "HTML":
self.create_html()
if version == "CSS":
self.create_css()
elif version == "SCSS":
self.create_scss()
elif version == "Less":
self.create_less()
self.create_js()
elif project == "JQuery":
self.create_html_jquery(version)
print(">> *** Project created successfully *** <<")
# Method: Create the HTML file of the selected project
def create_html(self):
content = '''
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="''' + self.file_name + '''.css">
<title>Document</title>
</head>
<body>
<!-- Auto-generated with autoTemplate -->
<script src="''' + self.file_name + '''.js"></script>
</body>
</html>
'''
file = open(self.path + "/" + self.folder_name + "/" + self.file_name + ".html", "w+")
file.write(content)
file.close()
# Method: Create the HTML template with the BOOTSTRAP link
def create_html_bootstrap(self, version):
content = '''
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="''' + self.file_name + '''.css">
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@'''+version+'''/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<!-- Auto-generated with autoTemplate -->
<p class="display-1">Auto-generated with autoTemplate</p>
<script src="''' + self.file_name + '''.js"></script>
</body>
</html>
'''
file = open(self.path + "/" + self.folder_name + "/" + self.file_name + ".html", "w+")
file.write(content)
file.close()
# Method: Create the HTML template with the JQUERY link
def create_html_jquery(self, version):
link_jquery_normal = '<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>'
link_jquery_ui = '<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.min.js" integrity="sha256-eTyxS0rkjpLEo16uXTS0uVCS4815lc40K2iVpWDvdSY=" crossorigin="anonymous"></script>'
link_jquery_mobile = '<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js" integrity="sha256-Lsk+CDPOzTapLoAzWW0G/WeQeViS3FMzywpzPZV8SXk=" crossorigin="anonymous"></script>'
if (version == "Normal"):
link_selected = link_jquery_normal
elif (version == "Mobile"):
link_selected = link_jquery_mobile
elif (version == "UI"):
link_selected = link_jquery_ui
content = '''
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="''' + self.file_name + '''.css">
<title>Document</title>
</head>
<body>
<!-- Auto-generated with autoTemplate -->
<script src="''' + self.file_name + '''.js"></script>
<!-- JQuery Link -->
''' + link_selected + '''
</body>
</html>
'''
file = open(self.path + "/" + self.folder_name + "/" + self.file_name + ".html", "w+")
file.write(content)
file.close()
# Method: Create the HTML template with the TAILWIND link
def create_html_tailwind(self):
content = '''
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="''' + self.file_name + '''.css">
<script src="https://cdn.tailwindcss.com"></script>
<title>Document</title>
</head>
<body>
<!-- Auto-generated with autoTemplate -->
<h1 class="text-3xl font-bold underline">
Auto-generated with autoTemplate
</h1>
<script src="''' + self.file_name + '''.js"></script>
</body>
</html>
'''
file = open(self.path + "/" + self.folder_name + "/" + self.file_name + ".html", "w+")
file.write(content)
file.close()
# Method: Create the CSS file of the selected project
def create_css(self):
content = '''
/* Auto-generated with autoTemplate */
/* RESET */
*, button, input, textarea, select {
box-sizing: border-box;
outline: none;
border: none;
list-style: none;
text-decoration: none;
text-emphasis: none;
}
'''
file = open(self.path + "/" + self.folder_name + "/" + self.file_name + ".css", "w+")
file.write(content)
file.close()
# Method: Create the JS file of the selected project
def create_js(self):
content = '''
// Auto-generated with autoTemplate
window.onload = function(e) {
console.log('Auto-generated with autoTemplate')
}
'''
file = open(self.path + "/" + self.folder_name + "/" + self.file_name + ".js", "w+")
file.write(content)
file.close()
# Method: Create the SCSS file of the selected project
def create_scss(self):
content = '''
/* Auto-generated with autoTemplate */
/* RESET */
*, button, input, textarea, select {
box-sizing: border-box;
outline: none;
border: none;
list-style: none;
text-decoration: none;
text-emphasis: none;
}
'''
file = open(self.path + "/" + self.folder_name + "/" + self.file_name + ".scss", "w+")
file.write(content)
file.close()
# Method: Create the LESS file of the selected project
def create_less(self):
content = '''
/* Auto-generated with autoTemplate */
/* RESET */
*, button, input, textarea, select {
box-sizing: border-box;
outline: none;
border: none;
list-style: none;
text-decoration: none;
text-emphasis: none;
}
'''
file = open(self.path + "/" + self.folder_name + "/" + self.file_name + ".less", "w+")
file.write(content)
file.close()
# Method: Sets the path where the project will be created
def set_path(self, path):
self.path = path if os.path.exists(path) else ""
return self.path
# Method: Sets the filename
def set_fileName(self, file_name):
self.file_name = file_name if file_name != "" else self.file_name
# Method: Sets the foldername
def set_folderName(self, folder_name):
self.folder_name = folder_name if folder_name != "" else self.folder_name
# Method: Get and show the info from de the project
def get_info(self, project, details_project):
print("Path: " + str(self.path), end="\t")
print("Folder name: " + str(self.folder_name))
print("File name: " + str(self.file_name), end="\t")
print("Project: " + project + " (" + details_project + ") ")
# Method: Show the differents options to pick of each project
def print_keys_from_projects(self, project):
i = 0
for value in self.projects[project].values():
print("["+ list(self.projects[project].keys())[i] +"] -> " + str(value))
i += 1
# Method: Check that the 'option' parameter is inside of the 'array' parameter
def in_array(self, option, array):
return option in array;
# Method: Show menu options
def print_options(self):
for key, value in self.options.items():
print("-> "+str(key)+" <- " + value)
# Method: Show the differents projects to pick
def print_projects(self):
for key, value in self.projects.items():
print("--> "+key)
# Method: Show menu
def print_menu(self):
print("""
█████ ██ ██ ████████ ██████ ████████ ███████ ███ ███ ██████ ██ █████ ████████ ███████
██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ██
███████ ██ ██ ██ ██ ██ ██ █████ ██ ████ ██ ██████ ██ ███████ ██ █████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██████ ██ ██████ ██ ███████ ██ ██ ██ ███████ ██ ██ ██ ███████
████████████████████████████████████████████████████████████████████████████████████████████████████████
Author: jedahee02 Description: This script can create the structure folder or templates for projects
with technologies like Bootstrap 5, Tailwind, HTML / CSS / JS,
JQuery (Normal version, Mobile version, UI version)
""")