caveat_patch_kids 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -37,6 +37,7 @@ These scripts are provided by CaveatPatchKids. Include them by updating ~/.cavea
37
37
 
38
38
  * caveat_patch_kids/display_avatars: display a [Gravatar](http://www.gravatar.com/) next to a user's name
39
39
  * caveat_patch_kids/display_cloudapp_images: display [CloudApp](http://getcloudapp.com/) images inline
40
+ * caveat_patch_kids/display_librato: adjust [librato](https://metrics.librato.com/) graph links to embed a live version of the graph
40
41
  * caveat_patch_kids/display_scout: display [Scout](https://scoutapp.com/) graph links as embeded graphs
41
42
  * caveat_patch_kids/embiggen_message_history: increase message history
42
43
  * caveat_patch_kids/stylize_diffs: colorize diffs with red/green
@@ -1,3 +1,3 @@
1
1
  module CaveatPatchKids
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -2,6 +2,7 @@
2
2
  //
3
3
  //= require caveat_patch_kids/display_avatars
4
4
  //= require caveat_patch_kids/display_cloudapp_images
5
+ //= require caveat_patch_kids/display_librato
5
6
  //= require caveat_patch_kids/display_scout
6
7
  //= require caveat_patch_kids/embiggen_message_history
7
8
  //= require caveat_patch_kids/stylize_nagios
@@ -0,0 +1,107 @@
1
+ // Propane extension to expand Librato instrument links
2
+ // v0.0.1
3
+
4
+ Campfire.LibratoExpander = Class.create({
5
+ initialize: function(chat) {
6
+ this.chat = chat;
7
+ var messages = this.chat.transcript.messages;
8
+ for (var i = 0; i < messages.length; i++) {
9
+ this.detectLibratoURL(messages[i]);
10
+ }
11
+ this.chat.windowmanager.scrollToBottom();
12
+ },
13
+
14
+ detectLibratoURL: function(message) {
15
+ if (!message.pending() && message.kind === 'text') {
16
+ var height = 400;
17
+
18
+ //var logs = message.bodyElement().select('a[href*="0.0.0.0:3000"]');
19
+ var logs = message.bodyElement().select('a[href*="metrics.librato.com"]');
20
+
21
+ // Bail unless there are logs
22
+ if (logs.length != 1) {
23
+ return;
24
+ }
25
+
26
+ // determine if this is a librato URL and parse out necessary
27
+ var elem = logs[0];
28
+ var href = elem.getAttribute('href');
29
+
30
+ //var regex = /^http:\/\/0.0.0.0:3000\/instruments\/(\d+)(\?.*)?$/;
31
+ var regex = /^https:\/\/metrics.librato.com\/instruments\/(\d+)(\?.*)?$/;
32
+ var match = href.match(regex);
33
+
34
+ // Bail unless there is a match
35
+ if (!match) {
36
+ return;
37
+ }
38
+
39
+ elem.onclick = (function(ev){
40
+ ev.preventDefault();
41
+
42
+ // Create the embed URL
43
+ var append_char = '?';
44
+ if (ev.target.href.match(/\?/) != null){
45
+ append_char = '&';
46
+ }
47
+
48
+ var embed_url = ev.target.href;
49
+
50
+ /// XXX: There's a bug in campfire, where URL's that end in '*'
51
+ // (e.g. https://metrics.librato.com/instruments/123?source=*foo*)
52
+ // get split into two elements, try to detect that and repair here.
53
+ //
54
+ // Have also been informed by 37S that this bug is currently
55
+ // not going to be fixed:
56
+ //
57
+ // "Right now, Campfire's URL detection isn't 100% perfect, so it breaks off at asterisks,
58
+ // like you noticed. When we tried updating that, overall Campfire
59
+ // performance went waaaaay down. Until we're able to fix this
60
+ // legitimately, I would recommend to use http://bitly.com to shorten
61
+ // your URLs."
62
+ // -37Signals Support
63
+ //
64
+ if(this.nextSibling != null) {
65
+ if (this.nextSibling.data == '*' || this.nextSibling.data == '=*') {
66
+ embed_url += this.nextSibling.data
67
+ }
68
+ }
69
+
70
+ embed_url = embed_url + append_char + "iframe=1";
71
+
72
+ var iframes = message.bodyElement().select('iframe');
73
+ if (iframes.length == 1) {
74
+ iframes[0].remove();
75
+ } else {
76
+ message.bodyElement().insert({bottom:"<iframe name='librato' style='border:0; margin-top: 5px;' height='"+height+"' width='98%' src='"+embed_url+"'></iframe>"});
77
+ setTimeout((function(message) {
78
+ return function() {
79
+ var iframes = message.bodyElement().select('iframe');
80
+ if (iframes.length == 1) {
81
+ iframes[0].remove();
82
+ message.bodyElement().insert({bottom:"<span> ... embed timed out.</span>"});
83
+ }
84
+ }
85
+ })(message), 1800000);
86
+ }
87
+ });
88
+ }
89
+ },
90
+
91
+ onMessagesInsertedBeforeDisplay: function(messages) {
92
+ var scrolledToBottom = this.chat.windowmanager.isScrolledToBottom();
93
+ for (var i = 0; i < messages.length; i++) {
94
+ this.detectLibratoURL(messages[i]);
95
+ }
96
+ if (scrolledToBottom) {
97
+ this.chat.windowmanager.scrollToBottom();
98
+ }
99
+ },
100
+
101
+ onMessageAccepted: function(message, messageID) {
102
+ this.detectLibratoURL(message);
103
+ }
104
+ });
105
+
106
+ Campfire.Responders.push("LibratoExpander");
107
+ window.chat.installPropaneResponder("LibratoExpander", "LibratoExpander");
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caveat_patch_kids
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -82,6 +82,7 @@ files:
82
82
  - scripts/caveat_patch_kids/display_avatars.js
83
83
  - scripts/caveat_patch_kids/display_cloudapp_images.js
84
84
  - scripts/caveat_patch_kids/display_githubs.js
85
+ - scripts/caveat_patch_kids/display_librato.js
85
86
  - scripts/caveat_patch_kids/display_scout.js
86
87
  - scripts/caveat_patch_kids/embed_youtube.js
87
88
  - scripts/caveat_patch_kids/embiggen_message_history.js