enjoy_cms_search 0.4.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b295ddfb305f2e7db8e98513cf9dc0f46ce7d8b
4
+ data.tar.gz: e8e11398d6ab597ccc595b7fc901d10c8e3ec881
5
+ SHA512:
6
+ metadata.gz: 1e3e994ac2e5fea82a0b3eb3fa4ba3c55c0a6e9f3926337283283c2b7cfbc5c808f26da399f32d53bdd0a301f400548e29b82c95da8e7294c4c75baf7b3ceb21
7
+ data.tar.gz: a74c54b8a1a3c69744100ffa3296ab53681394684b9c3b2727b35d1910b30ceae8e3b82b1d427f75372e540cc086e49915eb902ffaf65ef2643e5dd6b2f8d5fd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ enjoy_cms_search
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in enjoy_cms_search.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexander Kiseliev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # EnjoyCmsSearch
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/enjoy_cms_search`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'enjoy_cms_search'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install enjoy_cms_search
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/enjoy_cms_search.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module Enjoy::Search::Decorators
2
+ module Search
3
+ extend ActiveSupport::Concern
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Enjoy::Search
2
+ class SearchController < ApplicationController
3
+ include Enjoy::Search::Controllers::Search
4
+
5
+ include Enjoy::Search::Decorators::Search
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ module Enjoy::Search::Searchable
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def enjoy_search_fts_index(*opts)
6
+ if Enjoy::Search.mongoid?
7
+ opts = opts.extract_options!
8
+ index(
9
+ {
10
+ name: "text"
11
+ }.merge(opts[:fields]),
12
+ {
13
+ default_language: opts[:default_language] || "russian",
14
+ weights: {
15
+ name: 100
16
+ }.merge(opts[:weights]),
17
+ name: opts[:name]
18
+ }
19
+ )
20
+ end
21
+ end
22
+ end
23
+
24
+ included do
25
+ scope :fts, -> (query) {
26
+ ret = where({"$text": { "$search": query.to_s }})
27
+ ret.options[:fields] = {"score": { "$meta": "textScore" }}
28
+ ret.options[:sort] = {"score": { "$meta": "textScore" }}
29
+ ret
30
+ }
31
+ end
32
+
33
+ end
@@ -0,0 +1,3 @@
1
+ = form_tag enjoy_search_path, method: :get, class: 'nav_search' do
2
+ = text_field_tag 'q', params[:q], placeholder: "Поиск"
3
+ = submit_tag 'Найти'
@@ -0,0 +1,17 @@
1
+ .enjoy-search-results
2
+ h1 Результаты поиска
3
+ = render partial: "enjoy/search/search/form"
4
+ ol
5
+ - any = false
6
+ - @results.each do |r|
7
+ - any = true
8
+ li
9
+ .title= link_to r.name, url_for(r)
10
+ .text
11
+ = raw r.content
12
+ span.more= link_to 'открыть', url_for(r)
13
+
14
+ - unless any
15
+ .enjoy-search-no-results К сожалению, ничего не найдено
16
+
17
+ = paginate @results if any
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "enjoy_cms_search"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'enjoy/search/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "enjoy_cms_search"
8
+ spec.version = Enjoy::Search::VERSION
9
+ spec.authors = ["Alexander Kiseliev"]
10
+ spec.email = ["i43ack@gmail.com"]
11
+
12
+ spec.summary = %q{enjoy_cms_search}
13
+ spec.description = %q{enjoy_cms_search}
14
+ spec.homepage = "https://github.com/enjoycreative/enjoy_cms_search"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+
33
+ spec.add_dependency 'enjoy_cms', "~> 0.4.0.beta3"
34
+
35
+ end
@@ -0,0 +1,48 @@
1
+ module Enjoy::Search
2
+ module Controllers
3
+ module Search
4
+ extend ActiveSupport::Concern
5
+
6
+ def index
7
+ if search_redirecter
8
+ return redirect_to url_for(params)
9
+ end
10
+
11
+ if defined?(BreadcrumbsOnRails)
12
+ add_breadcrumb "search", [:enjoy_search]
13
+ end
14
+
15
+ if params[:q].blank?
16
+ @results = []
17
+ else
18
+ query = params[:q].to_s.gsub(/\P{Word}+/, ' ').gsub(/ +/, ' ').strip
19
+ @results = search_model_class.page(params[:page]).per(10).send(fts_method, query)
20
+ end
21
+
22
+ if defined?(BreadcrumbsOnRails)
23
+ add_breadcrumb "results", [:enjoy_search, {q: params[:q]}]
24
+ end
25
+ end
26
+
27
+ private
28
+ def search_model_class
29
+ Enjoy::Catalog::Item
30
+ end
31
+
32
+ def fts_method
33
+ :fts
34
+ end
35
+
36
+ def search_redirecter
37
+ if params[:utf8].present? or params[:submit].present? or params[:commit].present?
38
+ params.delete(:utf8)
39
+ params.delete(:submit)
40
+ params.delete(:commit)
41
+ return true
42
+ end
43
+ false
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ module Enjoy
2
+ module Search
3
+ class Engine < ::Rails::Engine
4
+ # isolate_namespace Enjoy::Search
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+
4
+ def enjoy_cms_search_routes(config = {})
5
+ routes_config = {
6
+ use_search_path: true
7
+ }
8
+ routes_config.merge!(config)
9
+
10
+ scope module: 'enjoy' do
11
+ scope module: 'search' do
12
+
13
+ if routes_config[:use_search_path]
14
+ get 'search/(:q)(/page/:page)' => 'search#index', as: :enjoy_search
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ module Enjoy
2
+ module Search
3
+ VERSION = "0.4.0.beta3"
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+ require "enjoy/search/version"
2
+ require "enjoy/search/engine"
3
+ require "enjoy/search/routes"
4
+
5
+ if Enjoy.active_record?
6
+ require 'pg_search'
7
+ end
8
+
9
+ # require 'enjoy_cms'
10
+
11
+ module Enjoy::Search
12
+ class << self
13
+ def orm
14
+ Enjoy.orm
15
+ end
16
+ def mongoid?
17
+ Enjoy::Search.orm == :mongoid
18
+ end
19
+ def active_record?
20
+ Enjoy::Search.orm == :active_record
21
+ end
22
+ # def model_namespace
23
+ # "Enjoy::Search::Models::#{Enjoy::Search.orm.to_s.camelize}"
24
+ # end
25
+ # def orm_specific(name)
26
+ # "#{model_namespace}::#{name}".constantize
27
+ # end
28
+ end
29
+
30
+ module Controllers
31
+ autoload :Search, 'enjoy/search/controllers/search'
32
+ end
33
+
34
+ end
data/release.sh ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/bash
2
+ bundle update
3
+ git add --all .
4
+ git commit -am "${*:1}"
5
+ git push
6
+ git push gh master
7
+ rake release
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enjoy_cms_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0.beta3
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Kiseliev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: enjoy_cms
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.0.beta3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.0.beta3
55
+ description: enjoy_cms_search
56
+ email:
57
+ - i43ack@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".ruby-gemset"
64
+ - ".ruby-version"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - app/controllers/concerns/enjoy/search/decorators/search.rb
71
+ - app/controllers/enjoy/search/search_controller.rb
72
+ - app/models/concerns/enjoy/search/searchable.rb
73
+ - app/views/enjoy/search/search/_form.html.slim
74
+ - app/views/enjoy/search/search/index.html.slim
75
+ - bin/console
76
+ - bin/setup
77
+ - enjoy_cms_search.gemspec
78
+ - lib/enjoy/search/controllers/search.rb
79
+ - lib/enjoy/search/engine.rb
80
+ - lib/enjoy/search/routes.rb
81
+ - lib/enjoy/search/version.rb
82
+ - lib/enjoy_cms_search.rb
83
+ - release.sh
84
+ homepage: https://github.com/enjoycreative/enjoy_cms_search
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">"
100
+ - !ruby/object:Gem::Version
101
+ version: 1.3.1
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.5.1
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: enjoy_cms_search
108
+ test_files: []