File: sorted_for.rb

package info (click to toggle)
lensfun 1%3A0.3.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,672 kB
  • sloc: xml: 52,273; cpp: 7,831; ansic: 7,411; python: 1,725; sh: 17; ruby: 16; makefile: 13; javascript: 3
file content (20 lines) | stat: -rw-r--r-- 551 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Jekyll
  class SortedForTag < Liquid::For
    def render(context)
      sorted_collection = context[@collection_name].dup
      sorted_collection = sorted_collection.sort_by { |i| i.to_liquid[@attributes['sort_by']] }

      sorted_collection_name = "#{@collection_name}_sorted".sub('.', '_')
      context[sorted_collection_name] = sorted_collection
      @collection_name = sorted_collection_name

      super
    end

    def end_tag
      'endsorted_for'
    end
  end
end

Liquid::Template.register_tag('sorted_for', Jekyll::SortedForTag)