Skip to content

Commit

Permalink
Merge branch 'master' of github.com:WardCunningham/Smallest-Federated…
Browse files Browse the repository at this point in the history
…-Wiki

Conflicts:
	client/client.js
	client/lib/legacy.coffee
  • Loading branch information
nrn committed Apr 24, 2012
2 parents 25d9455 + c09d3f7 commit bf7daef
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/client.js
Expand Up @@ -751,7 +751,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
wiki.addToJournal(pageElement.find('.journal'), { wiki.addToJournal(pageElement.find('.journal'), {
type: 'fork', type: 'fork',
site: site, site: site,
date: (new Date()).getTime() date: action.date
}); });
} }
if (wiki.useLocalStorage()) { if (wiki.useLocalStorage()) {
Expand Down
2 changes: 1 addition & 1 deletion client/lib/pageHandler.coffee
Expand Up @@ -77,7 +77,7 @@ pageHandler.put = (pageElement, action) ->
wiki.addToJournal pageElement.find('.journal'), wiki.addToJournal pageElement.find('.journal'),
type: 'fork' type: 'fork'
site: site site: site
date: (new Date()).getTime() date: action.date
if wiki.useLocalStorage() if wiki.useLocalStorage()
pushToLocal(pageElement, action) pushToLocal(pageElement, action)
pageElement.addClass("local") pageElement.addClass("local")
Expand Down
59 changes: 59 additions & 0 deletions client/plugins/method.coffee
@@ -0,0 +1,59 @@
window.plugins.method =
emit: (div, item) ->
bind: (div, item) ->
title = div.parents('.page:first').find('h1').text().trim()
data = wiki.getData()
throw "can't find data" unless data?
for row in data
input = row if row.Material == title
throw "can't find #{title} in data" unless input?

sum = (v) ->
_.reduce v, (s,n) -> s += n

avg = (v) ->
sum(v)/v.length

round = (n) ->
return '?' unless n?
if n.toString().match /\.\d\d\d/
n.toFixed 2
else
n

calculate = (item) ->
list = []
for line in item.text.split "\n"
color = '#eee'
value = comment = null
try
if input[line]?
value = input[line]
comment = input["#{line} Assumptions"] || null
else if line.match /^[0-9\.-]/
value = +line
else if line == 'SUM'
color = '#ddd'
[value, list] = [sum(list), []]
else if line == 'AVG'
color = '#ddd'
[value, list] = [avg(list), []]
else
color = '#edd'
catch err
color = '#edd'
value = null
comment = err.message

list.push +value if value? and ! isNaN +value

annotate = (text) ->
return '' unless text?
" <span title=\"#{text}\">*</span>"

"<tr style=\"background:#{color};\"><td style=\"width: 70%;\">#{line}#{annotate comment}<td><b>#{round value}</b>"

text = calculate(item).join "\n"
table = $(title+'<table style="width:100%; background:#eee; padding:.8em;"/>').html text
div.append table
div.dblclick -> wiki.textEditor div, item
78 changes: 78 additions & 0 deletions client/plugins/method.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/test/testclient.js
Expand Up @@ -778,7 +778,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
wiki.addToJournal(pageElement.find('.journal'), { wiki.addToJournal(pageElement.find('.journal'), {
type: 'fork', type: 'fork',
site: site, site: site,
date: (new Date()).getTime() date: action.date
}); });
} }
if (wiki.useLocalStorage()) { if (wiki.useLocalStorage()) {
Expand Down

0 comments on commit bf7daef

Please sign in to comment.