Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sorting for liquid for statements.
git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2531 567b1171-46fb-0310-a4c9-b4bef9110e78
- Loading branch information
technoweenie
committed
Dec 7, 2006
1 parent
b312360
commit ce99258
Showing
5 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Mephisto | ||
module Liquid | ||
module ForWithSorting | ||
def self.included(base) | ||
base.alias_method_chain :render, :sorting | ||
end | ||
|
||
def render_with_sorting(context) | ||
context.registers[:for] ||= Hash.new(0) | ||
|
||
collection = context[@collection_name] | ||
collection = collection.to_a if collection.is_a?(Range) | ||
|
||
return '' if collection.nil? or collection.empty? | ||
|
||
context[@collection_name] = collection.sort_by { |i| i[@attributes['sort_by']] } if @attributes['sort_by'] | ||
|
||
render_without_sorting(context) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters