summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-09-06 02:22:28 -0400
committerJules Laplace <jules@okfoc.us>2015-09-06 02:22:28 -0400
commit8e25a37aced0399ad13e2c184c618119ec3da16d (patch)
treefea00aa951b5468e886e15a26774a7ea7da1d737
parentf936c30cbcf9c5e1e5e77929f37a28603ab7c73a (diff)
beginning to port string formatting code..
-rw-r--r--lib/index.js11
-rw-r--r--public/assets/js/lib/views/index/threadbox.js47
-rw-r--r--public/assets/js/util/format.js86
-rw-r--r--views/pages/index.ejs28
4 files changed, 171 insertions, 1 deletions
diff --git a/lib/index.js b/lib/index.js
index 45def38..2ccf812 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -96,7 +96,6 @@ site.route = function(){
})
}
)
-
app.get("/api/thread/:id", function(req, res){
bucky.ensureThread,
bucky.ensureKeywordForThread,
@@ -113,4 +112,14 @@ site.route = function(){
})
app.post("/api/thread/:id", function(req, res){
})
+ app.post("/api/thread/:id/comment", function(req, res){
+ })
+ app.delete("/api/thread/:id", function(req, res){
+ })
+
+ app.put("/api/comment/:id", function(req, res){
+ })
+ app.delete("/api/thread/:id", function(req, res){
+ })
+
}
diff --git a/public/assets/js/lib/views/index/threadbox.js b/public/assets/js/lib/views/index/threadbox.js
new file mode 100644
index 0000000..951b025
--- /dev/null
+++ b/public/assets/js/lib/views/index/threadbox.js
@@ -0,0 +1,47 @@
+/*
+age_class
+views_class
+comments_class
+size_class
+files_class
+*/
+
+var ThreadBox = View.extend({
+ el: ".threads",
+
+ events: {
+ },
+
+ initialize: function(){
+ this.__super__.initialize.call(this)
+ this.template = this.$(".template").html()
+ },
+
+ load: function(comments){
+ comments.forEach(this.appendComment.bind(this))
+ },
+
+ parse: function(thread){
+ var t = this.template
+ .replace(/{{id}}/g, thread.id)
+ .replace(/{{username}}/g, thread.username)
+ .replace(/{{title}}/g, thread.title)
+ .replace(/{{age}}/g, get_age(thread.lastmodified) )
+ .replace(/{{views}}/g, thread.views + " v.")
+ .replace(/{{comments}}/g, thread.comments + " c.")
+ .replace(/{{files}}/g, thread.files + " c.")
+ .replace(/{{size}}/g, get_size(thread.size) )
+ return t
+ },
+
+ prependComment: function(comment){
+ var $el = $( this.parse(comment) )
+ this.$hoots.prepend($el)
+ },
+
+ appendComment: function(comment){
+ var $el = $( this.parse(comment) )
+ this.$hoots.append($el)
+ },
+
+})
diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js
new file mode 100644
index 0000000..21b1f68
--- /dev/null
+++ b/public/assets/js/util/format.js
@@ -0,0 +1,86 @@
+function commatize (n) {
+ var nums, i, counter = 0
+ if (n > 1024) {
+ n /= 1024;
+ nums.unshift((n * 10) % 10)
+ nums.unshift(".")
+ }
+
+ do {
+ i = n % 10
+ n = Math.floor(number / 10)
+ if (n && !(++counter % 3))
+ { i = ' ' + i }
+ nums.unshift(i)
+ }
+ while (n);
+
+ return nums.join("")
+}
+function get_age (d){
+}
+function get_size (d){
+}
+function carbon_date (date, no_bold) {
+ var span = (+new Date() - date * 1000);
+ if (! no_bold && span < 86400) // modified today
+ { color = "new"; }
+ else if (span < 604800) // modifed this week
+ { color = "recent"; }
+ else if (span < 1209600) // modifed 2 weeks ago
+ { color = "med"; }
+ else if (span < 3024000) // modifed 5 weeks ago
+ { color = "old"; }
+ else if (span < 12315200) // modifed 6 months ago
+ { color = "older"; }
+ else
+ { color = "quiet"; }
+ return color;
+}
+
+function hushview (n, bias, no_bold) {
+ var txt = commatize(n)
+ bias = bias || 1
+ n = n || 0
+ if (n < 30) {
+ n = 0 if (!n); return["quiet", n + " v."] }
+ if (n < 200) {
+ return ["quiet", txt + " v."] }
+ else if (n < 500) {
+ return ["quiet", txt + " v."] }
+ else if (n < 1000) {
+ return ["old", txt + " v."] }
+ else if (n < 5000) {
+ return ["med", txt + " kv."] }
+ else if (nobold || n < 10000) {
+ return ["recent", txt + " kv."] }
+ else {
+ return ["new", txt + " kv."] }
+}
+
+function hushsize (n, bias, nobold) {
+ var txt = commatize(n / 1024)
+ bias = 1 || bias
+ n = n || 0
+ if (n < 1024) {
+ return ["quiet", "0 b."]
+ }
+ if (n < 1024*1024) {
+ return ["quiet", txt + " kb."]
+ }
+ else if (n < (20000000/bias)) {
+ return ["quiet", txt + " mb."]
+ }
+ else if (n < (50000000/bias)) {
+ return ["old", txt + " mb."]
+ }
+ else if (n < (80000000/bias)) {
+ return ["med", txt + " mb."]
+ }
+ else if (nobold || n < (170000000/bias)) {
+ return ["recent", txt + " mb."]
+ }
+ else {
+ return ["new", txt + " mb."]
+ }
+}
diff --git a/views/pages/index.ejs b/views/pages/index.ejs
index 3b5e0f9..b6a8a5f 100644
--- a/views/pages/index.ejs
+++ b/views/pages/index.ejs
@@ -31,6 +31,34 @@
</div>
<div id="content">
+
+ <table class="threads">
+ <script class="template" type="text/html">
+ <tr>
+ <td>
+ <a href="/profile/{{username}}">{{username}}</a>
+ {{privacy_dot}}
+ </td>
+ <td>
+ <a href="/details/{{id}}">{{title}}</a>
+ </td>
+ <td class="{{age_class}}">
+ {{age}}
+ </td>
+ <td class="{{views_class}}">
+ {{views}}
+ </td>
+ <td class="{{comments_class}}">
+ {{comments}}
+ </td>
+ <td>
+ <span class="{{size_class}}">{{size}}</span>
+ in
+ <span class="{{files_class}}">{{files}}</span>
+ </td>
+ </tr>
+ </script>
+ </table>
</div>
<% include ../partials/footer %>