-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
116 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
define(function (require) { | ||
var $ = require('jquery'), | ||
t = require('template-cache'); | ||
|
||
var menu = ['About us', 'Offer', 'Contact']; | ||
|
||
var products = [ | ||
{ name: 'RequireJS', desc: 'Best AMD loader ever' }, | ||
{ name: 'r.js', desc: 'Best AMD optimizer ever' }, | ||
{ name: 'Almond', desc: 'AMD loader for production use' } | ||
]; | ||
|
||
return { | ||
appendToBody: function () { | ||
$('body').append(t('layout')()); | ||
$('.header').append(t('header')()); | ||
$('.footer').append(t('footer')()); | ||
$('.sidebar').append(t('menu')({ menu: menu })); | ||
$('.content').append(t('content')({ products: products })); | ||
} | ||
}; | ||
}); |
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,13 @@ | ||
require.config({}); | ||
require.config({ | ||
paths: { | ||
underscore: '../bower_components/underscore-amd/underscore', | ||
jquery: '../bower_components/jquery/jquery', | ||
text: '../bower_components/requirejs-text/text' | ||
} | ||
}); | ||
|
||
require([], function () { | ||
console.log('ready'); | ||
require(['jquery', 'main-view'], function ($, mainView) { | ||
$(function () { | ||
mainView.appendToBody(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
define(function (require) { | ||
var $ = require('jquery'), | ||
_ = require('underscore'), | ||
$body = $('body'), | ||
cache = {}, | ||
prefix = 'template-'; | ||
|
||
var templates = [ | ||
require('text!tpl/layout.html'), | ||
require('text!tpl/content.html'), | ||
require('text!tpl/menu.html') | ||
]; | ||
|
||
_.each(templates, function (markup) { | ||
$(markup).appendTo($body); | ||
}); | ||
|
||
return function (key) { | ||
var cacheKey = prefix + key, | ||
template = cache[cacheKey]; | ||
|
||
if (!template) { | ||
template = _.template($('#' + cacheKey).html()); | ||
cache[cacheKey] = template; | ||
} | ||
|
||
return template; | ||
}; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script id="template-content" type="text/template"> | ||
<h4>Our products:</h4> | ||
<% _.each(products, function (p) { %> | ||
<div> | ||
<p><strong><%= p.name %></strong></p> | ||
<p><%= p.desc %></p> | ||
</div> | ||
<% }) %> | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script id="template-layout" type="text/template"> | ||
<div class="container"> | ||
<div class="header"></div> | ||
<div class="sidebar"></div> | ||
<div class="content"></div> | ||
<div class="footer"></div> | ||
</div> | ||
</script> | ||
|
||
<script id="template-header" type="text/template"> | ||
<h2>Welcome to AMD inc</h2> | ||
<h3>Some catchy line!</h3> | ||
</script> | ||
|
||
<script id="template-footer" type="text/template"> | ||
<p>Copyright © 2013</p> | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script id="template-menu" type="text/template"> | ||
<h4>Main menu:</h4> | ||
<ul> | ||
<% _.each(menu, function (item) { %> | ||
<li><%= item %> | ||
<% }) %> | ||
</ul> | ||
</script> |
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