ransack_memory 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10e3fba05938906e50d390712345e76dbd704390
4
- data.tar.gz: ecd1d5cd30a20f5e5b9768df2d1795b0f18a560f
3
+ metadata.gz: 7e18e02f0204f759edc457fc98899ad16d731690
4
+ data.tar.gz: b280afa8586cc6b6595011434fb809e661ecc4e0
5
5
  SHA512:
6
- metadata.gz: 397f29e47cd222fe96ca649b9a1019dd9e414f917744860851a0aac790d3f8cb11dc5ff471eb4dfb57352931cf8f4cf7fc1b32f87d122154284fb008b6a39301
7
- data.tar.gz: f23736495ce5aab52fdf3ce2879e307a5d8ddeee649544a593e918e4811206a3109a15df7acc422630085b3ebadd8ea89d6a4419dc8eec4756af930379b4052c
6
+ metadata.gz: 965a6bbe5a161c331c487ddf75379b4cb866ac293c32e354507728026c4750eb358813fa2dc6b16f17f428fb10ce90c3d4d8b3fb6263fb9cca2dec1f65348cae
7
+ data.tar.gz: 1a7e5aa376ad22eedb637cb883daec678a8d7daab72f4befdc1603461b5a04f8a1143347c860805924a90fb392312095d0646297d319f46748d42d6d338450a9
data/README.md CHANGED
@@ -7,4 +7,39 @@ Add this line to your application's Gemfile:
7
7
 
8
8
  ```ruby
9
9
  gem 'ransack_memory'
10
- ```
10
+ ```
11
+
12
+ Add this line to your basic controller (typically ApplicationController):
13
+
14
+ ```ruby
15
+ class ApplicationController < ActionController::Base
16
+ include RansackMemory::Concern # insert this line
17
+
18
+ before_action :authenticate_user! # only if you use Devise gem
19
+ before_action :save_and_load_filters # insert this line after Devise auth before filter (Devise gem is not necessary)
20
+ end
21
+ ```
22
+
23
+ Add this in your views where you have search forms. This is clear button, which deletes ransack memory sessions.
24
+ ```erb
25
+ <%= clear_filter %>
26
+ ```
27
+ You can pass any of link attributes:
28
+
29
+ ```erb
30
+ <%= clear_filter, class: 'btn btn-primary', data: {confirm: 'Really?', my_data: 'something'} %>
31
+ ```
32
+
33
+ ## Configuration
34
+
35
+ Create file in config/initializers/ransack_memory.rb with this content:
36
+
37
+ ```ruby
38
+ RansackMemory::Core.config = {
39
+ param: :q, # this means the default Ransack param name for searching. You can change it
40
+ link_label: 'Clear filter' # clear_filter link label
41
+ }
42
+ ```
43
+
44
+ Or you can generate this config file by running ```rails generate ransack_memory``` in console.
45
+
@@ -1,5 +1,5 @@
1
- module Concerns
2
- module RansackMemory
1
+ module RansackMemory
2
+ module Concern
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def save_and_load_filters
@@ -13,7 +13,7 @@ module Concerns
13
13
 
14
14
  if user_signed_in?
15
15
  # search term saving
16
- session["#{controller_name}_#{action_name}_#{request.xhr?}"] = params[RansackMemory.config[:param]] if params[RansackMemory.config[:param]].present?
16
+ session["#{controller_name}_#{action_name}_#{request.xhr?}"] = params[::RansackMemory::Core.config[:param]] if params[::RansackMemory::Core.config[:param]].present?
17
17
 
18
18
  # page number saving
19
19
  session["#{controller_name}_#{action_name}_#{request.xhr?}_page"] = params[:page] if params[:page].present?
@@ -25,9 +25,9 @@ module Concerns
25
25
  if user_signed_in?
26
26
  # search term load
27
27
  if session["#{controller_name}_#{action_name}_#{request.xhr?}"]
28
- params[RansackMemory.config[:param]] = session["#{controller_name}_#{action_name}_#{request.xhr?}"]
28
+ params[::RansackMemory::Core.config[:param]] = session["#{controller_name}_#{action_name}_#{request.xhr?}"]
29
29
  else
30
- params[RansackMemory.config[:param]] = nil
30
+ params[::RansackMemory::Core.config[:param]] = nil
31
31
  end
32
32
 
33
33
  # page number load
@@ -38,11 +38,11 @@ module Concerns
38
38
  end
39
39
 
40
40
  # set page number to 1 if filter has changed
41
- if (params[RansackMemory.config[:param]] && session[:last_q_params] != params[RansackMemory.config[:param]]) || (params[:cancel_filter].present? && session["#{controller_name}_#{action_name}_#{request.xhr?}_page"] != params[:page])
41
+ if (params[::RansackMemory::Core.config[:param]] && session[:last_q_params] != params[::RansackMemory::Core.config[:param]]) || (params[:cancel_filter].present? && session["#{controller_name}_#{action_name}_#{request.xhr?}_page"] != params[:page])
42
42
  params[:page] = nil
43
43
  session["#{controller_name}_#{action_name}_#{request.xhr?}_page"] = nil
44
44
  end
45
- session[:last_q_params] = params[RansackMemory.config[:param]]
45
+ session[:last_q_params] = params[::RansackMemory::Core.config[:param]]
46
46
 
47
47
  # per page load
48
48
  if session["#{controller_name}_#{action_name}_#{request.xhr?}_per_page"]
@@ -1,2 +1,2 @@
1
- - if params[RansackMemory.config[:param]].present?
2
- = link_to 'Clear filter', url_for + "?cancel_filter=true", opts
1
+ - if params[RansackMemory::Core.config[:param].presence || :q].present?
2
+ = link_to RansackMemory::Core.config[:link_label].presence || 'Clear filter', url_for + "?cancel_filter=true", opts
@@ -2,9 +2,10 @@ if defined?(Rails)
2
2
 
3
3
  # Rails3 generator invoked with 'rails generate ransack_memory'
4
4
  class RansackMemoryGenerator < Rails::Generators::Base
5
- source_root(File.expand_path(File.dirname(__FILE__) + "/../../generators/ransack_memory/templates"))
5
+ source_root(File.expand_path(File.dirname(__FILE__) + "/../templates/ransack_memory"))
6
6
  def copy_initializer
7
- copy_file 'ransack_memory.rb', 'config/initializers/ransack_memory.rb'
7
+
8
+ copy_file 'ransack_memory_template.rb', 'config/initializers/ransack_memory.rb'
8
9
  end
9
10
  end
10
11
 
@@ -1,9 +1,15 @@
1
- class RansackMemory
2
- @@config = {}
3
- cattr_accessor :config
1
+ module RansackMemory
4
2
 
5
- def initialize(opts = {})
6
- @opts = opts
3
+ require 'ransack_memory/version'
4
+ require 'ransack_memory/engine' if defined?(::Rails)
5
+
6
+ class Core
7
+ @@config = {}
8
+ cattr_accessor :config
9
+
10
+ def initialize(opts = {})
11
+ @opts = opts
12
+ end
7
13
  end
8
14
 
9
15
  end
@@ -0,0 +1,4 @@
1
+ module RansackMemory
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RansackMemory
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,4 @@
1
+ RansackMemory::Core.config = {
2
+ param: :q, # this means the default Ransack param name for searching. You can change it
3
+ link_label: 'Clear filter' # clear_filter link label
4
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack_memory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lapiš
@@ -17,11 +17,14 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - README.md
20
- - app/controllers/concerns/ransack_memory.rb
20
+ - app/controllers/concerns/ransack_memory/concern.rb
21
21
  - app/helpers/ransack_memory_helper.rb
22
22
  - app/views/shared/_ransack_memory_clear_filter.html.haml
23
23
  - lib/generators/ransack_memory_generator.rb
24
24
  - lib/ransack_memory.rb
25
+ - lib/ransack_memory/engine.rb
26
+ - lib/ransack_memory/version.rb
27
+ - lib/templates/ransack_memory/ransack_memory_template.rb
25
28
  homepage: https://github.com/richardrails/ransack_memory
26
29
  licenses:
27
30
  - MIT