mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-06 13:01:50 +02:00
Add moment.js w/ Jinja integration
This commit is contained in:
parent
5ebcc8bd51
commit
745c3fb8b5
3 changed files with 24 additions and 0 deletions
21
ihatemoney/momentjs.py
Normal file
21
ihatemoney/momentjs.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
from jinja2 import Markup
|
||||||
|
|
||||||
|
|
||||||
|
class momentjs(object):
|
||||||
|
def __init__(self, timestamp):
|
||||||
|
self.timestamp = timestamp
|
||||||
|
|
||||||
|
def render(self, format):
|
||||||
|
return Markup(
|
||||||
|
'<script>\ndocument.write(moment("%s").%s);\n</script>'
|
||||||
|
% (self.timestamp.strftime("%Y-%m-%dT%H:%M:%S Z"), format)
|
||||||
|
)
|
||||||
|
|
||||||
|
def format(self, fmt):
|
||||||
|
return self.render('format("%s")' % fmt)
|
||||||
|
|
||||||
|
def calendar(self):
|
||||||
|
return self.render("calendar()")
|
||||||
|
|
||||||
|
def fromNow(self):
|
||||||
|
return self.render("fromNow()")
|
|
@ -20,6 +20,7 @@ from ihatemoney.utils import (
|
||||||
from ihatemoney.web import main as web_interface
|
from ihatemoney.web import main as web_interface
|
||||||
|
|
||||||
from ihatemoney import default_settings
|
from ihatemoney import default_settings
|
||||||
|
from ihatemoney.momentjs import momentjs
|
||||||
|
|
||||||
|
|
||||||
def setup_database(app):
|
def setup_database(app):
|
||||||
|
@ -146,6 +147,7 @@ def create_app(
|
||||||
app.jinja_env.globals["static_include"] = static_include
|
app.jinja_env.globals["static_include"] = static_include
|
||||||
app.jinja_env.globals["locale_from_iso"] = locale_from_iso
|
app.jinja_env.globals["locale_from_iso"] = locale_from_iso
|
||||||
app.jinja_env.filters["minimal_round"] = minimal_round
|
app.jinja_env.filters["minimal_round"] = minimal_round
|
||||||
|
app.jinja_env.globals["momentjs"] = momentjs
|
||||||
|
|
||||||
# Translations
|
# Translations
|
||||||
babel = Babel(app)
|
babel = Babel(app)
|
||||||
|
|
1
ihatemoney/static/js/moment.min.js
vendored
Normal file
1
ihatemoney/static/js/moment.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue