Skip to content
Browse files

Add a helper system for templates

  • Loading branch information...
1 parent d845edd commit 017167c6b6d9b62bdfd47a2402af173e5e3246c6 @chewbranca chewbranca committed
Showing with 43 additions and 1 deletion.
  1. +8 −1 src/fauxton/app/app.js
  2. +35 −0 src/fauxton/app/helpers.js
View
9 src/fauxton/app/app.js
@@ -4,11 +4,13 @@ define([
"lodash",
"backbone",
+ "helpers",
+
// Plugins.
"plugins/backbone.layoutmanager"
],
-function($, _, Backbone) {
+function($, _, Backbone, Helpers) {
// Provide a global location to place configuration settings and module
// creation.
@@ -27,6 +29,11 @@ function($, _, Backbone) {
prefix: "app/",
+ // Inject app/helper.js for shared functionality across all html templates
+ render: function(template, context) {
+ return template(_.extend(Helpers, context));
+ },
+
fetch: function(path) {
// Initialize done for use in async-mode
var done;
View
35 src/fauxton/app/helpers.js
@@ -0,0 +1,35 @@
+// 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.
+
+
+// This file creates a set of helper functions that will be loaded for all html
+// templates. These functions should be self contained and not rely on any
+// external dependencies as they are loaded prior to the application. We may
+// want to change this later, but for now this should be thought of as a
+// "purely functional" helper system.
+
+
+define([
+],
+
+function() {
+
+ var Helpers = {};
+
+ Helpers.imageUrl = function(path) {
+ // TODO: add dynamic path for different deploy targets
+ return path;
+ };
+
+ return Helpers;
+});
+

0 comments on commit 017167c

Please sign in to comment.
Something went wrong with that request. Please try again.