Making module system more flexible to accept wrapping divs

This commit is contained in:
Sacha Greif 2015-04-24 10:22:17 +09:00
parent 36e2d063ce
commit 7770c21d3a
14 changed files with 72 additions and 58 deletions

View file

@ -1,5 +1,13 @@
<template name="modules">
{{#each getModules}}
{{> Template.dynamic template=template data=../..}}
{{/each}}
{{#if hasWrapper}}
{{#each getModules}}
<div class="{{wrapperClass}}">
{{> Template.dynamic template=template data=../..}}
</div>
{{/each}}
{{else}}
{{#each getModules}}
{{> Template.dynamic template=template data=../..}}
{{/each}}
{{/if}}
</template>

View file

@ -1,6 +1,15 @@
Template.modules.helpers({
hasWrapper: function () {
return !!this.moduleClass; // only add a wrapper if a class has been specified
},
wrapperClass: function () {
var zone = Template.parentData(1);
var module = this;
return Telescope.utils.camelToDash(module.template) + " " + zone.moduleClass;
},
getModules: function () {
var zone = this.toString();
// look for the zone name in either the zone variable, or the data context itself
var zone = this.zone || this.toString();
return Telescope.modules.get(zone);
}
});

View file

@ -2,11 +2,9 @@
<div class="mobile-nav">
<div class="mobile-nav-inner">
<ul class="mobile-menu">
{{#each mobileNav}}
<li>
{{> Template.dynamic template=template data=mobileContext}}
</li>
{{/each}}
{{#with mobileContext}}
{{> modules zone="mobileNav" moduleClass="mobile-menu-item"}}
{{/with}}
</ul>
</div>
</div>

View file

@ -1,7 +1,4 @@
Template.mobile_nav.helpers({
mobileNav: function () {
return _.sortBy(Telescope.config.mobileNav, 'order');
},
mobileContext: function () {
return {mobile: true};
}

View file

@ -7,21 +7,17 @@
{{> logo}}
{{#with primaryNav}}
{{#if hasPrimaryNav}}
<div class="nav primary-nav desktop-nav header-module desktop-only">
{{#each this}}
{{> Template.dynamic template=template}}
{{/each}}
{{> modules "primaryNav"}}
</div>
{{/with}}
{{/if}}
{{#with secondaryNav}}
{{#if hasSecondaryNav}}
<div class="nav secondary-nav desktop-nav header-module desktop-only">
{{#each this}}
{{> Template.dynamic template=template}}
{{/each}}
{{> modules "secondaryNav"}}
</div>
{{/with}}
{{/if}}
</header>
</template>

View file

@ -15,17 +15,11 @@ Template.nav.helpers({
}
return headerClass;
},
primaryNav: function () {
return _.sortBy(Telescope.config.primaryNav, 'order');
},
hasPrimaryNav: function () {
return !!Telescope.config.primaryNav.length;
},
secondaryNav: function () {
return _.sortBy(Telescope.config.secondaryNav, 'order');
return !!Telescope.modules.get("primaryNav").length;
},
hasSecondaryNav: function () {
return !!Telescope.config.secondaryNav.length;
return !!Telescope.modules.get("secondaryNav").length;
},
dropdownClass: function () {
var dropdownClass = "";

View file

@ -0,0 +1,31 @@
// array containing nav items;
Telescope.modules.register("secondaryNav", [
{
template: 'userMenu',
order: 10
},
{
template:'notificationsMenu',
order: 20
},
{
template: 'submitButton',
order: 30
}
]);
Telescope.modules.register("mobileNav", [
{
template: 'userMenu',
order: 10
},
{
template:'notificationsMenu',
order: 20
},
{
template: 'submitButton',
order: 30
}
]);

View file

@ -38,8 +38,9 @@ Package.onUse(function(api) {
'lib/router/filters.js',
'lib/router/admin.js',
'lib/router/server.js',
'lib/vote.js',
'lib/config.js'
'lib/config.js',
'lib/modules.js',
'lib/vote.js'
], ['client', 'server']);
api.addFiles([

View file

@ -1,9 +1,5 @@
<template name="post_item">
<div class="post {{#if sticky}}sticky{{/if}} {{inactiveClass}} {{postClass}}" id="{{_id}}">
{{#each postComponents}}
<div class="{{moduleClass}}">
{{> Template.dynamic template=template data=..}}
</div>
{{/each}}
{{> modules zone="postComponents" moduleClass="post-module"}}
</div>
</template>

View file

@ -5,25 +5,16 @@ Template.post_item.created = function () {
};
Template.post_item.helpers({
postComponents: function () {
return Telescope.modules.get("postComponents");
},
moduleContext: function () { // not used for now
var module = this;
module.templateClass = Telescope.utils.camelToDash(this.template) + ' ' + this.position + ' cell';
module.post = post;
return module;
},
moduleClass: function () {
return Telescope.utils.camelToDash(this.template) + ' post-module';
},
postClass: function () {
var post = this;
var postAuthorClass = "author-"+post.author;
var postClass = Telescope.callbacks.run("postClass", postAuthorClass);
return postClass;
}
});

View file

@ -1,15 +1,15 @@
// push "search" template to primaryNav
Telescope.config.primaryNav.push({
Telescope.modules.register("primaryNav", {
template: 'search',
order: 100
});
Telescope.config.mobileNav.push({
Telescope.modules.register("mobileNav", {
template: 'search',
order: 1
});
Telescope.config.adminMenu.push({
Telescope.modules.register("adminMenu", {
route: 'searchLogs',
label: 'search_logs',
description: 'see_what_people_are_searching_for'

View file

@ -83,7 +83,7 @@ $mobile-nav-width: 200px;
display: block;
margin-right: 0px;
}
>li{
.mobile-menu-item{
margin-bottom: 0;
border-bottom:1px white(0.2) solid;
&:last-child{

View file

@ -1,7 +1,5 @@
<template name="user_edit">
{{#with user}}
{{#each userProfileEdit}}
{{> Template.dynamic template=template data=..}}
{{/each}}
{{> modules "profileEdit"}}
{{/with}}
</template>

View file

@ -1,5 +0,0 @@
Template.user_edit.helpers({
userProfileEdit: function () {
return userProfileEdit;
}
});