Add a t5/core/moment wrapper around moment, to set the lang to match the document
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/56c87d11 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/56c87d11 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/56c87d11 Branch: refs/heads/master Commit: 56c87d11ccca0a14afb2e38cef45ae28b49f2d12 Parents: 61990a7 Author: Howard M. Lewis Ship <[email protected]> Authored: Thu Dec 5 10:26:38 2013 -0800 Committer: Howard M. Lewis Ship <[email protected]> Committed: Thu Dec 5 10:26:38 2013 -0800 ---------------------------------------------------------------------- .../META-INF/modules/t5/core/localdate.coffee | 2 +- .../META-INF/modules/t5/core/moment.coffee | 25 ++++++++++++++++++++ tapestry-core/src/test/app1/LocalDateDemo.tml | 6 +++++ .../integration/app1/pages/LocalDateDemo.groovy | 13 ++++++++++ .../activationctx/services/AppModule.java | 2 +- 5 files changed, 46 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56c87d11/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/localdate.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/localdate.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/localdate.coffee index 136ce26..93f932f 100644 --- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/localdate.coffee +++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/localdate.coffee @@ -17,7 +17,7 @@ # Used with the LocalDate component to present a Date in a particular format, in the # browser's time zone. -define ["./dom", "moment"], +define ["./dom", "./moment"], (dom, moment) -> ATTR = "data-localdate-format" http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56c87d11/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/moment.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/moment.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/moment.coffee new file mode 100644 index 0000000..eeff51d --- /dev/null +++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/moment.coffee @@ -0,0 +1,25 @@ +# Copyright 2013 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http:#www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# ## t5/core/moment +# +# A wrapper around Moment.js; this simply initializes Moment to +# use the correct locale (as per the data-locale attribute of the document element). +define ["moment"], +(moment) -> + locale = (document.documentElement.getAttribute "data-locale") or "en" + + moment.lang(locale) + + return moment \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56c87d11/tapestry-core/src/test/app1/LocalDateDemo.tml ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/app1/LocalDateDemo.tml b/tapestry-core/src/test/app1/LocalDateDemo.tml index 26d7eca..2edf414 100644 --- a/tapestry-core/src/test/app1/LocalDateDemo.tml +++ b/tapestry-core/src/test/app1/LocalDateDemo.tml @@ -13,5 +13,11 @@ </t:localdate> </p> + + <div class="btn-toolbar"> + <t:actionlink t:id="english" class="btn btn-default">English</t:actionlink> + <t:actionlink t:id="french" class="btn btn-default">French</t:actionlink> + </div> + </html> http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56c87d11/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/pages/LocalDateDemo.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/pages/LocalDateDemo.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/pages/LocalDateDemo.groovy index 1959caf..c019ca4 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/pages/LocalDateDemo.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/pages/LocalDateDemo.groovy @@ -1,11 +1,24 @@ package org.apache.tapestry5.integration.app1.pages import org.apache.tapestry5.annotations.Cached +import org.apache.tapestry5.ioc.annotations.Inject +import org.apache.tapestry5.services.PersistentLocale class LocalDateDemo { + @Inject + PersistentLocale persistentLocale + @Cached Date getNow() { new Date() } + + void onActionFromFrench() { + persistentLocale.set Locale.FRENCH + } + + void onActionFromEnglish() { + persistentLocale.set Locale.ENGLISH + } } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56c87d11/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/services/AppModule.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/services/AppModule.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/services/AppModule.java index 4d4541a..ca1e777 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/services/AppModule.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/activationctx/services/AppModule.java @@ -24,7 +24,7 @@ public class AppModule { public static void contributeApplicationDefaults(MappedConfiguration<String, String> configuration) { - configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en"); + configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en,fr"); configuration.add(SymbolConstants.PRODUCTION_MODE, "false"); } }
