Merge pull requests #220 from ldavin/add French locale and #226 from subosito/syntax-highlights

enable syntax highlighting on README
This commit is contained in:
jonatack 2013-05-23 14:49:04 +02:00
parent e3914b814f
commit 1b9bbb8dcf
2 changed files with 145 additions and 56 deletions

131
README.md
View File

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/ernie/ransack.png?branch=master)](https://travis-ci.org/ernie/ransack) [![Build Status](https://travis-ci.org/ernie/ransack.png?branch=master)](https://travis-ci.org/ernie/ransack)
Ransack is a rewrite of [MetaSearch](http://metautonomo.us/projects/metasearch). While it Ransack is a rewrite of [MetaSearch](https://github.com/ernie/meta_search). While it
supports many of the same features as MetaSearch, its underlying implementation differs supports many of the same features as MetaSearch, its underlying implementation differs
greatly from MetaSearch, and _backwards compatibility is not a design goal._ greatly from MetaSearch, and _backwards compatibility is not a design goal._
@ -10,18 +10,21 @@ Ransack enables the creation of both simple and [advanced](http://ransack-demo.h
search forms against your application's models. If you're looking for something that search forms against your application's models. If you're looking for something that
simplifies query generation at the model or controller layer, you're probably not looking simplifies query generation at the model or controller layer, you're probably not looking
for Ransack (or MetaSearch, for that matter). Try for Ransack (or MetaSearch, for that matter). Try
[Squeel](http://metautonomo.us/projects/squeel) instead. [Squeel](https://github.com/ernie/squeel) instead.
## Getting started ## Getting started
In your Gemfile: In your Gemfile:
gem "ransack" # Last officially released gem ```ruby
gem "ransack" # Last officially released gem
```
Or if you want to use the bleeding edge: Or if you want to use the bleeding edge:
gem "ransack", :git => "git://github.com/ernie/ransack.git" # Track git repo ```ruby
gem "ransack", :git => "git://github.com/ernie/ransack.git" # Track git repo
```
## Usage ## Usage
@ -55,20 +58,24 @@ If you're coming from MetaSearch, things to note:
In your controller: In your controller:
def index ```ruby
@q = Person.search(params[:q]) def index
@people = @q.result(:distinct => true) @q = Person.search(params[:q])
end @people = @q.result(:distinct => true)
end
```
In your view: In your view:
<%= search_form_for @q do |f| %> ```erb
<%= f.label :name_cont %> <%= search_form_for @q do |f| %>
<%= f.text_field :name_cont %> <%= f.label :name_cont %>
<%= f.label :articles_title_start %> <%= f.text_field :name_cont %>
<%= f.text_field :articles_title_start %> <%= f.label :articles_title_start %>
<%= f.submit %> <%= f.text_field :articles_title_start %>
<% end %> <%= f.submit %>
<% end %>
```
`cont` (contains) and `start` (starts with) are just two of the available search predicates. `cont` (contains) and `start` (starts with) are just two of the available search predicates.
See [Constants](https://github.com/ernie/ransack/blob/master/lib/ransack/constants.rb) for a full list and the [wiki](https://github.com/ernie/ransack/wiki/Basic-Searching) for more description. See [Constants](https://github.com/ernie/ransack/blob/master/lib/ransack/constants.rb) for a full list and the [wiki](https://github.com/ernie/ransack/wiki/Basic-Searching) for more description.
@ -83,23 +90,29 @@ parameter string will typically force you to use the HTTP POST method instead of
This means you'll need to tweak your routes... This means you'll need to tweak your routes...
resources :people do ```ruby
collection do resources :people do
match 'search' => 'people#search', :via => [:get, :post], :as => :search collection do
end match 'search' => 'people#search', :via => [:get, :post], :as => :search
end end
end
```
... and add another controller action ... ... and add another controller action ...
def search ```ruby
index def search
render :index index
end render :index
end
```
... and update your `search_form_for` line in the view ... ... and update your `search_form_for` line in the view ...
<%= search_form_for @q, :url => search_people_path, ```erb
:html => {:method => :post} do |f| %> <%= search_form_for @q, :url => search_people_path,
:html => {:method => :post} do |f| %>
```
Once you've done so, you can make use of the helpers in Ransack::Helpers::FormBuilder to Once you've done so, you can make use of the helpers in Ransack::Helpers::FormBuilder to
construct much more complex search forms, such as the one on the construct much more complex search forms, such as the one on the
@ -111,48 +124,54 @@ You can easily use Ransack to search in associated objects.
Given you have these associations ... Given you have these associations ...
class Employee < ActiveRecord::Base ```ruby
belongs_to :supervisor class Employee < ActiveRecord::Base
belongs_to :supervisor
# has attribute last_name:string # has attribute last_name:string
end end
class Department < ActiveRecord::Base class Department < ActiveRecord::Base
has_many :supervisors has_many :supervisors
# has attribute title:string # has attribute title:string
end end
class Supervisor < ActiveRecord::Base class Supervisor < ActiveRecord::Base
belongs_to :department belongs_to :department
has_many :employees has_many :employees
# has attribute last_name:string # has attribute last_name:string
end end
```
... and a controller ... ... and a controller ...
class SupervisorsController < ApplicationController ```ruby
def index class SupervisorsController < ApplicationController
@search = Supervisor.search(params[:q]) def index
@supervisors = @search.result(:distinct => true) @search = Supervisor.search(params[:q])
end @supervisors = @search.result(:distinct => true)
end end
end
```
... you might set up your form like this ... ... you might set up your form like this ...
<%= search_form_for @search do |f| %> ```erb
<%= f.label :last_name_cont %> <%= search_form_for @search do |f| %>
<%= f.text_field :last_name_cont %> <%= f.label :last_name_cont %>
<%= f.text_field :last_name_cont %>
<%= f.label :department_title_cont %> <%= f.label :department_title_cont %>
<%= f.text_field :department_title_cont %> <%= f.text_field :department_title_cont %>
<%= f.label :employees_last_name_cont %> <%= f.label :employees_last_name_cont %>
<%= f.text_field :employees_last_name_cont %> <%= f.text_field :employees_last_name_cont %>
<%= f.submit "search" %> <%= f.submit "search" %>
<% end %> <% end %>
```
## Contributions ## Contributions
@ -166,4 +185,4 @@ To support the project:
## Copyright ## Copyright
Copyright &copy; 2011 [Ernie Miller](http://twitter.com/erniemiller) Copyright &copy; 2011 [Ernie Miller](http://twitter.com/erniemiller)

70
lib/ransack/locale/fr.yml Normal file
View File

@ -0,0 +1,70 @@
fr:
ransack:
search: "recherche"
predicate: "prédicat"
and: "et"
or: "ou"
any: "au moins un"
all: "tous"
combinator: "combinateur"
attribute: "attribut"
value: "valeur"
condition: "condition"
sort: "tri"
asc: "ascendant"
desc: "descendant"
predicates:
eq: "égal à"
eq_any: "égal à au moins un"
eq_all: "égal à tous"
not_eq: "différent de"
not_eq_any: "différent d'au moins un"
not_eq_all: "différent de tous"
matches: "correspond à"
matches_any: "correspond à au moins un"
matches_all: "correspond à tous"
does_not_match: "ne correspond pas à"
does_not_match_any: "ne correspond pas à au moins un"
does_not_match_all: "ne correspond à aucun"
lt: "inférieur à"
lt_any: "inférieur à au moins un"
lt_all: "inférieur à tous"
lteq: "inférieur ou égal à"
lteq_any: "inférieur ou égal à au moins un"
lteq_all: "inférieur ou égal à tous"
gt: "supérieur à"
gt_any: "supérieur à au moins un"
gt_all: "supérieur à tous"
gteq: "supérieur ou égal à"
gteq_any: "supérieur ou égal à au moins un"
gteq_all: "supérieur ou égal à tous"
in: "inclus dans"
in_any: "inclus dans au moins un"
in_all: "inclus dans tous"
not_in: "non inclus dans"
not_in_any: "non inclus dans au moins un"
not_in_all: "non inclus dans tous"
cont: "contient"
cont_any: "contient au moins un"
cont_all: "contient tous"
not_cont: "ne contient pas"
not_cont_any: "ne contient pas au moins un"
not_cont_all: "ne contient pas tous"
start: "commence par"
start_any: "commence par au moins un"
start_all: "commence par tous"
not_start: "ne commence pas par"
not_start_any: "ne commence pas par au moins un"
not_start_all: "ne commence pas par tous"
end: "finit par"
end_any: "finit par au moins un"
end_all: "finit par tous"
not_end: "ne finit pas par"
not_end_any: "ne finit pas par au moins un"
not_end_all: "ne finit pas par tous"
'true': "est vrai"
'false': "est faux"
present: "est présent"
blank: "est blanc"
'null': "est null"
not_null: "n'est pas null"