Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit 258796f

Browse files
author
cstrap
committed
djangofy vue app
WIP check TODO
1 parent bc08524 commit 258796f

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

python_vuejs/django.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
import click
55
import os
6+
from .utils import touch, cd
67

78

89
@click.command()
910
@click.argument('project')
10-
def djangobuild(project):
11+
def django_build(project):
1112
"""
1213
Called inside `package.json`
1314
"""
@@ -25,14 +26,29 @@ def djangobuild(project):
2526

2627
@click.command()
2728
@click.argument('project')
28-
def djangofy(project):
29+
def djangofy_vue_project(project):
2930
"""
3031
Convert Vue.js webpack project into a django app
3132
"""
32-
os.makedirs('{project}/templates/{project}/'.format(project=project))
33+
urls_py = """# -*- coding: utf-8 -*-
34+
35+
from django.conf.urls import url
36+
from django.views.generic.base import TemplateView
37+
38+
urlpatterns = [
39+
url(r'^{project}/$', TemplateView.as_view(template_name='{project}/index.html'), name='vue_index'),
40+
]
41+
42+
""".format(project=project)
43+
try:
44+
os.makedirs('{project}/templates/{project}/'.format(project=project))
45+
except FileExistsError:
46+
pass
47+
with cd(project):
48+
touch('__init__.py')
49+
touch('index.html', 'templates/{project}/'.format(project=project))
50+
with open('urls.py', 'w') as f:
51+
f.write(urls_py)
3352
# TODO:
34-
# create urls.py
35-
# create __init__.py
36-
# create empty index.html under templates/project
3753
# edit `index.json` build
3854
# edit `package.json` build

python_vuejs/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ def cd(path):
1515
os.chdir(path)
1616
yield
1717
os.chdir(prev_cwd)
18+
19+
20+
def touch(filename, extrapath=''):
21+
open(os.path.join(extrapath, filename), 'a').close()

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
'checkenv=python_vuejs.vuejs:check_env',
3737
'vuecli=python_vuejs.vuejs:install_vue_cli',
3838
'startvueapp=python_vuejs.vuejs:startvueapp',
39-
'startvueapp=python_vuejs.vuejs:vuedev',
40-
'djangobuild=python_vueks.django:djbuild',
41-
'djangofy=python_vuejs.django:djvue',
39+
'vuedev=python_vuejs.vuejs:vuedev',
40+
'djbuild=python_vueks.django:django_build',
41+
'djvue=python_vuejs.django:djangofy_vue_project',
4242
]
4343
},
4444
include_package_data=True,

0 commit comments

Comments
 (0)