Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

began cleanup for more flexibility

  • Loading branch information...
commit 1e525b3b95a10fa6aaef634f85734861b50149f0 1 parent a89a4de
@jimfleming jimfleming authored
Showing with 47 additions and 168 deletions.
  1. +1 −0  .gitignore
  2. +18 −24 index.html
  3. +9 −62 server.coffee
  4. +11 −74 server.js
  5. +8 −8 styles.css
View
1  .gitignore
@@ -1 +1,2 @@
*.rdb
+*.swp
View
42 index.html
@@ -16,41 +16,35 @@
<script type="text/template" id="key-template">
<li>
- <a href="#<%= command %> <%= reply %><% if (command === 'LRANGE') { %> 0 -1<% } %><% if (command === 'ZRANGE') { %> 0 -1 WITHSCORES<% } %>"><%= reply %></a>
- <span><%= type %></span>
- <a href='#DEL <%= reply %>' class="confirm">[DEL?]</a>
+ <pre class="val"><a href="#<%= command %> <%= reply %><% if (command === 'LRANGE') { %> 0 -1<% } %><% if (command === 'ZRANGE') { %> 0 -1 WITHSCORES<% } %>"><%= reply %></a></pre>
+ <div class="type"><%= type %></div>
</li>
</script>
<script type="text/template" id="string-template">
<li>
- <pre><%= reply %></pre>
- <br />
- <a href='#KEYS *'>[KEYS *]</a>
+ <pre class="val"><%= reply %></pre>
</li>
</script>
<script type="text/template" id="hash-template">
- <li>
- <% _.each(reply, function(val, key) { %>
- <div class="hash-row"><div class="hash-key"><%= key %>:</div> <pre class="hash-val"><%= val %></pre></div>
- <% }); %>
- <a href='#KEYS *'>[KEYS *]</a>
- </li>
+ <% _.each(reply, function(val, key) { %>
+ <li>
+ <div class="key"><%= key %>:</div> <pre class="val"><%= val %></pre>
+ </li>
+ <% }); %>
</script>
<script type="text/template" id="list-template">
- <li>
- <% _.each(reply, function(val, key) { %>
- <div class="hash-row"><div class="hash-key"><%= key %>:</div> <pre class="hash-val"><%= val %></pre></div>
- <% }); %>
- <a href='#KEYS *'>[KEYS *]</a>
- </li>
+ <% _.each(reply, function(val, key) { %>
+ <li>
+ <div class="key"><%= key %>:</div> <pre class="val"><%= val %></pre>
+ </li>
+ <% }); %>
</script>
<script type="text/template" id="set-template">
- <li>
- <% _.each(reply, function(val, key) { %>
- <div class="hash-row"><div class="hash-key"><%= key %>:</div> <pre class="hash-val"><%= val %></pre></div>
- <% }); %>
- <a href='#KEYS *'>[KEYS *]</a>
- </li>
+ <% _.each(reply, function(val, key) { %>
+ <li>
+ <div class="key"><%= key %>:</div> <pre class="val"><%= val %></pre>
+ </li>
+ <% }); %>
</script>
</head>
View
71 server.coffee
@@ -3,7 +3,12 @@ redis = require('redis')
io = require('socket.io')
_ = require('underscore')
commands = require('./commands')
+format_json = require('./format_json')
+_.each commands, (val, key) ->
+ console.log key
+
+redis.debug_mode = true
redis_client = redis.createClient()
redis_client.on 'error', (error) ->
@@ -20,78 +25,20 @@ socket = io.listen(app)
# map the command to the type of data it'll return
reply_types =
- 'KEYS': 'key'
- 'GET': 'string'
+ 'KEYS': 'keys'
'HGETALL': 'hash'
- 'DEL': 'string'
- 'SET': 'string'
- 'HSET': 'string'
'LRANGE': 'list'
'SMEMBERS': 'set'
'ZRANGE': 'zset'
+ 'ZADD': 'integer'
-command_map =
+key_command_map =
'string': 'GET'
'hash': 'HGETALL'
'list': 'LRANGE'
'set': 'SMEMBERS'
'zset': 'ZRANGE'
-format_json = (data, indent = '') ->
- return "\"#{data}\"" if _.isString(data)
-
- try
- data = JSON.parse(data)
-
- return '(nil)' if _.isNull(data)
-
- return data if _.isNumber(data)
-
- next_indent = ' '
-
- is_array = _.isArray(data)
-
- if is_array
- if data.length is 0
- return '[]'
- else
- closing_brace = ']'
- html = '['
- else
- if _.size(data) is 0
- return '{}'
- else
- closing_brace = '}'
- html = '{'
-
- i = 0
-
- _.each data, (val, key) ->
- html += ', ' if i > 0
-
- if is_array
- html += '\n' + indent + next_indent
- else
- html += '\n' + indent + next_indent + '<strong>\"' + key + '\":</strong> '
-
- switch typeof val
- when 'object'
- html += format_json(val, indent + next_indent)
- when 'string'
- html += '\"' + JSON.stringify(val).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\"'
- when 'number'
- html += JSON.stringify(val)
- when 'boolean'
- html += JSON.stringify(val)
- else
- html += '\"' + JSON.stringify(val) + '\"'
-
- i++
-
- html += '\n' + indent + closing_brace
-
- return html
-
socket.on 'connection', (client) ->
client.on 'message', (message) ->
@@ -113,7 +60,7 @@ socket.on 'connection', (client) ->
reply: key
type: type
title: message
- command: command_map[type]
+ command: key_command_map[type]
reply_type: reply_type
return
else
View
85 server.js
@@ -1,10 +1,15 @@
(function() {
- var app, command_map, commands, express, format_json, io, redis, redis_client, reply_types, socket, _;
+ var app, commands, express, format_json, io, key_command_map, redis, redis_client, reply_types, socket, _;
express = require('express');
redis = require('redis');
io = require('socket.io');
_ = require('underscore');
commands = require('./commands');
+ format_json = require('./format_json');
+ _.each(commands, function(val, key) {
+ return console.log(key);
+ });
+ redis.debug_mode = true;
redis_client = redis.createClient();
redis_client.on('error', function(error) {
return console.log(error);
@@ -18,88 +23,20 @@
console.log('listening on :3000');
socket = io.listen(app);
reply_types = {
- 'KEYS': 'key',
- 'GET': 'string',
+ 'KEYS': 'keys',
'HGETALL': 'hash',
- 'DEL': 'string',
- 'SET': 'string',
- 'HSET': 'string',
'LRANGE': 'list',
'SMEMBERS': 'set',
- 'ZRANGE': 'zset'
+ 'ZRANGE': 'zset',
+ 'ZADD': 'integer'
};
- command_map = {
+ key_command_map = {
'string': 'GET',
'hash': 'HGETALL',
'list': 'LRANGE',
'set': 'SMEMBERS',
'zset': 'ZRANGE'
};
- format_json = function(data, indent) {
- var closing_brace, html, i, is_array, next_indent;
- if (indent == null) {
- indent = '';
- }
- if (_.isString(data)) {
- return "\"" + data + "\"";
- }
- try {
- data = JSON.parse(data);
- } catch (_e) {}
- if (_.isNull(data)) {
- return '(nil)';
- }
- if (_.isNumber(data)) {
- return data;
- }
- next_indent = ' ';
- is_array = _.isArray(data);
- if (is_array) {
- if (data.length === 0) {
- return '[]';
- } else {
- closing_brace = ']';
- html = '[';
- }
- } else {
- if (_.size(data) === 0) {
- return '{}';
- } else {
- closing_brace = '}';
- html = '{';
- }
- }
- i = 0;
- _.each(data, function(val, key) {
- if (i > 0) {
- html += ', ';
- }
- if (is_array) {
- html += '\n' + indent + next_indent;
- } else {
- html += '\n' + indent + next_indent + '<strong>\"' + key + '\":</strong> ';
- }
- switch (typeof val) {
- case 'object':
- html += format_json(val, indent + next_indent);
- break;
- case 'string':
- html += '\"' + JSON.stringify(val).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\"';
- break;
- case 'number':
- html += JSON.stringify(val);
- break;
- case 'boolean':
- html += JSON.stringify(val);
- break;
- default:
- html += '\"' + JSON.stringify(val) + '\"';
- }
- return i++;
- });
- html += '\n' + indent + closing_brace;
- return html;
- };
socket.on('connection', function(client) {
client.on('message', function(message) {
var args, command;
@@ -121,7 +58,7 @@
reply: key,
type: type,
title: message,
- command: command_map[type],
+ command: key_command_map[type],
reply_type: reply_type
});
});
View
16 styles.css
@@ -54,10 +54,10 @@ ul#results {
ul#results li {
margin: 0 0 10px;
background: #fafafa;
- display: block;
padding: 10px;
border-radius: 5px;
box-shadow: 1px 1px 5px rgba(0,0,0,0.1);
+ overflow: hidden;
}
ul#results li a {
text-shadow: 1px 1px 0 #f0f0f0;
@@ -72,19 +72,19 @@ pre {
font-family: Menlo, Monaco, Consolas, monospace;
margin: 0;
}
-.hash-row {
- overflow: hidden;
- padding: 0 0 10px;
- margin: 0 0 10px;
- border-bottom: 1px solid #eee;
+.type {
+ float: left;
+ margin: 0 0 0 10px;
+ padding: 11px 0 0;
+ font-size: 10px;
}
-.hash-key {
+.key {
font-weight: bold;
float: left;
margin: 0 10px 0 0;
padding: 11px 0 0;
}
-.hash-val {
+.val {
float: left;
}
pre {
Please sign in to comment.
Something went wrong with that request. Please try again.