Skip to content

Commit c692486

Browse files
Classify name of Class in Python Template (as this will be done with … (#55)
* Classify name of Class in Python Template (as this will be done with the Reflex Class name if its read from js during runtime). Fixed generation of templates in case of underscores. * Make sure that filenames still use lowercase Co-authored-by: Jonathan Sundqvist <sundqvist.jonathan@gmail.com>
1 parent adaa00d commit c692486

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

sockpuppet/management/commands/generate_reflex.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.template.loader import get_template
44

55
from ._base import BaseGenerateCommand
6-
6+
from ...utils import classify
77

88
TEMPLATES = {
99
'_reflex.py': 'sockpuppet/scaffolds/reflex.py',
@@ -46,8 +46,8 @@ def handle(self, *args, **options):
4646
for path, suffix in paths:
4747
template_name = TEMPLATES[suffix]
4848
template = get_template(template_name)
49-
rendered = template.render({'reflex_name': reflex_name})
50-
self.create_file(path, '{}{}'.format(reflex_name, suffix), rendered)
49+
rendered = template.render({'class_name': classify(reflex_name), 'reflex_name': reflex_name})
50+
self.create_file(path, '{}{}'.format(reflex_name.lower(), suffix), rendered)
5151

5252
self.create_file('views', '__init__.py', '')
5353
self.create_file('reflexes', '__init__.py', '')

sockpuppet/templates/sockpuppet/scaffolds/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Application } from 'stimulus'
22
import StimulusReflex from 'stimulus_reflex'
33
import WebsocketConsumer from 'sockpuppet-js'
4-
import {{reflex_name|title }}Controller from './controllers/{{reflex_name}}_controller'
4+
import {{ reflex_name|title }}Controller from './controllers/{{ reflex_name|lower }}_controller'
55

66
const application = Application.start()
77
const consumer = new WebsocketConsumer('ws://localhost:8000/ws/sockpuppet-sync')

sockpuppet/templates/sockpuppet/scaffolds/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export default class extends Controller {
99
increment(event) {
1010
console.log('increment')
1111
event.preventDefault()
12-
this.stimulate('{{ reflex_name|title }}Reflex#increment', 1)
12+
this.stimulate('{{ reflex_name }}Reflex#increment', 1)
1313
}
1414
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from sockpuppet.reflex import Reflex
22

33

4-
class {{ reflex_name|title }}Reflex(Reflex):
4+
class {{ class_name }}Reflex(Reflex):
55
def increment(self, step=1):
66
self.count = int(self.element.dataset['count']) + step

sockpuppet/templates/sockpuppet/scaffolds/view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from django.views.generic.base import TemplateView
22

33

4-
class {{ reflex_name|title }}View(TemplateView):
5-
template_name = '{{ reflex_name }}.html'
4+
class {{ class_name }}View(TemplateView):
5+
template_name = '{{ reflex_name|lower }}.html'
66

77
def get_context_data(self, *args, **kwargs):
88
context = super().get_context_data(*args, **kwargs)

0 commit comments

Comments
 (0)