passages 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f37c423eff6bfd9da867704180a01ca6abcc650f
4
- data.tar.gz: e9689b0ea723de0b76c90e9e10ae59f429ec4840
3
+ metadata.gz: 91ad2eb2bfd8de3cb90f430b52679748b6458249
4
+ data.tar.gz: 2dc1db09ec74c6815f2d5b5b3c236d714b952ee5
5
5
  SHA512:
6
- metadata.gz: 743b38a9e68e39887fa93529191793d70af8721e8df2113929a6daf95357ae423c4f07ae903f18e4f6dd93c10d92942b5265d0ad49277e705b8a5f37129edf73
7
- data.tar.gz: eac0cf7983556bf5383b6372928fb84df773ba3bcd4db2b309a912f36a87ea12bda5d50d6efdd546c21b2b6a63f488685e549a6e97269c1dad431187b0386772
6
+ metadata.gz: 4aab33a5ca1ade95fa46865311fd94d9f4bae52fb2079a3dbb78df90ad7a99879e0ba2edba6542fd92c2693b344f234acba823273734cc261253806319673989
7
+ data.tar.gz: bd078de0461d8dd8367848ebd25a6fdcafd8c19f270282edcf693dd2c348a8563f9518aff855e6cfd6b1f64d3dfdd5a5c25423b8addedc2a0536fe673d84dc49
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- passages (0.1.0)
4
+ passages (0.2.0)
5
5
  rails (~> 4.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -8,6 +8,10 @@ This Rails Engine adds the ability to search over different attributes of Ruby o
8
8
 
9
9
  For example, an internal (or very permissive external) API can now expose a single page that will answer simple questions like: *"What was the HTTP verb for the `/users/clear_password` route?"* or *"Does a v2 or v3 version for this route exist?"*.
10
10
 
11
+ ## Demo
12
+
13
+ ![Demo](demo.gif)
14
+
11
15
  ## Install
12
16
 
13
17
  In your `Gemfile`
@@ -19,13 +23,13 @@ gem 'passages'
19
23
 
20
24
  `bundle install`
21
25
 
22
- The `Passages` engine will **prepend** a `/passages` route to the application's routes.
26
+ The `Passages` engine will **prepend** a `/passages` route to the application's routes. This means that if a project's `routes.rb` specifically defines a `/passages` route, the `Passages` Engine will not overwrite that.
23
27
 
24
28
  Visiting `/passages` will display a search box and list of all known routes in an application.
25
29
 
26
30
  ## Authorization
27
31
 
28
- Since there is no environment dependent checks, the `/passages` page uses configurable http basic authentication.
32
+ Since there are no environment dependent checks, the `/passages` page uses configurable http basic authentication.
29
33
 
30
34
  Default username: **username**
31
35
 
@@ -1,13 +1,36 @@
1
1
  //= require jquery-2.1.4.min
2
2
 
3
- DomElements = {
3
+ var Highlighter = {
4
+ highlight: function(result, terms) {
5
+ $.each(terms.split(' '), function(index, term) {
6
+ if(term.length > 0 ) {
7
+ $.each(result.find('td'), function(index, element) {
8
+ if ($(element).find('span').length == 0){
9
+ var existingHtml = $(element).html();
10
+ var replacedHtml = existingHtml.replace(new RegExp("(" + term + ")", "i"), "<span class='highlighted'>$1</span>");
11
+ $(element).html(replacedHtml);
12
+ }
13
+ else {
14
+ $.each($('element').contents(), function(index, content) {
15
+ if(content.nodeType == 3) { // nodeType == 3 means it is not a child node
16
+ $(content).html($(content).html().replace(new RegExp("(" + term + ")", "i"), "<span class='highlighted'>$1</span>"));
17
+ }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ };
25
+
26
+ DomElement = {
4
27
  matchingTerm: 'table.matching-term'
5
28
  };
6
29
 
7
30
  function clearAndHideResultTable() {
8
31
  var header = $('table.matching-term .header');
9
- $(DomElements.matchingTerm).html(header);
10
- $(DomElements.matchingTerm).hide();
32
+ $(DomElement.matchingTerm).html(header);
33
+ $(DomElement.matchingTerm).hide();
11
34
  }
12
35
 
13
36
  function hideNoResults() {
@@ -20,28 +43,36 @@ function showNoResults(searchTerm) {
20
43
 
21
44
  function showResultTable() {
22
45
  hideNoResults();
23
- $(DomElements.matchingTerm).show();
46
+ $(DomElement.matchingTerm).show();
24
47
  }
25
48
 
26
49
  function searchResults(query) {
27
50
  clearAndHideResultTable();
28
- return $('[data-search*=' + query).parent('tr');
29
- }
51
+ var terms = query.split(' ');
52
+ var parents = [];
30
53
 
31
- function highlight(element, term) {
32
- var existing = $(element).html();
33
- var bolded = existing.replace(new RegExp("(" + term + ")", "i"), "<span class='highlighted'>$1</span>");
34
- $(element).html(bolded)
54
+ $.each(terms, function(index, el) {
55
+ if (parents.length == 0) {
56
+ parents = $('[data-search*=' + el + ']').parent('tr');
57
+ }
58
+ else if(el.length > 0) {
59
+ $.each(parents, function(index, parent) {
60
+ if($(parent).find($('[data-search*=' + el + ']')).length == 0) {
61
+ parents[index] = null;
62
+ }
63
+ });
64
+ }
65
+ });
66
+
67
+ return parents
35
68
  }
36
69
 
37
- function addToResultTable(result, searchTerm){
70
+ function addToResultTable(result, searchTerms){
38
71
  showResultTable();
39
72
  var table = $('.matching-term');
40
73
  var lastChild = table.find('tr:last');
41
74
 
42
- $.each(result.children(), function(index, element) {
43
- highlight(element, searchTerm);
44
- });
75
+ Highlighter.highlight(result, searchTerms);
45
76
 
46
77
  if(lastChild.length == 0) {
47
78
  table.html(result);
@@ -6,7 +6,9 @@ require 'passages/engine_route_collection'
6
6
 
7
7
  module Passages
8
8
  class RoutesController < ActionController::Base
9
- http_basic_authenticate_with name: Passages.username, password: Passages.password
9
+ unless Passages.no_auth?
10
+ http_basic_authenticate_with name: Passages.username, password: Passages.password
11
+ end
10
12
 
11
13
  layout false
12
14
 
@@ -7,5 +7,13 @@ module Passages
7
7
  ENV['passages_password'] || 'password'
8
8
  end
9
9
 
10
- module_function :username, :password
10
+ def no_auth=(no_auth)
11
+ @no_auth = no_auth
12
+ end
13
+
14
+ def no_auth?
15
+ @no_auth.nil? || @no_auth
16
+ end
17
+
18
+ module_function :username, :password, :no_auth=, :no_auth?
11
19
  end
data/demo.gif ADDED
Binary file
data/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Passages
2
- MAJOR = 0
3
- MINOR = 2
2
+ MAJOR = 1
3
+ MINOR = 0
4
4
  TINY = 0
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join('.').freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Yesbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-27 00:00:00.000000000 Z
11
+ date: 2016-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -61,6 +61,7 @@ files:
61
61
  - config/initializers/assets.rb
62
62
  - config/initializers/basic_auth.rb
63
63
  - config/routes.rb
64
+ - demo.gif
64
65
  - lib/passages.rb
65
66
  - lib/passages/engine.rb
66
67
  - lib/passages/engine_route.rb