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
b01a1e00
Commit
b01a1e00
authored
Dec 13, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue_31' into development: closing issue #31.
parents
22fbaa2b
235df11b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
134 additions
and
1 deletions
+134
-1
HISTORY.rst
+1
-0
pystache/commands.py
+72
-0
setup.py
+16
-1
tests/test_commands.py
+45
-0
No files found.
HISTORY.rst
View file @
b01a1e00
...
@@ -6,6 +6,7 @@ Next Release (version TBD)
...
@@ -6,6 +6,7 @@ Next Release (version TBD)
* Bugfix: Whitespace surrounding sections is no longer altered, in
* Bugfix: Whitespace surrounding sections is no longer altered, in
accordance with the mustache spec. [heliodor]
accordance with the mustache spec. [heliodor]
* A custom template loader can now be passed to a View. [cjerdonek]
* A custom template loader can now be passed to a View. [cjerdonek]
* Added a command-line interface. [vrde, cjerdonek]
* Added some docstrings. [kennethreitz]
* Added some docstrings. [kennethreitz]
0.4.0 (2011-01-12)
0.4.0 (2011-01-12)
...
...
pystache/commands.py
0 → 100644
View file @
b01a1e00
# coding: utf-8
"""
This module provides command-line access to pystache.
Run this script using the -h option for command-line help.
"""
import
json
# The optparse module is deprecated in Python 2.7 in favor of argparse.
# However, argparse is not available in Python 2.6 and earlier.
from
optparse
import
OptionParser
import
sys
# We use absolute imports here to allow use of this script from its
# location in source control (e.g. for development purposes).
# Otherwise, the following error occurs:
#
# ValueError: Attempted relative import in non-package
#
from
pystache.loader
import
Loader
from
pystache.template
import
Template
USAGE
=
"""
\
%
prog [-h] template context
Render a mustache template with the given context.
positional arguments:
template A filename or template string.
context A filename or JSON string."""
def
parse_args
(
sys_argv
,
usage
):
"""
Return an OptionParser for the script.
"""
args
=
sys_argv
[
1
:]
parser
=
OptionParser
(
usage
=
usage
)
options
,
args
=
parser
.
parse_args
(
args
)
template
,
context
=
args
return
template
,
context
def
main
(
sys_argv
):
template
,
context
=
parse_args
(
sys_argv
,
USAGE
)
if
template
.
endswith
(
'.mustache'
):
template
=
template
[:
-
9
]
try
:
template
=
Loader
()
.
load_template
(
template
)
except
IOError
:
pass
try
:
context
=
json
.
load
(
open
(
context
))
except
IOError
:
context
=
json
.
loads
(
context
)
print
(
Template
(
template
,
context
)
.
render
())
if
__name__
==
'__main__'
:
main
(
sys
.
argv
)
setup.py
View file @
b01a1e00
...
@@ -19,19 +19,34 @@ def publish():
...
@@ -19,19 +19,34 @@ def publish():
os
.
system
(
'python setup.py sdist upload'
)
os
.
system
(
'python setup.py sdist upload'
)
def
make_long_description
():
"""
Return the long description for the package.
"""
long_description
=
open
(
'README.rst'
)
.
read
()
+
'
\n\n
'
+
open
(
'HISTORY.rst'
)
.
read
()
return
long_description
if
sys
.
argv
[
-
1
]
==
'publish'
:
if
sys
.
argv
[
-
1
]
==
'publish'
:
publish
()
publish
()
sys
.
exit
()
sys
.
exit
()
long_description
=
make_long_description
()
setup
(
name
=
'pystache'
,
setup
(
name
=
'pystache'
,
version
=
'0.3.1'
,
version
=
'0.3.1'
,
description
=
'Mustache for Python'
,
description
=
'Mustache for Python'
,
long_description
=
open
(
'README.rst'
)
.
read
()
+
'
\n\n
'
+
open
(
'HISTORY.rst'
)
.
read
()
,
long_description
=
long_description
,
author
=
'Chris Wanstrath'
,
author
=
'Chris Wanstrath'
,
author_email
=
'chris@ozmm.org'
,
author_email
=
'chris@ozmm.org'
,
url
=
'http://github.com/defunkt/pystache'
,
url
=
'http://github.com/defunkt/pystache'
,
packages
=
[
'pystache'
],
packages
=
[
'pystache'
],
license
=
'MIT'
,
license
=
'MIT'
,
entry_points
=
{
'console_scripts'
:
[
'pystache=pystache.commands:main'
],
},
classifiers
=
(
classifiers
=
(
'Development Status :: 4 - Beta'
,
'Development Status :: 4 - Beta'
,
'License :: OSI Approved :: MIT License'
,
'License :: OSI Approved :: MIT License'
,
...
...
tests/test_commands.py
0 → 100644
View file @
b01a1e00
# coding: utf-8
"""
Unit tests of commands.py.
"""
import
sys
import
unittest
from
pystache.commands
import
main
ORIGINAL_STDOUT
=
sys
.
stdout
class
MockStdout
(
object
):
def
__init__
(
self
):
self
.
output
=
""
def
write
(
self
,
str
):
self
.
output
+=
str
class
CommandsTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
sys
.
stdout
=
MockStdout
()
def
callScript
(
self
,
template
,
context
):
argv
=
[
'pystache'
,
template
,
context
]
main
(
argv
)
return
sys
.
stdout
.
output
def
testMainSimple
(
self
):
"""
Test a simple command-line case.
"""
actual
=
self
.
callScript
(
"Hi {{thing}}"
,
'{"thing": "world"}'
)
self
.
assertEquals
(
actual
,
u"Hi world
\n
"
)
def
tearDown
(
self
):
sys
.
stdout
=
ORIGINAL_STDOUT
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