Sha256: 29dcb7e5070e56e2b03c73633e82102d600ca9593a3609f1dae5b3d6403d7125

Contents?: true

Size: 1003 Bytes

Versions: 2

Compression:

Stored size: 1003 Bytes

Contents

# Drops are for lazy-loading content.
#  - http://www.rubydoc.info/github/Shopify/liquid/Liquid/Drop
#  - https://github.com/Shopify/liquid/blob/master/lib/liquid/drop.rb

module Landable
  module Liquid
    # CategoryProxy gives us these:
    #
    # {{ categories.size }}
    #
    # {% for category in categories %}
    #   {{ category.name }}: {{ category.pages.size }} pages
    # {% endfor %}
    #
    # <h1>Blog posts</h1>
    # <ul>
    #   {% for page in categories.blog.pages %}
    #     <li><a href="{{ page.url }}">{{ page.name }}</a></li>
    #   {% endfor %}
    # </ul>
    class CategoriesDrop < ::Liquid::Drop
      def before_method(method_name)
        category_cache[method_name] ||= ::Landable::Category.find_by_slug method_name
      end

      def size
        @size ||= Category.count
      end

      def each(&block)
        ::Landable::Category.all.each(&block)
      end

      protected

      def category_cache
        @category_cache ||= {}
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
landable-1.14.0 lib/landable/liquid/drops.rb
landable-1.13.2 lib/landable/liquid/drops.rb