Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `generate' #6

Open
bagwaa opened this issue Jan 9, 2014 · 6 comments
Open

undefined method `generate' #6

bagwaa opened this issue Jan 9, 2014 · 6 comments

Comments

@bagwaa
Copy link

bagwaa commented Jan 9, 2014

I did the following :-

  1. I dropped this file inside my _plugins folder (category_pagination.rb)
  2. I created two directories (blog and screencast)
  3. I added an index.html file in each folder which contained ...

{% for post in paginator.posts %}

....

I then run jekyll build

This is the error I get back during the build process ...

Generating... error: undefined method `generate' for #Jekyll::Pagination:0x007fcd64121270

@zenorocha
Copy link

Same for me.

@ghost
Copy link

ghost commented Apr 16, 2014

Me as well.

@benxtan
Copy link

benxtan commented May 27, 2014

I'm running jekyll 2.0.3 and heres the customised code I'm using to achieve pagination by post category:

module Jekyll
  module Paginate
    class Pagination < Generator
      # This generator is safe from arbitrary code execution.
      safe true

      # This generator should be passive with regard to its execution
      priority :lowest

      # Generate paginated pages if necessary.
      #
      # site - The Site.
      #
      # Returns nothing.
      def generate(site)
        if Pager.pagination_enabled?(site)
          if template = template_page(site)
            paginate(site, template)
          else
            Jekyll.logger.warn "Pagination:", "Pagination is enabled, but I couldn't find " +
            "an index.html page to use as the pagination template. Skipping pagination."
          end
        end
      end

      # Paginates the blog's posts. Renders the index.html file into paginated
      # directories, e.g.: page2/index.html, page3/index.html, etc and adds more
      # site-wide data.
      #
      # site - The Site.
      # page - The index.html Page that requires pagination.
      #
      # {"paginator" => { "page" => <Number>,
      #                   "per_page" => <Number>,
      #                   "posts" => [<Post>],
      #                   "total_posts" => <Number>,
      #                   "total_pages" => <Number>,
      #                   "previous_page" => <Number>,
      #                   "next_page" => <Number> }}
      def paginate(site, page)
        category = page.dir.split('/').last
        if category != nil and site.site_payload['site']['categories'].has_key? category
            # If we're in a category's folder, paginate by category.
            all_posts = site.site_payload['site']['categories'][category]
        else
            all_posts = site.site_payload['site']['posts']
        end

        pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i)
        (1..pages).each do |num_page|
          pager = Pager.new(site, num_page, all_posts, pages)
          if num_page > 1
            newpage = Page.new(site, site.source, page.dir, page.name)
            newpage.pager = pager
            newpage.dir = Pager.paginate_path(site, num_page)
            site.pages << newpage
          else
            page.pager = pager
          end
        end
      end

      # Static: Fetch the URL of the template page. Used to determine the
      #         path to the first pager in the series.
      #
      # site - the Jekyll::Site object
      #
      # Returns the url of the template page
      def self.first_page_url(site)
        if page = Pagination.new.template_page(site)
          page.url
        else
          nil
        end
      end

      # Public: Find the Jekyll::Page which will act as the pager template
      #
      # site - the Jekyll::Site object
      #
      # Returns the Jekyll::Page which will act as the pager template
      def template_page(site)
        site.pages.dup.select do |page|
          Pager.pagination_candidate?(site.config, page)
        end.sort do |one, two|
          two.path.size <=> one.path.size
        end.first
      end

    end
  end
end

@ssorallen
Copy link

@benxtan When using your code, the only pagination that works is the one defined by paginate_path in _config.yml. Are there are config settings you changed to support multiple paginated categories?

@benxtan
Copy link

benxtan commented Jul 8, 2014

Hmm, good question. In my case, I only needed one of my categories to have pages.

@rafaelstz
Copy link

Me too

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants