Class: JekyllAllCollections::AllCollectionsTag
- Inherits:
-
JekyllSupport::JekyllTag
- Object
- Liquid::Tag
- JekyllSupport::JekyllTag
- JekyllAllCollections::AllCollectionsTag
- Includes:
- JekyllPluginSupportVersion
- Defined in:
- lib/jekyll_all_collections/all_collections_tag.rb
Constant Summary
Constants included from JekyllPluginSupportVersion
JekyllPluginSupportVersion::VERSION
Instance Attribute Summary
Attributes inherited from JekyllSupport::JekyllTag
#argument_string, #helper, #line_number, #logger, #page, #site
Attributes included from JekyllSupportError
Class Method Summary collapse
-
.create_lambda_string(criteria) ⇒ Object
Descending sort keys are preceded by a minus sign, and reverse the order of comparison.
- .verify_sort_by_type(sort_by) ⇒ Object
Instance Method Summary collapse
-
#render_impl ⇒ String
Method prescribed by JekyllTag.
Methods inherited from JekyllSupport::JekyllTag
#initialize, #render, #set_error_context
Methods included from ToString
Methods included from JekyllSupportError
#exit_without_stack_trace, #format_error_message, #maybe_reraise_error, #remove_ansi_color, #warn_short_trace
Constructor Details
This class inherits a constructor from JekyllSupport::JekyllTag
Class Method Details
.create_lambda_string(criteria) ⇒ Object
Descending sort keys are preceded by a minus sign, and reverse the order of comparison
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jekyll_all_collections/all_collections_tag.rb', line 32 def self.create_lambda_string(criteria) criteria_lhs_array = [] criteria_rhs_array = [] verify_sort_by_type(criteria).each do |c| descending_sort = c.start_with? '-' c.delete_prefix! '-' abort("Error: '#{c}' is not a valid sort field. Valid field names are: #{CRITERIA.join ', '}") \ unless CRITERIA.include?(c) criteria_lhs_array << (descending_sort ? "b.#{c}" : "a.#{c}") criteria_rhs_array << (descending_sort ? "a.#{c}" : "b.#{c}") end "->(a, b) { [#{criteria_lhs_array.join(', ')}] <=> [#{criteria_rhs_array.join(', ')}] }" end |
.verify_sort_by_type(sort_by) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jekyll_all_collections/all_collections_tag.rb', line 46 def self.verify_sort_by_type(sort_by) case sort_by when Array sort_by when Enumerable sort_by.to_a when Date [sort_by.to_i] when String [sort_by] else abort "Error: @sort_by was specified as '#{sort_by}'; it must either be a string or an array of strings" end end |
Instance Method Details
#render_impl ⇒ String
Method prescribed by JekyllTag.
15 16 17 18 19 20 21 22 |
# File 'lib/jekyll_all_collections/all_collections_tag.rb', line 15 def render_impl parse_arguments # Defines instance variables like @sort_by sort_lambda = init_sort_by @sort_by generate_output sort_lambda rescue StandardError => e ::JekyllSupport.error_short_trace @logger, e # ::JekyllSupport.warn_short_trace @logger, e end |