Permalink
Browse files

Released v1.0

  • Loading branch information...
1 parent ed74cec commit 6ad15264a7ba7d65eefcc716186c869b01a1bd73 @binarylogic committed Sep 9, 2008
View
@@ -1,3 +1,5 @@
+v1.0.0. Major changes in the helpers, they were completely re-engineered. Much nicer and cleaner now. I established a pattern between all helpers giving you complete flexibility as to how they are used. All helpers are called differently now (see documentation).
+
v0.9.10. Hardened more tests, fixed bug with setting the per_page configuration to only take effect on protected searches, thus staying out of the way of normal searching.
v0.9.9. Fixed setting per_page to nil, false, or ''. This is done to "show all" results.
View
@@ -22,9 +22,16 @@ lib/searchgasm/condition/tree.rb
lib/searchgasm/conditions/base.rb
lib/searchgasm/conditions/protection.rb
lib/searchgasm/config.rb
-lib/searchgasm/helpers/form_helper.rb
-lib/searchgasm/helpers/search_helper.rb
-lib/searchgasm/helpers/utilities_helper.rb
+lib/searchgasm/helpers/control_types/link.rb
+lib/searchgasm/helpers/control_types/links.rb
+lib/searchgasm/helpers/control_types/remote_link.rb
+lib/searchgasm/helpers/control_types/remote_links.rb
+lib/searchgasm/helpers/control_types/remote_select.rb
+lib/searchgasm/helpers/control_types/select.rb
+lib/searchgasm/helpers/control_types.rb
+lib/searchgasm/helpers/form.rb
+lib/searchgasm/helpers/utilities.rb
+lib/searchgasm/helpers.rb
lib/searchgasm/search/base.rb
lib/searchgasm/search/conditions.rb
lib/searchgasm/search/ordering.rb
View
@@ -84,19 +84,21 @@ Your view:
%table
%tr
- %th= order_by :first_name
- %th= order_by :last_name
- %th= order_by :email
+ %th= order_by_link :account => :name
+ %th= order_by_link :first_name
+ %th= order_by_link :last_name
+ %th= order_by_link :email
- @users.each do |user|
- %tr
- %td= user.first_name
- %td= user.last_name
- %td= user.email
+ %tr
+ %td= user.account? ? user.account.name : "-"
+ %td= user.first_name
+ %td= user.last_name
+ %td= user.email
Per page:
- = per_page
+ = per_page_select
Page:
- = pages
+ = page_select
<b>{See my tutorial on this example}(http://www.binarylogic.com/2008/9/7/tutorial-pagination-ordering-and-searching-with-searchgasm)</b>
@@ -253,6 +255,8 @@ If there is one thing we all know, it's to always use protection against SQL inj
search = Account.new_search!(params[:search])
conditions = Account.new_conditions!(params[:conditions])
+I'm sure you already knew this, but it's tempting to do this when you can pass the params hash right into these methods.
+
Lesson learned: use new\_search and new\_conditions when passing in params as *ANY* of the options.
== Available Conditions
View
@@ -40,9 +40,14 @@
require "searchgasm/condition/sibling_of"
# Helpers
-require "searchgasm/helpers/utilities_helper"
-require "searchgasm/helpers/form_helper"
-require "searchgasm/helpers/search_helper"
+require "searchgasm/helpers/utilities"
+require "searchgasm/helpers/form"
+require "searchgasm/helpers/control_types/link"
+require "searchgasm/helpers/control_types/links"
+require "searchgasm/helpers/control_types/select"
+require "searchgasm/helpers/control_types/remote_link"
+require "searchgasm/helpers/control_types/remote_links"
+require "searchgasm/helpers/control_types/remote_select"
# Lets do it!
module Searchgasm
View
@@ -43,31 +43,6 @@ def desc_indicator=(value)
@desc_indicator = value
end
- def pages_text # :nodoc:
- @set_pages_text ? @pages_text : "Page %p"
- end
-
- # The default value for the :text options in the pages helper.
- #
- # * <tt>Default:</tt> "Page %p"
- # * <tt>Accepts:</tt> "Your string %p": where %p is replaced by the page number, or a block: Proc.new { |p| "Page #{p}" }
- def pages_text=(value)
- @set_pages_text = true
- @pages_text
- end
-
- def pages_type # :nodoc:
- @pages_type ||= :select
- end
-
- # The default value for the :type option in the pages helper.
- #
- # * <tt>Default:</tt> :select
- # * <tt>Accepts:</tt> :select, :links
- def pages_type=(value)
- @pages_type = value.to_sym
- end
-
def per_page # :nodoc:
@per_page
end
@@ -95,69 +70,17 @@ def per_page_choices=(value)
@per_page_choices = value
end
- def per_page_type # :nodoc:
- @per_page_type ||= :select
- end
-
- # The default value for the :type option in the per_page helper.
- #
- # * <tt>Default:</tt> :select
- # * <tt>Accepts:</tt> :select, :links
- def per_page_type=(value)
- @per_page_type = value.to_sym
- end
-
def hidden_fields # :nodoc:
@hidden_fields ||= (Search::Base::SPECIAL_FIND_OPTIONS - [:page])
end
- # Which hidden fields to automatically include when creating a form with a Searchgasm object. See Searchgasm::Helpers::FormHelper for more info.
+ # Which hidden fields to automatically include when creating a form with a Searchgasm object. See Searchgasm::Helpers::Form for more info.
#
# * <tt>Default:</tt> [:order_by, :order_as, :per_page]
# * <tt>Accepts:</tt> Array, nil, false
def hidden_fields=(value)
@hidden_fields = value
end
-
- def remote_helpers # :nodoc:
- @remote_helpers ||= false
- end
-
- # Tells all helpers to default to using remote links (AJAX) instead of normal links.
- #
- # * <tt>Default:</tt> false
- # * <tt>Accepts:</tt> Boolean
- #
- # nil means "Show all"
- def remote_helpers=(value)
- @remote_helpers = value
- end
-
- def remote_helpers? # :nodoc:
- remote_helpers == true
- end
-
- def search_scope # :nodoc:
-
- end
-
- def search_obj_name # :nodoc:
- @search_obj_name ||= :@search
- end
-
- # The instance variable name you use to assign your search to. This allows the helpers to grab your Searchgasm object without having
- # to specify it everywhere.
- #
- # * <tt>Default:</tt> :@search
- # * <tt>Accepts:</tt> String or Symbol.
- #
- # === Examples
- #
- # config.search_obj_name = :@search
- # config.search_obj_name = "@search"
- def search_obj_name=(value)
- @search_obj_name = value
- end
end
end
end
@@ -0,0 +1,3 @@
+module Searchgasm
+ module Helpers #:nodoc:
+ module UtilitiesHelper # :nodoc:
@@ -0,0 +1,41 @@
+module Searchgasm
+ module Helpers
+ # = Control Type Helpers
+ #
+ # The purpose of these helpers is to make ordering and paginating data, in your view, a breeze. Everyone has their own flavor of displaying data, so I made these helpers extra flexible, just for you.
+ #
+ # === How it's organized
+ #
+ # Basically you can do 4 different things in your with with your data:
+ #
+ # 1. Order your data by a single column or an array of columns
+ # 2. Descend or ascend your data
+ # 3. Change how many items are on each page
+ # 4. Paginate through your data
+ #
+ # Each one of these actions comes with 3 different types of helpers:
+ #
+ # 1. Link - A single link for a single value. Requires that you pass a value as the first parameter.
+ # 2. Group of links - A group of single links.
+ # 3. Select - A select with choices that perform an action once selected. Basically the same thing as a group of links, but just as a select form element
+ #
+ # === Examples
+ #
+ # Sometimes the best way to explain something is with some examples. Let's pretend we are performing these actions on a User model. Check it out:
+ #
+ # order_by_link(:name)
+ # => produces a single link that when clicked will order by the name column, and each time its clicked alternated between "ASC" and "DESC"
+ #
+ # order_by_links
+ # => produces a group of links for all of the columns in your users table, each link is basically order_by_link(column.name)
+ #
+ # order_by_select
+ # => produces a select form element with all of the user's columns as choices, when the value is change (onchange) it will act as if they clicked a link.
+ # => This is just order_by_links as a select form element, nothing fancy
+ #
+ # You can apply the _link, _links, or _select to any of the following: order_by, order_as, per_page, page. You have your choice on how you want to set up the interface. For more information and options on these individual
+ # helpers check out their source files. Look at the sub modules under this one (Ex: Searchgasm::Helpers::ControlTypes::Select)
+ module ControlTypes
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 6ad1526

Please sign in to comment.