ransack_abbreviator 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
1
  ## v0.0.1
2
2
 
3
- * initial release
3
+ * initial release
4
+
5
+ ## v0.0.2-0.0.5
6
+
7
+ * Don't use
8
+
9
+ ## v0.0.6
10
+
11
+ * First stable release
data/README.md CHANGED
@@ -1,7 +1,62 @@
1
1
  ## Ransack Abbreviator [![Build Status](https://travis-ci.org/jhdavids8/ransack-abbreviator.png?branch=master)](http://travis-ci.org/jhdavids8/ransack-abbreviator)
2
2
  ===================
3
3
 
4
+ [Ransack](https://github.com/ernie/ransack) is a gem that gives you the ability to create powerful search forms. Unfortunately though, the more fields you add to your form, the longer the URL gets, which usually forces you to use the HTTP POST method instead of GET, which can get annoying pretty quickly.
4
5
 
5
- ## To Do
6
+ Ransack Abbreviator uses defined abbreviations for columns and associations to shorten your query params and thus the URL generated by your search form. Hopefully, it allows you to avoid that POST.
7
+
8
+ ### Getting Started
9
+ In your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ransack_abbreviator'
13
+ ```
14
+
15
+ ### How to Use
16
+ The abbreviator should cause absolutely no problems if you decide to not use abbreviations. It only kicks in when an abbreviation is detected in the params. That said, here's how to use it:
17
+
18
+ #### Define Abbreviations
19
+ First, define some abbreviations for columns and associations that can be queried in your search form. You can create a ransack_abbreviator.yml file in your config directory in a structure like this:
20
+
21
+ ransack_abbreviations:
22
+ columns:
23
+ name: "nm"
24
+ title: "tl"
25
+ associations:
26
+ articles: "ars"
27
+ people: "ppl"
28
+
29
+ If you don't want to use a YAML file, define an initializer and add your abbreviations there.
30
+ ```ruby
31
+ RansackAbbreviator.configure do |config|
32
+ config.add_column_abbreviation(:name, :nm)
33
+ config.add_column_abbreviation(:title, :tl)
34
+ config.add_assoc_abbreviation(:articles, :ars)
35
+ config.add_assoc_abbreviation(:people, :ppl)
36
+ end
37
+ ```
38
+ #### Use the Abbreviated Attribute in your Form
39
+ In your form, pass the Ransack language you would normally use (along with the search object) to a helper called ransack_abbreviation_for:
40
+
41
+ <%= search_form_for @q do |f| %>
42
+ <%= f.text_field ransack_abbreviation_for(@q, :name_cont) %>
43
+ <%= f.text_field ransack_abbreviation_for(@q, :articles_title_start) %>
44
+ <%= f.submit %>
45
+ <% end %>
46
+
47
+ When the above form is submitted, what would have normally been a URL param of 'name_cont' is now 'nm_cont'. 'articles_title_start' is now 'ars.tl_start'.
48
+
49
+ See the [Ransack](https://github.com/ernie/ransack) documentation on how to reference associations, columns, and predicates.
50
+
51
+ #### Remove those POST hacks!
52
+ Hopefully, the URL is now at least half the size it could have been before and you can remove all the POST hacks you did to get pagination and whatnot to work correctly!
53
+
54
+ ### Some Notes
55
+ * ransack_abbreviation_for abbreviates what it can, and returns the full name for what it cannot. For example, if you forgot to abbreviate 'articles', then ransack_abbreviation_for(@q, :articles_title_start) would return 'articles.tl_start'
56
+
57
+ ### To Do
6
58
  * Support abbreviation of 'ransacker' attributes
7
- * Extend the 'attribute_select' form helper to support returning attributes as their abbreviations
59
+ * Extend the 'attribute_select' form helper to support returning attributes as their abbreviations
60
+
61
+ ### License and Copyright
62
+ MIT License. Copyright &copy; 2013 [Jamie Davidson](http://jamie-davidson.com)
@@ -15,7 +15,7 @@ module RansackAbbreviator
15
15
  fail "You used a reserved keyword as a column abbreviation. Reserverd keywords: #{RansackAbbreviator::Constants::RESERVED_KEYWORDS.join(", ")}"
16
16
  end
17
17
 
18
- self.column_abbreviations = abbreviations
18
+ @@column_abbreviations = abbreviations
19
19
  end
20
20
  end
21
21
 
@@ -25,7 +25,7 @@ module RansackAbbreviator
25
25
  fail "You used a reserved keyword as an association abbreviation. Reserverd keywords: #{RansackAbbreviator::Constants::RESERVED_KEYWORDS.join(", ")}"
26
26
  end
27
27
 
28
- self.assoc_abbreviations = abbreviations
28
+ @@assoc_abbreviations = abbreviations
29
29
  end
30
30
  end
31
31
 
@@ -58,7 +58,7 @@ module RansackAbbreviator
58
58
  end
59
59
 
60
60
  def config_dir
61
- defined?(Rails) ? Rails.root.join("config") : Pathname.new("config")
61
+ Pathname.new("config")
62
62
  end
63
63
  end
64
64
  end
@@ -0,0 +1,4 @@
1
+ module RansackAbbreviator
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module RansackAbbreviator
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,7 +1,10 @@
1
1
  require "ostruct"
2
2
  require "yaml"
3
+ require 'ransack'
3
4
  require 'ransack_abbreviator/configuration'
4
5
  require 'ransack_abbreviator/constants'
6
+ require 'ransack_abbreviator/engine' if defined? Rails
7
+
5
8
 
6
9
  module RansackAbbreviator
7
10
  extend Configuration
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ransack_abbreviator
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jamie Davidson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-02-04 00:00:00 Z
13
+ date: 2013-02-05 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ransack
@@ -102,6 +102,7 @@ files:
102
102
  - lib/ransack_abbreviator/adapters/active_record/base.rb
103
103
  - lib/ransack_abbreviator/configuration.rb
104
104
  - lib/ransack_abbreviator/constants.rb
105
+ - lib/ransack_abbreviator/engine.rb
105
106
  - lib/ransack_abbreviator/ransack_extensions/context.rb
106
107
  - lib/ransack_abbreviator/ransack_extensions/nodes/condition.rb
107
108
  - lib/ransack_abbreviator/ransack_extensions/search.rb