Skip to content

Commit

Permalink
Merge pull request #448 from RocketChat/colors-2
Browse files Browse the repository at this point in the history
Process colors in messages
  • Loading branch information
rodrigok committed Aug 12, 2015
2 parents f62598d + d253f1e commit 6299f8e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ todda00:friendly-slugs
underscorestring:underscore.string
yasaricli:slugify
yasinuslu:blaze-meta
rocketchat:colors
1 change: 1 addition & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ reactive-var@1.0.5
reload@1.1.3
retry@1.0.3
rocketchat:autolinker@0.0.1
rocketchat:colors@0.0.1
rocketchat:emojione@0.0.1
rocketchat:favico@0.0.1
rocketchat:file@0.0.1
Expand Down
17 changes: 17 additions & 0 deletions packages/rocketchat-colors/client.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
###
# Colors is a named function that will process Colors
# @param {Object} message - The message object
###

class ColorsClient
constructor: (message) ->
if _.trim message.html
msg = message.html

msg = msg.replace /(?:^|\s|\n)(#[A-Fa-f0-9]{3}([A-Fa-f0-9]{3})?)\b/g, (match, completeColor) ->
return match.replace completeColor, "<div class=\"message-color\"><div class=\"message-color-sample\" style=\"background-color: #{completeColor}\"></div>#{completeColor.toUpperCase()}</div>"

message.html = msg
return message

RocketChat.callbacks.add 'renderMessage', ColorsClient, RocketChat.callbacks.priority.HIGH
22 changes: 22 additions & 0 deletions packages/rocketchat-colors/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Package.describe({
name: 'rocketchat:colors',
version: '0.0.1',
summary: 'Message pre-processor that will process colors',
git: ''
});

Package.onUse(function(api) {
api.versionsFrom('1.0');

api.use([
'coffeescript',
'rocketchat:lib@0.0.1'
]);

api.addFiles('client.coffee', 'client');
api.addFiles('style.css', 'client');
});

Package.onTest(function(api) {

});
16 changes: 16 additions & 0 deletions packages/rocketchat-colors/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.message-color {
display: inline-block;
font-weight: 100;
}

.message-color-sample {
width: 14px;
height: 14px;
display: inline-block;
border-radius: 3px;
margin-right: 3px;
margin-left: 2px;
border: 1px solid rgba(0,0,0,.2);
position: relative;
top: 2px;
}

0 comments on commit 6299f8e

Please sign in to comment.