This repository has been archived by the owner on Feb 12, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated templates to be more legible
- Loading branch information
Showing
13 changed files
with
205 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
{{^useJQuery}} | ||
define(function () { | ||
{{#useJQuery}} | ||
{{/useJQuery}}{{#useJQuery}} | ||
define(['jquery'], function ($) { | ||
{{/useJQuery}} | ||
|
||
<%= content %> | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
{{^useJQuery}} | ||
define(function () { | ||
{{/useJQuery}} | ||
{{#useJQuery}} | ||
(function () { | ||
{{/useJQuery}}{{#useJQuery}} | ||
(function ($) { | ||
{{/useJQuery}} | ||
|
||
<%= content %> | ||
|
||
{{^useJQuery}} | ||
)()); | ||
{{/useJQuery}} | ||
{{#useJQuery}} | ||
)(jQuery)); | ||
}()); | ||
{{/useJQuery}}{{#useJQuery}} | ||
}(jQuery)); | ||
{{/useJQuery}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,162 @@ | ||
define(function () { | ||
(function () { | ||
|
||
{%- content %} | ||
// jQuery flavored settings for Builder | ||
var settings = { | ||
'template engine': function (tmpl) { | ||
return tmpl; | ||
}, | ||
'dom engine': function (content) { | ||
return $(content); | ||
} | ||
}; | ||
|
||
)()); | ||
// Create storage for before and after functions | ||
var beforeFns = [], | ||
afterFns = []; | ||
|
||
/** | ||
* Build chain for client side views. before -> template -> domify -> after -> return | ||
* @param {String} tmpl Template to process through template engine | ||
* @param {Object} [data] Data to pass through to template engine | ||
* @returns {Mixed} Output from before -> template -> domify -> after -> return | ||
*/ | ||
function Builder(tmpl, data) { | ||
// Generate a this context for data | ||
var that = {'data': data}; | ||
|
||
// Run the beforeFns on tmpl | ||
tmpl = pre.call(that, tmpl); | ||
|
||
// Convert the template into content | ||
var content = template.call(that, tmpl, data); | ||
|
||
// Pass the template through the dom engine | ||
var $content = domify.call(that, content); | ||
|
||
// Run the afterFns on $content | ||
$content = post.call(that, $content); | ||
|
||
// Return the $content | ||
return $content; | ||
} | ||
|
||
/** | ||
* Modify tmpl via beforeFns | ||
* @param {String} tmpl Template string to modify | ||
* @returns {String} Modified tmpl | ||
*/ | ||
function pre(tmpl) { | ||
// Iterate over the beforeFns | ||
var i = 0, | ||
len = beforeFns.length; | ||
for (; i < len; i++) { | ||
tmpl = beforeFns[i].call(this, tmpl) || tmpl; | ||
} | ||
|
||
// Return tmpl | ||
return tmpl; | ||
} | ||
Builder.pre = pre; | ||
Builder.beforeFns = beforeFns; | ||
|
||
/** | ||
* Parse template through its engine | ||
* @param {String} tmpl Template to process through template engine | ||
* @param {Object} [data] Data to pass through to template engine | ||
*/ | ||
function template(tmpl, data) { | ||
// Grab the template engine | ||
var engine = settings['template engine']; | ||
|
||
// Process the template through the template engine | ||
var content = engine.call(this, tmpl, data); | ||
|
||
// Return the content | ||
return content; | ||
} | ||
Builder.template = template; | ||
|
||
/** | ||
* Convert HTML into HTMLElements, jQuery elements, or other | ||
* @param {String} content HTML to pass through dom engine | ||
*/ | ||
function domify(content) { | ||
// Grab the dom engine | ||
var engine = settings['dom engine']; | ||
|
||
// Process the content through the dom engine | ||
var $content = engine.call(this, content); | ||
|
||
// Return the $content | ||
return $content; | ||
} | ||
Builder.domify = domify; | ||
|
||
/** | ||
* Modify $content via afterFns | ||
* @param {String} $content Content to modify | ||
* @returns {String} Modified $content | ||
*/ | ||
function post($content) { | ||
// Iterate over the afterFns | ||
var i = 0, | ||
len = afterFns.length; | ||
for (; i < len; i++) { | ||
$content = afterFns[i].call(this, $content) || $content; | ||
} | ||
|
||
// Return tmpl | ||
return $content; | ||
} | ||
Builder.post = post; | ||
Builder.afterFns = afterFns; | ||
|
||
/** | ||
* Settings helper for Builder | ||
* @param {String|Object} name If object, interpret as key-value pairs of settings. If string, save val under settings key. | ||
* @param {Mixed} [val] Value to save under name | ||
*/ | ||
function set(name, val) { | ||
// If the name is an object | ||
var key; | ||
if (typeof name === 'object') { | ||
// Iterate over its properties | ||
for (key in name) { | ||
if (name.hasOwnProperty(key)) { | ||
// Set each one | ||
set(key, name[key]); | ||
} | ||
} | ||
} else { | ||
// Otherwise, save to settings | ||
settings[name] = val; | ||
} | ||
} | ||
Builder.set = set; | ||
Builder.settings = settings; | ||
|
||
/** | ||
* Helper method for saving new before methods | ||
* @param {Function} fn Before method to add | ||
*/ | ||
function before(fn) { | ||
beforeFns.push(fn); | ||
} | ||
Builder.before = before; | ||
|
||
/** | ||
* Helper method for saving new after methods | ||
* @param {Function} fn After method to add | ||
*/ | ||
function after(fn) { | ||
afterFns.push(fn); | ||
} | ||
Builder.after = after; | ||
|
||
// TODO: Inside of README, leave notes about this.data | ||
|
||
|
||
|
||
return Builder; | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters