trestle-search 0.2.1 → 0.3.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
  SHA256:
3
- metadata.gz: 3b0d81acc19c8af1130e82598e8a8c6692ea1d303874f9ddc4b44a91b816447b
4
- data.tar.gz: c806a1734cd63cebc00e78c19f2191da54ef56675eb11ca7e50fac1b55039d19
3
+ metadata.gz: 7bc1fa4641982dcb21cc9ae627fb195a7478d309772a8783a058eb9520fc7753
4
+ data.tar.gz: 2dddb7bf7cd81cfa160a00a117197e9069d079c1e9071190866cbaebf2802726
5
5
  SHA512:
6
- metadata.gz: 36f4856d6b27759116fd98f589fff5101e283c9f2d66d7525791424df9678cd2496cccab3fdc5eb2ac2a4936eda31b63d601094201e623a965f9e208314e4824
7
- data.tar.gz: 91022be5e6490aad23d6c9adc8cc751a5e3d5bf599550160e18c1b9e8c7832685539928a0924d6c3506e26b818b5656dbe0fb90620d0a5bfc6e352f00e82e8bd
6
+ metadata.gz: e868a81ac6c4e7cfb1147746053234e995c638ee67c0b8f9b15494a2bc3aa12255c975abaef830c8d446c3c40ae3360a6f30905a48ae1a0be1bf672c088f0e40
7
+ data.tar.gz: 042b653baf975277db24c9d1f39aaf01af1878e3d189bfea640dccd1ae975a8daa468afa4a8f275f7473a64215d942740165fdfd77485cd84e051b7f95fb51a4
@@ -1,55 +1,41 @@
1
1
  @import "trestle/support";
2
2
 
