Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pystache_custom
Commits
c9cb0c53
Commit
c9cb0c53
authored
Dec 27, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch into development: moved make_template_name() from view to loader.
parents
22d5f044
4b884554
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
6 deletions
+42
-6
pystache/loader.py
+24
-0
pystache/view.py
+2
-6
tests/test_loader.py
+16
-0
No files found.
pystache/loader.py
View file @
c9cb0c53
...
@@ -6,6 +6,7 @@ This module provides a Loader class.
...
@@ -6,6 +6,7 @@ This module provides a Loader class.
"""
"""
import
os
import
os
import
re
import
sys
import
sys
from
.reader
import
Reader
from
.reader
import
Reader
...
@@ -14,6 +15,29 @@ from .reader import Reader
...
@@ -14,6 +15,29 @@ from .reader import Reader
DEFAULT_EXTENSION
=
'mustache'
DEFAULT_EXTENSION
=
'mustache'
def
make_template_name
(
obj
):
"""
Return the canonical template name for an object instance.
This method converts Python-style class names (PEP 8's recommended
CamelCase, aka CapWords) to lower_case_with_underscords. Here
is an example with code:
>>> class HelloWorld(object):
... pass
>>> hi = HelloWorld()
>>> make_template_name(hi)
'hello_world'
"""
template_name
=
obj
.
__class__
.
__name__
def
repl
(
match
):
return
'_'
+
match
.
group
(
0
)
.
lower
()
return
re
.
sub
(
'[A-Z]'
,
repl
,
template_name
)[
1
:]
class
Loader
(
object
):
class
Loader
(
object
):
def
__init__
(
self
,
search_dirs
=
None
,
extension
=
None
,
reader
=
None
):
def
__init__
(
self
,
search_dirs
=
None
,
extension
=
None
,
reader
=
None
):
...
...
pystache/view.py
View file @
c9cb0c53
...
@@ -9,6 +9,7 @@ import re
...
@@ -9,6 +9,7 @@ import re
from
types
import
UnboundMethodType
from
types
import
UnboundMethodType
from
.context
import
Context
from
.context
import
Context
from
.loader
import
make_template_name
from
.loader
import
Loader
from
.loader
import
Loader
from
.reader
import
Reader
from
.reader
import
Reader
from
.renderer
import
Renderer
from
.renderer
import
Renderer
...
@@ -94,12 +95,7 @@ class View(object):
...
@@ -94,12 +95,7 @@ class View(object):
if
self
.
template_name
:
if
self
.
template_name
:
return
self
.
template_name
return
self
.
template_name
template_name
=
self
.
__class__
.
__name__
return
make_template_name
(
self
)
def
repl
(
match
):
return
'_'
+
match
.
group
(
0
)
.
lower
()
return
re
.
sub
(
'[A-Z]'
,
repl
,
template_name
)[
1
:]
def
render
(
self
):
def
render
(
self
):
"""
"""
...
...
tests/test_loader.py
View file @
c9cb0c53
...
@@ -4,11 +4,27 @@ import os
...
@@ -4,11 +4,27 @@ import os
import
sys
import
sys
import
unittest
import
unittest
from
pystache.loader
import
make_template_name
from
pystache.loader
import
Loader
from
pystache.loader
import
Loader
from
pystache.reader
import
Reader
from
pystache.reader
import
Reader
from
.common
import
DATA_DIR
from
.common
import
DATA_DIR
class
MakeTemplateNameTests
(
unittest
.
TestCase
):
"""
Test the make_template_name() function.
"""
def
test
(
self
):
class
FooBar
(
object
):
pass
foo
=
FooBar
()
self
.
assertEquals
(
make_template_name
(
foo
),
'foo_bar'
)
class
LoaderTestCase
(
unittest
.
TestCase
):
class
LoaderTestCase
(
unittest
.
TestCase
):
search_dirs
=
'examples'
search_dirs
=
'examples'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment