Class: Jekyll::PaginateV2::AutoPages::Utils
- Inherits:
-
Object
- Object
- Jekyll::PaginateV2::AutoPages::Utils
- Defined in:
- lib/jekyll-paginate-v2-redux/autopages/utils.rb
Class Method Summary collapse
- .ap_index_posts_by(all_posts, index_key) ⇒ Object
-
.collect_all_docs(site_collections) ⇒ Object
Static: returns all documents from all collections defined in the hash of collections passed in excludes all pagination pages though.
-
.format_cat_macro(toFormat, category) ⇒ Object
Static: returns a fully formatted string with the category macro (:cat) replaced.
-
.format_coll_macro(toFormat, collection) ⇒ Object
Static: returns a fully formatted string with the collection macro (:coll) replaced.
-
.format_tag_macro(toFormat, tag) ⇒ Object
Static: returns a fully formatted string with the tag macro (:tag) replaced.
Class Method Details
.ap_index_posts_by(all_posts, index_key) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/jekyll-paginate-v2-redux/autopages/utils.rb', line 36 def self.ap_index_posts_by(all_posts, index_key) return nil if all_posts.nil? return all_posts if index_key.nil? index = {} for post in all_posts next if post.data.nil? next if !post.data.has_key?(index_key) next if post.data[index_key].nil? next if post.data[index_key].size <= 0 next if post.data[index_key].to_s.strip.length == 0 # Only tags and categories come as premade arrays, locale does not, so convert any data # elements that are strings into arrays post_data = post.data[index_key] if post_data.is_a?(String) post_data = post_data.split(/;|,|\s/) end for key in post_data key = key.strip # If the key is a delimetered list of values # (meaning the user didn't use an array but a string with commas) for raw_k_split in key.split(/;|,/) k_split = raw_k_split.to_s.downcase.strip #Clean whitespace and junk if !index.has_key?(k_split) # Need to store the original key value here so that I can present it to the users as a page variable they can use (unmodified, e.g. tags not being 'sci-fi' but "Sci-Fi") # Also, only interested in storing all the keys not the pages in this case index[k_split.to_s] = [k_split.to_s, raw_k_split.to_s] end end end end return index end |
.collect_all_docs(site_collections) ⇒ Object
Static: returns all documents from all collections defined in the hash of collections passed in excludes all pagination pages though
26 27 28 29 30 31 32 33 34 |
# File 'lib/jekyll-paginate-v2-redux/autopages/utils.rb', line 26 def self.collect_all_docs(site_collections) coll = [] for coll_name, coll_data in site_collections if !coll_data.nil? coll += coll_data.docs.select { |doc| !doc.data.has_key?('pagination') }.each{ |doc| doc.data['__coll'] = coll_name } # Exclude all pagination pages and then for every page store it's collection name end end return coll end |
.format_cat_macro(toFormat, category) ⇒ Object
Static: returns a fully formatted string with the category macro (:cat) replaced
14 15 16 |
# File 'lib/jekyll-paginate-v2-redux/autopages/utils.rb', line 14 def self.format_cat_macro(toFormat, category) return toFormat.sub(':cat', Jekyll::Utils.slugify(category.to_s)) end |
.format_coll_macro(toFormat, collection) ⇒ Object
Static: returns a fully formatted string with the collection macro (:coll) replaced
20 21 22 |
# File 'lib/jekyll-paginate-v2-redux/autopages/utils.rb', line 20 def self.format_coll_macro(toFormat, collection) return toFormat.sub(':coll', Jekyll::Utils.slugify(collection.to_s)) end |
.format_tag_macro(toFormat, tag) ⇒ Object
Static: returns a fully formatted string with the tag macro (:tag) replaced
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/autopages/utils.rb', line 8 def self.format_tag_macro(toFormat, tag) return toFormat.sub(':tag', Jekyll::Utils.slugify(tag.to_s)) end |