3
3
  .searchbox {
4
- float: left;
5
- max-width: 25%;
6
- padding: 8px 0;
4
+ width: 100%;
5
+ max-width: 30em;
6
+ margin-right: auto;
7
+
8
+ .input-group {
9
+ background: white;
10
+ border: 1px solid #ccc;
11
+ border-radius: 50px;
12
+ box-shadow: inset 0 1px 1px rgba(black, 0.075);
13
+ }
7
14
 
8
15
  .input-group-addon {
9
- background: none;
10
- border: none;
11
- padding-left: 0;
16
+ background: transparent;
17
+ border: 0;
12
18
  }
13
19
 
14
20
  .form-control {
15
21
  padding-left: 0;
16
22
 
17
- background: none;
23
+ background: transparent;
18
24
  box-shadow: none;
19
25
 
20
- border: none;
21
- border-radius: 0;
22
-
23
- border-bottom: 1px solid #ddd;
24
-
25
- transition: border-color 500ms;
26
-
27
- &:focus {
28
- border-color: #555;
29
- }
26
+ border: 0;
30
27
  }
31
28
 
32
- @media (max-width: $screen-xs-max) {
29
+ .clear-search {
33
30
  position: absolute;
34
- top: 10px;
35
- left: 10px;
36
- width: $sidebar-width - 20px;
37
- max-width: none;
38
-
39
- padding: 0 12px;
40
- background: white;
41
- box-shadow: inset 0 1px 1px rgba(black, 0.075);
42
- border-radius: 50px;
43
-
44
- .form-control {
45
- border-bottom: none;
46
- font-size: 16px;
31
+ right: 10px;
32
+ z-index: 5;
33
+ color: #555;
34
+ font-size: 16px;
35
+ padding: 4px;
36
+
37
+ &:hover, &:focus {
38
+ color: #333;
47
39
  }
48
40
  }
49
41
  }
50
-
51
- @media (max-width: $screen-xs-max) {
52
- .app-sidebar {
53
- padding-top: 40px;
54
- }
55
- }
@@ -1,10 +1,9 @@
1
- <% if defined?(admin) && admin.respond_to?(:searchable?) && admin.searchable? -%>
2
- <div class="searchbox">
3
- <%= form_tag admin.path, method: :get do %>
4
- <div class="input-group">
5
- <span class="input-group-addon"><icon class="fa fa-search"></icon></span>
6
- <%= text_field_tag :q, params[:q], class: "form-control", placeholder: t("admin.search.placeholder", default: "Search") %>
7
- </div>
8
- <% end %>
9
- </div>
10
- <% end -%>
1
+ <div class="searchbox">
2
+ <%= form_tag admin.path, method: :get do %>
3
+ <div class="input-group">
4
+ <span class="input-group-addon"><icon class="fa fa-search"></icon></span>
5
+ <%= link_to icon("fa fa-times"), admin.path, class: "clear-search" if params[:q].present? %>
6
+ <%= search_field_tag :q, params[:q], class: "form-control", autocomplete: "off", placeholder: admin.t("search.placeholder", default: "Search") %>
7
+ </div>
8
+ <% end %>
9
+ </div>
@@ -1,11 +1,11 @@
1
1
  Trestle.configure do |config|
2
2
  config.persistent_params << :q
3
-
3
+
4
4
  config.hook("stylesheets") do
5
5
  stylesheet_link_tag "trestle/search"
6
6
  end
7
7
 
8
- config.hook("view.header") do
8
+ config.hook("resource.index.header", if: -> { admin.searchable? }) do
9
9
  render "trestle/search/search"
10
10
  end
11
11
  end
@@ -2,7 +2,7 @@ module Trestle
2
2
  module Search
3
3
  module Builder
4
4
  def search(&block)
5
- admin.search = block
5
+ admin.define_adapter_method(:search, &block)
6
6
  end
7
7
  end
8
8
  end
@@ -4,7 +4,7 @@ module Trestle
4
4
  config.assets.precompile << "trestle/search.css"
5
5
 
6
6
  initializer :extensions do
7
- Trestle::Resource.singleton_class.send(:prepend, Trestle::Search::Resource)
7
+ Trestle::Resource.send(:include, Trestle::Search::Resource)
8
8
  Trestle::Resource::Builder.send(:include, Trestle::Search::Builder)
9
9
  Trestle::Resource::Controller.send(:prepend, Trestle::Search::Controller)
10
10
  end
@@ -1,22 +1,30 @@
1
1
  module Trestle
2
2
  module Search
3
3
  module Resource
4
- attr_writer :search
4
+ extend ActiveSupport::Concern
5
5
 
6
- def initialize_collection(params)
7
- if searchable?
8
- search(params[:q], params)
9
- else
10
- super(params)
11
- end
6
+ included do
7
+ # Include custom #collection method on Resource instance
8
+ prepend Collection
9
+
10
+ # Include custom #collection method on Resource class
11
+ singleton_class.send(:prepend, Collection)
12
12
  end
13
13
 
14
- def search(query, params)
15
- instance_exec(query.presence, params, &@search)
14
+ module Collection
15
+ def collection(params)
16
+ if searchable?
17
+ adapter.search(params[:q].presence, params)
18
+ else
19
+ super
20
+ end
21
+ end
16
22
  end
17
23
 
18
- def searchable?
19
- @search
24
+ module ClassMethods
25
+ def searchable?
26
+ adapter.respond_to?(:search)
27
+ end
20
28
  end
21
29
  end
22
30
  end
@@ -1,5 +1,5 @@
1
1
  module Trestle
2
2
  module Search
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "trestle", "~> 0.8", ">= 0.8.7"
21
+ spec.add_dependency "trestle", "~> 0.8", ">= 0.8.10"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.12"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trestle-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Pohlenz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-20 00:00:00.000000000 Z
11
+ date: 2018-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trestle
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.8'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.8.7
22
+ version: 0.8.10
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0.8'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.8.7
32
+ version: 0.8.10
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.7.3
124
+ rubygems_version: 2.7.6
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Search plugin for the Trestle admin framework