gitlab-peek 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +12 -0
  4. data/CHANGELOG.md +96 -0
  5. data/Gemfile +30 -0
  6. data/Gemfile-rails42 +27 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +253 -0
  9. data/Rakefile +13 -0
  10. data/app/assets/javascripts/peek.js +86 -0
  11. data/app/assets/javascripts/peek/vendor/jquery.tipsy.js +258 -0
  12. data/app/assets/stylesheets/peek.scss +85 -0
  13. data/app/assets/stylesheets/peek/vendor/tipsy.scss +22 -0
  14. data/app/controllers/peek/results_controller.rb +25 -0
  15. data/app/views/peek/_bar.html.erb +11 -0
  16. data/config/routes.rb +3 -0
  17. data/gitlab-peek.gemspec +22 -0
  18. data/lib/peek.rb +93 -0
  19. data/lib/peek/adapters/base.rb +17 -0
  20. data/lib/peek/adapters/elasticsearch.rb +33 -0
  21. data/lib/peek/adapters/memcache.rb +25 -0
  22. data/lib/peek/adapters/memory.rb +25 -0
  23. data/lib/peek/adapters/redis.rb +21 -0
  24. data/lib/peek/controller_helpers.rb +22 -0
  25. data/lib/peek/railtie.rb +37 -0
  26. data/lib/peek/version.rb +3 -0
  27. data/lib/peek/views/view.rb +124 -0
  28. data/test/controllers/requests_test.rb +33 -0
  29. data/test/dummy/README.rdoc +28 -0
  30. data/test/dummy/Rakefile +6 -0
  31. data/test/dummy/app/assets/javascripts/application.js +16 -0
  32. data/test/dummy/app/assets/stylesheets/application.css +14 -0
  33. data/test/dummy/app/controllers/application_controller.rb +13 -0
  34. data/test/dummy/app/controllers/home_controller.rb +11 -0
  35. data/test/dummy/app/helpers/application_helper.rb +2 -0
  36. data/test/dummy/app/views/home/show.html.erb +5 -0
  37. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  38. data/test/dummy/app/views/peek/_test_view.html.erb +1 -0
  39. data/test/dummy/bin/bundle +3 -0
  40. data/test/dummy/bin/rails +4 -0
  41. data/test/dummy/bin/rake +4 -0
  42. data/test/dummy/config.ru +4 -0
  43. data/test/dummy/config/application.rb +25 -0
  44. data/test/dummy/config/boot.rb +5 -0
  45. data/test/dummy/config/environment.rb +5 -0
  46. data/test/dummy/config/environments/development.rb +23 -0
  47. data/test/dummy/config/environments/test.rb +36 -0
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/test/dummy/config/initializers/inflections.rb +16 -0
  51. data/test/dummy/config/initializers/mime_types.rb +5 -0
  52. data/test/dummy/config/initializers/peek.rb +3 -0
  53. data/test/dummy/config/initializers/secret_token.rb +12 -0
  54. data/test/dummy/config/initializers/session_store.rb +3 -0
  55. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  56. data/test/dummy/config/locales/en.yml +23 -0
  57. data/test/dummy/config/routes.rb +8 -0
  58. data/test/dummy/lib/test_view.rb +18 -0
  59. data/test/dummy/public/404.html +58 -0
  60. data/test/dummy/public/422.html +58 -0
  61. data/test/dummy/public/500.html +57 -0
  62. data/test/dummy/public/favicon.ico +0 -0
  63. data/test/peek/views/view_test.rb +37 -0
  64. data/test/peek_test.rb +69 -0
  65. data/test/test_helper.rb +22 -0
  66. metadata +161 -0
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ desc 'Default: run tests'
5
+ task default: :test
6
+
7
+ desc 'Run Peek tests.'
8
+ Rake::TestTask.new do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.test_files = FileList['test/**/*_test.rb']
12
+ t.verbose = true
13
+ end
@@ -0,0 +1,86 @@
1
+ //= require peek/vendor/jquery.tipsy
2
+
3
+ var requestId;
4
+
5
+ requestId = null;
6
+
7
+ (function($) {
8
+ var fetchRequestResults, getRequestId, initializeTipsy, peekEnabled, toggleBar, updatePerformanceBar;
9
+ getRequestId = function() {
10
+ if (requestId != null) {
11
+ return requestId;
12
+ } else {
13
+ return $('#peek').data('request-id');
14
+ }
15
+ };
16
+ peekEnabled = function() {
17
+ return $('#peek').length;
18
+ };
19
+ updatePerformanceBar = function(results) {
20
+ var key, label;
21
+ for (key in results.data) {
22
+ for (label in results.data[key]) {
23
+ $("[data-defer-to=" + key + "-" + label + "]").text(results.data[key][label]);
24
+ }
25
+ }
26
+ return $(document).trigger('peek:render', [getRequestId(), results]);
27
+ };
28
+ initializeTipsy = function() {
29
+ return $('#peek .peek-tooltip, #peek .tooltip').each(function() {
30
+ var el, gravity;
31
+ el = $(this);
32
+ gravity = el.hasClass('rightwards') || el.hasClass('leftwards') ? $.fn.tipsy.autoWE : $.fn.tipsy.autoNS;
33
+ return el.tipsy({
34
+ gravity: gravity
35
+ });
36
+ });
37
+ };
38
+ toggleBar = function(event) {
39
+ var wrapper;
40
+ if ($(event.target).is(':input')) {
41
+ return;
42
+ }
43
+ if (event.which === 96 && !event.metaKey) {
44
+ wrapper = $('#peek');
45
+ if (wrapper.hasClass('disabled')) {
46
+ wrapper.removeClass('disabled');
47
+ return document.cookie = "peek=true; path=/";
48
+ } else {
49
+ wrapper.addClass('disabled');
50
+ return document.cookie = "peek=false; path=/";
51
+ }
52
+ }
53
+ };
54
+ fetchRequestResults = function() {
55
+ return $.ajax('/peek/results', {
56
+ data: {
57
+ request_id: getRequestId()
58
+ },
59
+ success: function(data, textStatus, xhr) {
60
+ return updatePerformanceBar(data);
61
+ },
62
+ error: function(xhr, textStatus, error) {}
63
+ });
64
+ };
65
+ $(document).on('keypress', toggleBar);
66
+ $(document).on('peek:update', initializeTipsy);
67
+ $(document).on('peek:update', fetchRequestResults);
68
+ $(document).on('pjax:end', function(event, xhr, options) {
69
+ if (xhr != null) {
70
+ requestId = xhr.getResponseHeader('X-Request-Id');
71
+ }
72
+ if (peekEnabled()) {
73
+ return $(this).trigger('peek:update');
74
+ }
75
+ });
76
+ $(document).on('page:change turbolinks:load', function() {
77
+ if (peekEnabled()) {
78
+ return $(this).trigger('peek:update');
79
+ }
80
+ });
81
+ return $(function() {
82
+ if (peekEnabled()) {
83
+ return $(this).trigger('peek:update');
84
+ }
85
+ });
86
+ })(jQuery);
@@ -0,0 +1,258 @@
1
+ // tipsy, facebook style tooltips for jquery
2
+ // version 1.0.0a
3
+ // (c) 2008-2010 jason frame [jason@onehackoranother.com]
4
+ // released under the MIT license
5
+
6
+ (function($) {
7
+
8
+ function maybeCall(thing, ctx) {
9
+ return (typeof thing == 'function') ? (thing.call(ctx)) : thing;
10
+ };
11
+
12
+ function isElementInDOM(ele) {
13
+ while (ele = ele.parentNode) {
14
+ if (ele == document) return true;
15
+ }
16
+ return false;
17
+ };
18
+
19
+ function Tipsy(element, options) {
20
+ this.$element = $(element);
21
+ this.options = options;
22
+ this.enabled = true;
23
+ this.fixTitle();
24
+ };
25
+
26
+ Tipsy.prototype = {
27
+ show: function() {
28
+ var title = this.getTitle();
29
+ if (title && this.enabled) {
30
+ var $tip = this.tip();
31
+
32
+ $tip.find('.tipsy-inner')[this.options.html ? 'html' : 'text'](title);
33
+ $tip[0].className = 'tipsy'; // reset classname in case of dynamic gravity
34
+ $tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).prependTo(document.body);
35
+
36
+ var pos = $.extend({}, this.$element.offset(), {
37
+ width: this.$element[0].offsetWidth,
38
+ height: this.$element[0].offsetHeight
39
+ });
40
+
41
+ var actualWidth = $tip[0].offsetWidth,
42
+ actualHeight = $tip[0].offsetHeight,
43
+ gravity = maybeCall(this.options.gravity, this.$element[0]);
44
+
45
+ var tp;
46
+ switch (gravity.charAt(0)) {
47
+ case 'n':
48
+ tp = {top: pos.top + pos.height + this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
49
+ break;
50
+ case 's':
51
+ tp = {top: pos.top - actualHeight - this.options.offset, left: pos.left + pos.width / 2 - actualWidth / 2};
52
+ break;
53
+ case 'e':
54
+ tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth - this.options.offset};
55
+ break;
56
+ case 'w':
57
+ tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width + this.options.offset};
58
+ break;
59
+ }
60
+
61
+ if (gravity.length == 2) {
62
+ if (gravity.charAt(1) == 'w') {
63
+ tp.left = pos.left + pos.width / 2 - 15;
64
+ } else {
65
+ tp.left = pos.left + pos.width / 2 - actualWidth + 15;
66
+ }
67
+ }
68
+
69
+ $tip.css(tp).addClass('tipsy-' + gravity);
70
+ $tip.find('.tipsy-arrow')[0].className = 'tipsy-arrow tipsy-arrow-' + gravity.charAt(0);
71
+ if (this.options.className) {
72
+ $tip.addClass(maybeCall(this.options.className, this.$element[0]));
73
+ }
74
+
75
+ if (this.options.fade) {
76
+ $tip.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: this.options.opacity});
77
+ } else {
78
+ $tip.css({visibility: 'visible', opacity: this.options.opacity});
79
+ }
80
+ }
81
+ },
82
+
83
+ hide: function() {
84
+ if (this.options.fade) {
85
+ this.tip().stop().fadeOut(function() { $(this).remove(); });
86
+ } else {
87
+ this.tip().remove();
88
+ }
89
+ },
90
+
91
+ fixTitle: function() {
92
+ var $e = this.$element;
93
+ if ($e.attr('title') || typeof($e.attr('original-title')) != 'string') {
94
+ $e.attr('original-title', $e.attr('title') || '').removeAttr('title');
95
+ }
96
+ },
97
+
98
+ getTitle: function() {
99
+ var title, $e = this.$element, o = this.options;
100
+ this.fixTitle();
101
+ var title, o = this.options;
102
+ if (typeof o.title == 'string') {
103
+ title = $e.attr(o.title == 'title' ? 'original-title' : o.title);
104
+ } else if (typeof o.title == 'function') {
105
+ title = o.title.call($e[0]);
106
+ }
107
+ title = ('' + title).replace(/(^\s*|\s*$)/, "");
108
+ return title || o.fallback;
109
+ },
110
+
111
+ tip: function() {
112
+ if (!this.$tip) {
113
+ this.$tip = $('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>');
114
+ this.$tip.data('tipsy-pointee', this.$element[0]);
115
+ }
116
+ return this.$tip;
117
+ },
118
+
119
+ validate: function() {
120
+ if (!this.$element[0].parentNode) {
121
+ this.hide();
122
+ this.$element = null;
123
+ this.options = null;
124
+ }
125
+ },
126
+
127
+ enable: function() { this.enabled = true; },
128
+ disable: function() { this.enabled = false; },
129
+ toggleEnabled: function() { this.enabled = !this.enabled; }
130
+ };
131
+
132
+ $.fn.tipsy = function(options) {
133
+
134
+ if (options === true) {
135
+ return this.data('tipsy');
136
+ } else if (typeof options == 'string') {
137
+ var tipsy = this.data('tipsy');
138
+ if (tipsy) tipsy[options]();
139
+ return this;
140
+ }
141
+
142
+ options = $.extend({}, $.fn.tipsy.defaults, options);
143
+
144
+ function get(ele) {
145
+ var tipsy = $.data(ele, 'tipsy');
146
+ if (!tipsy) {
147
+ tipsy = new Tipsy(ele, $.fn.tipsy.elementOptions(ele, options));
148
+ $.data(ele, 'tipsy', tipsy);
149
+ }
150
+ return tipsy;
151
+ }
152
+
153
+ function enter() {
154
+ var tipsy = get(this);
155
+ tipsy.hoverState = 'in';
156
+ if (options.delayIn == 0) {
157
+ tipsy.show();
158
+ } else {
159
+ tipsy.fixTitle();
160
+ setTimeout(function() { if (tipsy.hoverState == 'in') tipsy.show(); }, options.delayIn);
161
+ }
162
+ };
163
+
164
+ function leave() {
165
+ var tipsy = get(this);
166
+ tipsy.hoverState = 'out';
167
+ if (options.delayOut == 0) {
168
+ tipsy.hide();
169
+ } else {
170
+ setTimeout(function() { if (tipsy.hoverState == 'out') tipsy.hide(); }, options.delayOut);
171
+ }
172
+ };
173
+
174
+ if (!options.live) this.each(function() { get(this); });
175
+
176
+ if (options.trigger != 'manual') {
177
+ var binder = options.live ? 'live' : 'bind',
178
+ eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
179
+ eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
180
+ this[binder](eventIn, enter)[binder](eventOut, leave);
181
+ }
182
+
183
+ return this;
184
+
185
+ };
186
+
187
+ $.fn.tipsy.defaults = {
188
+ className: null,
189
+ delayIn: 0,
190
+ delayOut: 0,
191
+ fade: false,
192
+ fallback: '',
193
+ gravity: 'n',
194
+ html: false,
195
+ live: false,
196
+ offset: 0,
197
+ opacity: 0.8,
198
+ title: 'title',
199
+ trigger: 'hover'
200
+ };
201
+
202
+ $.fn.tipsy.revalidate = function() {
203
+ $('.tipsy').each(function() {
204
+ var pointee = $.data(this, 'tipsy-pointee');
205
+ if (!pointee || !isElementInDOM(pointee)) {
206
+ $(this).remove();
207
+ }
208
+ });
209
+ };
210
+
211
+ // Overwrite this method to provide options on a per-element basis.
212
+ // For example, you could store the gravity in a 'tipsy-gravity' attribute:
213
+ // return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
214
+ // (remember - do not modify 'options' in place!)
215
+ $.fn.tipsy.elementOptions = function(ele, options) {
216
+ return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
217
+ };
218
+
219
+ $.fn.tipsy.autoNS = function() {
220
+ return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
221
+ };
222
+
223
+ $.fn.tipsy.autoWE = function() {
224
+ return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
225
+ };
226
+
227
+ /**
228
+ * yields a closure of the supplied parameters, producing a function that takes
229
+ * no arguments and is suitable for use as an autogravity function like so:
230
+ *
231
+ * @param margin (int) - distance from the viewable region edge that an
232
+ * element should be before setting its tooltip's gravity to be away
233
+ * from that edge.
234
+ * @param prefer (string, e.g. 'n', 'sw', 'w') - the direction to prefer
235
+ * if there are no viewable region edges effecting the tooltip's
236
+ * gravity. It will try to vary from this minimally, for example,
237
+ * if 'sw' is preferred and an element is near the right viewable
238
+ * region edge, but not the top edge, it will set the gravity for
239
+ * that element's tooltip to be 'se', preserving the southern
240
+ * component.
241
+ */
242
+ $.fn.tipsy.autoBounds = function(margin, prefer) {
243
+ return function() {
244
+ var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)},
245
+ boundTop = $(document).scrollTop() + margin,
246
+ boundLeft = $(document).scrollLeft() + margin,
247
+ $this = $(this);
248
+
249
+ if ($this.offset().top < boundTop) dir.ns = 'n';
250
+ if ($this.offset().left < boundLeft) dir.ew = 'w';
251
+ if ($(window).width() + $(document).scrollLeft() - $this.offset().left < margin) dir.ew = 'e';
252
+ if ($(window).height() + $(document).scrollTop() - $this.offset().top < margin) dir.ns = 's';
253
+
254
+ return dir.ns + (dir.ew ? dir.ew : '');
255
+ }
256
+ };
257
+
258
+ })(jQuery);
@@ -0,0 +1,85 @@
1
+ //= require peek/vendor/tipsy
2
+
3
+ #peek {
4
+ background: #000;
5
+ height: 35px;
6
+ line-height: 35px;
7
+ color: #999;
8
+ text-shadow: 0 1px 1px rgba(0, 0, 0, 0.75);
9
+
10
+ .hidden {
11
+ display: none;
12
+ visibility: visible;
13
+ }
14
+
15
+ &.disabled {
16
+ display: none;
17
+ }
18
+
19
+ &.production {
20
+ background-color: #222;
21
+ }
22
+
23
+ &.staging {
24
+ background-color: #291430;
25
+ }
26
+
27
+ &.development {
28
+ background-color: #4c1210;
29
+ }
30
+
31
+ .wrapper {
32
+ width: 800px;
33
+ margin: 0 auto;
34
+ }
35
+
36
+ // UI Elements
37
+ .bucket {
38
+ background: #111;
39
+ display: inline-block;
40
+ padding: 4px 6px;
41
+ font-family: Consolas, "Liberation Mono", Courier, monospace;
42
+ line-height: 1;
43
+ color: #ccc;
44
+ border-radius: 3px;
45
+ box-shadow: 0 1px 0 rgba(255,255,255,.2), inset 0 1px 2px rgba(0,0,0,.25);
46
+
47
+ .hidden {
48
+ display: none;
49
+ }
50
+
51
+ &:hover .hidden {
52
+ display: inline;
53
+ }
54
+ }
55
+
56
+ strong {
57
+ color: #fff;
58
+ }
59
+
60
+ .view {
61
+ margin-right: 15px;
62
+ float: left;
63
+
64
+ &:last-child {
65
+ margin-right: 0;
66
+ }
67
+ }
68
+
69
+ .css-truncate {
70
+ &.css-truncate-target,
71
+ .css-truncate-target {
72
+ display: inline-block;
73
+ max-width: 125px;
74
+ overflow: hidden;
75
+ text-overflow: ellipsis;
76
+ white-space: nowrap;
77
+ vertical-align: top;
78
+ }
79
+
80
+ &.expandable:hover .css-truncate-target,
81
+ &.expandable:hover.css-truncate-target {
82
+ max-width: 10000px !important;
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,22 @@
1
+ .tipsy { font-size: 10px; position: absolute; padding: 5px; z-index: 100000; }
2
+ .tipsy-inner { background-color: #000; color: #FFF; max-width: 200px; padding: 5px 8px 4px 8px; text-align: center; }
3
+
4
+ /* Rounded corners */
5
+ .tipsy-inner { border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
6
+
7
+ .tipsy-arrow { position: absolute; width: 0; height: 0; line-height: 0; border: 5px dashed #000; }
8
+
9
+ /* Rules to colour arrows */
10
+ .tipsy-arrow-n { border-bottom-color: #000; }
11
+ .tipsy-arrow-s { border-top-color: #000; }
12
+ .tipsy-arrow-e { border-left-color: #000; }
13
+ .tipsy-arrow-w { border-right-color: #000; }
14
+
15
+ .tipsy-n .tipsy-arrow { top: 0px; left: 50%; margin-left: -5px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent; }
16
+ .tipsy-nw .tipsy-arrow { top: 0; left: 10px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent;}
17
+ .tipsy-ne .tipsy-arrow { top: 0; right: 10px; border-bottom-style: solid; border-top: none; border-left-color: transparent; border-right-color: transparent;}
18
+ .tipsy-s .tipsy-arrow { bottom: 0; left: 50%; margin-left: -5px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
19
+ .tipsy-sw .tipsy-arrow { bottom: 0; left: 10px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
20
+ .tipsy-se .tipsy-arrow { bottom: 0; right: 10px; border-top-style: solid; border-bottom: none; border-left-color: transparent; border-right-color: transparent; }
21
+ .tipsy-e .tipsy-arrow { right: 0; top: 50%; margin-top: -5px; border-left-style: solid; border-right: none; border-top-color: transparent; border-bottom-color: transparent; }
22
+ .tipsy-w .tipsy-arrow { left: 0; top: 50%; margin-top: -5px; border-right-style: solid; border-left: none; border-top-color: transparent; border-bottom-color: transparent; }