Permalink
Browse files

将菜谱的级别配置化

  • Loading branch information...
1 parent b2a563d commit 19af37dd7b2e3672faa17790940680cb4e4229c5 @dgunzi committed Oct 30, 2012
Showing with 30 additions and 18 deletions.
  1. +3 −1 app.js
  2. +6 −1 config/config.js
  3. +7 −6 views/cookbookwrite.html
  4. +14 −10 views/index.html
View
4 app.js
@@ -6,6 +6,7 @@ var express = require('express'),
routes = require('./routes'),
app = express(),
site = require('./config/config').site,
+ cookconfig = require('./config/config').cookbook,
ejs = require('ejs'),
path = require('path');
@@ -44,7 +45,8 @@ app.configure('production', function(){
//定义locals变量
app.locals({
config : config,
- site : site
+ site : site,
+ cookconfig : cookconfig
});
// Routes
View
@@ -25,4 +25,9 @@ exports.site = {
description: 'Homely Dishes,国内第一个兼容所有平台的美食,食谱,菜谱网。做你最喜爱的美食网,菜谱网。提供最人性化的菜谱大全,食谱家常菜,家常菜谱大全的美食网,让您为自己爱的人做一份美食,来吧!享受美食的乐趣.找家常菜谱。',
copyright: 'Copyright ©2011 - 2012 Homely Dishes版权所有 ',
version: '0.1',
-};
+};
+
+//cookbookconfig
+exports.cookbook = {
+ level: ["新手尝试","初级入门","初中水平","中级掌勺","高级厨师","厨神级"]
+};
View
@@ -86,12 +86,13 @@
<div class="controls">
<select id="clevel" name="level">
<option value="0">请选择</option>
- <option value="1" <%if(level == 1){%> selected = selected <%}%>>新手尝试</option>
- <option value="2" <%if(level == 2){%> selected = selected <%}%>>初级入门</option>
- <option value="3" <%if(level == 3){%> selected = selected <%}%>>初中水平</option>
- <option value="4" <%if(level == 4){%> selected = selected <%}%>>中级掌勺</option>
- <option value="5" <%if(level == 5){%> selected = selected <%}%>>高级厨师</option>
- <option value="6" <%if(level == 6){%> selected = selected <%}%>>厨神级</option>
+ <%
+ for (var item=0; item < cookconfig.level.length; item++){
+ %>
+ <option value="<%=item+1%>" <%if(level == item+1){%> selected = selected <%}%>><%=cookconfig.level[item]%></option>
+ <%
+ }
+ %>
</select>
</div>
</div>
View
@@ -2,30 +2,34 @@
<div class="container-fluid">
<div class="subnav">
<ul class="nav nav-pills">
- <li><a href="/">全部</a></li>
- <li><a href="/cookbook">新手尝试</a></li>
- <li><a href="/cookbook">初级入门</a></li>
- <li><a href="/cookbook">初中水平</a></li>
- <li><a href="/cookbook">中级掌勺</a></li>
- <li><a href="/cookbook">高级厨师</a></li>
- <li><a href="/cookbook">厨神级</a></li>
+ <li><a href="/">全部</a></li>
+ <%
+ for (var item=0; item < cookconfig.level.length; item++){
+ %>
+ <li><a href="/cookbook"><%=cookconfig.level[item]%></a></li>
+ <%
+ }
+ %>
</ul>
</div>
<div class="row-fluid">
<div class="span8">
- <% var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
-
+ <%
+ var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
+ var levelClass = ["","label-success","label-warning","label-important","label-info","label-inverse"];
for (var item = cookbooks.length - 1; item != -1 ; item -- ) {
var d = cookbooks[item].datetime;
var datetime = monthNames[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
+ var levelIndex = cookbooks[item].level-1;
+
%>
<section class="cookbookitem thumbnail">
<div class="page-header">
<h2><a href="/<%=cookbooks[item].url%>" target="_blank"><%=cookbooks[item].title %></a></h2>
<div class="info">
<span><i class="icon-user"></i>作者:<%- cookbooks[item].user %></span>
<span style="margin-left: 35px;"><i class="icon-calendar"></i>发表于:<small><%=datetime%></small></span>
- <span class="label label-warning fr">中级掌勺</span>
+ <span class="label <%=levelClass[levelIndex]%> fr"><%=cookconfig.level[levelIndex]%></span>
</div>
</div>
<div class="steps">

0 comments on commit 19af37d

Please sign in to comment.