trestle-search 0.2.1 → 0.4.3

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: c44c519d3870778dc31c5eec549290d197ea2bb09eb3db856c4208a64e3be20c
4
+ data.tar.gz: 712100fba45ffa35814854889da4f5e94be4e0f479a0863a73a2d3286f45bd04
5
5
  SHA512:
6
- metadata.gz: 36f4856d6b27759116fd98f589fff5101e283c9f2d66d7525791424df9678cd2496cccab3fdc5eb2ac2a4936eda31b63d601094201e623a965f9e208314e4824
7
- data.tar.gz: 91022be5e6490aad23d6c9adc8cc751a5e3d5bf599550160e18c1b9e8c7832685539928a0924d6c3506e26b818b5656dbe0fb90620d0a5bfc6e352f00e82e8bd
6
+ metadata.gz: 7791222516cebd2bea8d941279d7c71c6e120976cbebd229564925220e2e8fac794f240fcb25f8ba570b32acdf4fd5084bf202dd0abef7920525ea0d1f75b42e
7
+ data.tar.gz: 76cb2f9208c783b2fe3ace5ed8bf8f36a0bb9a6e31f5fd5a89c9c43cf797306e38f3785217571e9fcad2cca773d3b1e969485c0ac32dc7ffbd6e342b46d5f35e
@@ -0,0 +1 @@
1
+ > 0.25%
data/.gitignore CHANGED
@@ -7,3 +7,8 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /node_modules/
11
+ /spec/dummy/db/*.sqlite3
12
+ /spec/dummy/*.sqlite3-journal
13
+ /spec/dummy/log/*.log
14
+ /spec/dummy/tmp/*
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
+ --require spec_helper
1
2
  --format documentation
2
3
  --color
@@ -1,5 +1,22 @@
1
- sudo: false
2
1
  language: ruby
2
+
3
+ cache: bundler
4
+
5
+ before_install:
6
+ - gem update --system
7
+ - gem install bundler
8
+
3
9
  rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.12.5
10
+ - 2.6.5
11
+
12
+ gemfile:
13
+ - gemfiles/rails-5.0.gemfile
14
+ - gemfiles/rails-5.1.gemfile
15
+ - gemfiles/rails-5.2.gemfile
16
+ - gemfiles/rails-6.0.gemfile
17
+
18
+ jobs:
19
+ include:
20
+ gemfile: gemfiles/rails-4.2.gemfile
21
+ before_install:
22
+ - gem install bundler -v '< 2'
data/Gemfile CHANGED
@@ -2,3 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in trestle-auth.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "capybara"
8
+ end
9
+
10
+ gem "sqlite3", "~> 1.4"
11
+
12
+ gem "trestle", github: "TrestleAdmin/trestle"
@@ -0,0 +1 @@
1
+ .searchbox{width:100%;max-width:30em;margin-right:auto}.searchbox .input-group{background:#fff;border:1px solid #ccc;border-radius:50rem}.searchbox .form-control,.searchbox .input-group-text{background:transparent;border:0}.searchbox .form-control{padding-left:0;box-shadow:none}.searchbox .form-control::-webkit-search-cancel-button{display:none}.searchbox .clear-search{position:absolute;right:.75rem;z-index:5;color:#555;font-size:1.2rem;padding:.35rem}.searchbox .clear-search:focus,.searchbox .clear-search:hover{color:#333}
@@ -1,10 +1,11 @@
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") %>
1
+ <div class="searchbox">
2
+ <%= form_tag admin.path, method: :get do %>
3
+ <div class="input-group">
4
+ <div class="input-group-prepend">
5
+ <span class="input-group-text"><icon class="fa fa-search"></icon></span>
7
6
  </div>
8
- <% end %>
9
- </div>
10
- <% end -%>
7
+ <%= link_to icon("fa fa-times"), admin.path, class: "clear-search" if params[:q].present? %>
8
+ <%= search_field_tag :q, params[:q], class: "form-control", autocomplete: "off", placeholder: admin.t("search.placeholder", default: "Search") %>
9
+ </div>
10
+ <% end %>
11
+ </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
File without changes
@@ -0,0 +1,5 @@
1
+ es:
2
+ admin:
3
+ search:
4
+ placeholder: "Buscar"
5
+ results: "Resultados de la búsqueda"
@@ -0,0 +1,5 @@
1
+ fr:
2
+ admin:
3
+ search:
4
+ placeholder: "Recherche"
5
+ results: "Résultats de la recherche"
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ ru:
2
+ admin:
3
+ search:
4
+ placeholder: "Поиск"
5
+ results: "Результаты поиска"
@@ -0,0 +1,42 @@
1
+ .searchbox {
2
+ width: 100%;
3
+ max-width: 30em;
4
+ margin-right: auto;
5
+
6
+ .input-group {
7
+ background: white;
8
+ border: 1px solid #ccc;
9
+ border-radius: 50rem;
10
+ }
11
+
12
+ .input-group-text {
13
+ background: transparent;
14
+ border: 0;
15
+ }
16
+
17
+ .form-control {
18
+ padding-left: 0;
19
+
20
+ background: transparent;
21
+ box-shadow: none;
22
+
23
+ border: 0;
24
+
25
+ &::-webkit-search-cancel-button {
26
+ display: none;
27
+ }
28
+ }
29
+
30
+ .clear-search {
31
+ position: absolute;
32
+ right: 0.75rem;
33
+ z-index: 5;
34
+ color: #555;
35
+ font-size: 1.2rem;
36
+ padding: 0.35rem;
37
+
38
+ &:hover, &:focus {
39
+ color: #333;
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem "coveralls", require: false
5
+ gem "capybara"
6
+
7
+ gem "sqlite3", "~> 1.3.13"
8
+ end
9
+
10
+ gem "rails", "~> 4.2.0"
11
+
12
+ gem "trestle", github: "TrestleAdmin/trestle"
13
+
14
+ gemspec path: "../"
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem "coveralls", require: false
5
+ gem "capybara"
6
+
7
+ gem "sqlite3", "~> 1.3.13"
8
+ end
9
+
10
+ gem "rails", "~> 5.0.0"
11
+
12
+ gem "trestle", github: "TrestleAdmin/trestle"
13
+
14
+ gemspec path: "../"
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem "coveralls", require: false
5
+ gem "capybara"
6
+
7
+ gem "sqlite3", "~> 1.3.13"
8
+ end
9
+
10
+ gem "rails", "~> 5.1.0"
11
+
12
+ gem "trestle", github: "TrestleAdmin/trestle"
13
+
14
+ gemspec path: "../"
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem "coveralls", require: false
5
+ gem "capybara"
6
+
7
+ gem "sqlite3", "~> 1.3.13"
8
+ end
9
+
10
+ gem "rails", "~> 5.2.0"
11
+
12
+ gem "trestle", github: "TrestleAdmin/trestle"
13
+
14
+ gemspec path: "../"
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem "coveralls", require: false
5
+
6
+ gem "capybara"
7
+ gem "sqlite3", "~> 1.4"
8
+ end
9
+
10
+ gem "rails", "~> 6.0.0"
11
+
12
+ gem "trestle", github: "TrestleAdmin/trestle"
13
+
14
+ gemspec path: "../"
@@ -1,4 +1,4 @@
1
- require "trestle/search/version"
1
+ require_relative "search/version"
2
2
 
3
3
  require "trestle"
4
4
 
@@ -6,9 +6,9 @@ module Trestle
6
6
  module Search
7
7
  extend ActiveSupport::Autoload
8
8
 
9
- autoload :Builder
10
- autoload :Controller
11
- autoload :Resource
9
+ require_relative "search/builder"
10
+ require_relative "search/controller"
11
+ require_relative "search/resource"
12
12
 
13
13
  autoload_under "adapters" do
14
14
  autoload :ChewyAdapter
@@ -17,4 +17,4 @@ module Trestle
17
17
  end
18
18
  end
19
19
 
20
- require "trestle/search/engine" if defined?(Rails)
20
+ require_relative "search/engine" if defined?(Rails)
@@ -4,6 +4,10 @@ module Trestle
4
4
  def finalize_collection(query)
5
5
  query.records
6
6
  end
7
+
8
+ def count(collection)
9
+ collection.count
10
+ end
7
11
  end
8
12
  end
9
13
  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
@@ -2,11 +2,11 @@ module Trestle
2
2
  module Search
3
3
  module Controller
4
4
  def index
5
- super
6
-
7
5
  if admin.searchable? && params[:q].present?
8
6
  breadcrumb t("admin.search.results", default: "Search Results"), { q: params[:q] }
9
7
  end
8
+
9
+ super
10
10
  end
11
11
  end
12
12
  end
@@ -3,10 +3,13 @@ module Trestle
3
3
  class Engine < ::Rails::Engine
4
4
  config.assets.precompile << "trestle/search.css"
5
5
 
6
+ config.to_prepare do
7
+ Trestle::ResourceController.send(:prepend, Trestle::Search::Controller)
8
+ end
9
+
6
10
  initializer :extensions do
7
- Trestle::Resource.singleton_class.send(:prepend, Trestle::Search::Resource)
11
+ Trestle::Resource.send(:include, Trestle::Search::Resource)
8
12
  Trestle::Resource::Builder.send(:include, Trestle::Search::Builder)
9
- Trestle::Resource::Controller.send(:prepend, Trestle::Search::Controller)
10
13
  end
11
14
  end
12
15
  end
@@ -1,22 +1,35 @@
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
+ query = params[:q].presence
18
+ search(query, params) || super
19
+ else
20
+ super
21
+ end
22
+ end
23
+
24
+ def search(query, params={})
25
+ adapter.search(query, params)
26
+ end
16
27
  end
17
28
 
18
- def searchable?
19
- @search
29
+ module ClassMethods
30
+ def searchable?
31
+ adapter.respond_to?(:search)
32
+ end
20
33
  end
21
34
  end
22
35
  end
@@ -1,5 +1,5 @@
1
1
  module Trestle
2
2
  module Search
3
- VERSION = "0.2.1"
3
+ VERSION = "0.4.3"
4
4
  end
5
5
  end
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "trestle-search",
3
+ "version": "0.4.0",
4
+ "description": "Search plugin for the Trestle admin framework",
5
+ "main": "index.scss",
6
+ "repository": "https://github.com/TrestleAdmin/trestle-search.git",
7
+ "author": "Sam Pohlenz <sam@sampohlenz.com>",
8
+ "license": "LGPL-3.0",
9
+ "private": true,
10
+ "scripts": {
11
+ "dev": "webpack --mode development",
12
+ "build": "webpack --mode production",
13
+ "watch": "webpack --mode development --watch"
14
+ },
15
+ "devDependencies": {
16
+ "autoprefixer": "^9.6.1",
17
+ "css-loader": "^3.2.0",
18
+ "mini-css-extract-plugin": "^0.8.0",
19
+ "node-sass": "^4.12.0",
20
+ "optimize-css-assets-webpack-plugin": "^5.0.3",
21
+ "postcss-loader": "^3.0.0",
22
+ "sass-loader": "^8.0.0",
23
+ "webpack": "^4.40.2",
24
+ "webpack-cli": "^3.3.9",
25
+ "webpack-fix-style-only-entries": "^0.4.0"
26
+ },
27
+ "dependencies": {
28
+ "trestle": "https://github.com/TrestleAdmin/trestle.git"
29
+ }
30
+ }
@@ -1,7 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'trestle/search/version'
1
+ require_relative 'lib/trestle/search/version'
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
  spec.name = "trestle-search"
@@ -11,16 +8,21 @@ Gem::Specification.new do |spec|
11
8
  spec.email = ["sam@sampohlenz.com"]
12
9
 
13
10
  spec.summary = "Search plugin for the Trestle admin framework"
14
- spec.description = "Search plugin for the Trestle admin framework."
15
11
  spec.homepage = "https://www.trestle.io"
16
12
  spec.license = "LGPL-3.0"
17
13
 
18
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
16
+ end
17
+
19
18
  spec.require_paths = ["lib"]
20
19
 
21
- spec.add_dependency "trestle", "~> 0.8", ">= 0.8.7"
20
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/TrestleAdmin/trestle-search"
24
+
25
+ spec.add_dependency "trestle", "~> 0.9.0", ">= 0.9.3"
22
26
 
23
- spec.add_development_dependency "bundler", "~> 1.12"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "rspec-rails", "~> 3.0"
26
28
  end