pax_global_header00006660000000000000000000000064137376346120014526gustar00rootroot0000000000000052 comment=96319a93e8c42b4b09367d91c009fdda9c445197 jekyll-include-cache-0.2.1/000077500000000000000000000000001373763461200155025ustar00rootroot00000000000000jekyll-include-cache-0.2.1/.github/000077500000000000000000000000001373763461200170425ustar00rootroot00000000000000jekyll-include-cache-0.2.1/.github/CODEOWNERS000066400000000000000000000002461373763461200204370ustar00rootroot00000000000000# Require @benbalter's :+1: for changes to the .github repo-config files # mainly due to https://github.com/probot/settings privilege escalation .github/* @benbalter jekyll-include-cache-0.2.1/.github/ISSUE_TEMPLATE/000077500000000000000000000000001373763461200212255ustar00rootroot00000000000000jekyll-include-cache-0.2.1/.github/ISSUE_TEMPLATE/bug_report.md000066400000000000000000000010071373763461200237150ustar00rootroot00000000000000--- name: Bug report about: Create a report to help us improve --- ### Describe the bug A clear and concise description of what the bug is. ### Steps to reproduce the behavior 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error ### Expected behavior A clear and concise description of what you expected to happen. ### Screenshots If applicable, add screenshots to help explain your problem. ### Additional context Add any other context about the problem here. jekyll-include-cache-0.2.1/.github/ISSUE_TEMPLATE/feature_request.md000066400000000000000000000011541373763461200247530ustar00rootroot00000000000000--- name: Feature request about: Suggest an idea for this project --- ### Is your feature request related to a problem? Please describe the problem you're trying to solve. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] ### Describe the solution you'd like A clear and concise description of what you want to happen. ### Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. ### Additional context Add any other context or screenshots about the feature request here. jekyll-include-cache-0.2.1/.github/config.yml000066400000000000000000000035011373763461200210310ustar00rootroot00000000000000# Behaviorbot config. See https://github.com/behaviorbot/ for more information. # Note: Please Don't edit this file directly. # Edit https://github.com/benbalter/shared-community-files instead. # Configuration for update-docs - https://github.com/behaviorbot/update-docs updateDocsComment: "Thanks for the pull request! If you are making any changes to the user-facing functionality, please be sure to update the documentation in the `README` or `docs/` folder alongside your change. :heart:" # Configuration for request-info - https://github.com/behaviorbot/request-info requestInfoReplyComment: Thanks for this. Do you mind providing a bit more information about what problem you're trying to solve? requestInfoLabelToAdd: more-information-needed # Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome #newIssueWelcomeComment: > # Welcome! # Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome newPRWelcomeComment: Welcome! Congrats on your first pull request to Jekyll Include Cache. If you haven't already, please be sure to check out [the contributing guidelines](https://github.com/benbalter/jekyll-include-cache/blob/master/docs/CONTRIBUTING.md). # Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge firstPRMergeComment: "Congrats on getting your first pull request to Jekyll Include Cache merged! Without amazing humans like you submitting pull requests, we couldn’t run this project. You rock! :tada:

If you're interested in tackling another bug or feature, take a look at [the open issues](https://github.com/benbalter/jekyll-include-cache/issues), especially those [labeled `help wanted`](https://github.com/benbalter/jekyll-include-cache/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)." # Bug workaround contact_links: [] jekyll-include-cache-0.2.1/.github/funding.yml000066400000000000000000000000231373763461200212120ustar00rootroot00000000000000patreon: benbalter jekyll-include-cache-0.2.1/.github/no-response.yml000066400000000000000000000014631373763461200220410ustar00rootroot00000000000000# Configuration for probot-no-response - https://github.com/probot/no-response # Note: Please Don't edit this file directly. # Edit https://github.com/benbalter/shared-community-files instead. # Number of days of inactivity before an Issue is closed for lack of response daysUntilClose: 14 # Label requiring a response responseRequiredLabel: more-information-needed # Comment to post when closing an Issue for lack of response. Set to `false` to disable closeComment: > This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further. jekyll-include-cache-0.2.1/.github/release-drafter.yml000066400000000000000000000000541373763461200226310ustar00rootroot00000000000000template: | ## What's Changed $CHANGES jekyll-include-cache-0.2.1/.github/settings.yml000066400000000000000000000015101373763461200214220ustar00rootroot00000000000000# Repository settings set via https://github.com/probot/settings # Note: Please Don't edit this file directly. # Edit https://github.com/benbalter/shared-community-files instead. repository: has_issues: true has_wiki: false has_projects: false has_downloads: false labels: - name: help wanted oldname: help-wanted color: 0e8a16 - name: more-information-needed color: d93f0b - name: bug color: b60205 - name: feature color: 1d76db - name: good first issue color: "5319e7" # Not currently implemented by probot/settings, but manually implemented in script/deploy branch_protection: restrictions: null enforce_admins: false required_status_checks: strict: true contexts: - "continuous-integration/travis-ci" required_pull_request_reviews: require_code_owner_reviews: true jekyll-include-cache-0.2.1/.github/stale.yml000066400000000000000000000017121373763461200206760ustar00rootroot00000000000000# Configuration for probot-stale - https://github.com/probot/stale # Note: Please Don't edit this file directly. # Edit https://github.com/benbalter/shared-community-files instead. # Number of days of inactivity before an Issue or Pull Request becomes stale daysUntilStale: 60 # Number of days of inactivity before a stale Issue or Pull Request is closed daysUntilClose: 7 # Issues or Pull Requests with these labels will never be considered stale exemptLabels: - pinned - security # Label to use when marking as stale staleLabel: wontfix # Comment to post when marking as stale. Set to `false` to disable markComment: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. # Comment to post when closing a stale Issue or Pull Request. Set to `false` to disable closeComment: false # Limit to only `issues` or `pulls` # only: issues jekyll-include-cache-0.2.1/.gitignore000066400000000000000000000001161373763461200174700ustar00rootroot00000000000000spec/examples.txt *.gem Gemfile.lock /tmp vendor/bundle .bundle .jekyll-cache jekyll-include-cache-0.2.1/.rspec000066400000000000000000000000361373763461200166160ustar00rootroot00000000000000--color --require spec_helper jekyll-include-cache-0.2.1/.rubocop.yml000066400000000000000000000002411373763461200177510ustar00rootroot00000000000000require: rubocop-jekyll inherit_gem: rubocop-jekyll: .rubocop.yml AllCops: Exclude: - vendor/**/* Metrics/BlockLength: Exclude: - spec/**/* jekyll-include-cache-0.2.1/.travis.yml000066400000000000000000000002131373763461200176070ustar00rootroot00000000000000language: ruby script: script/cibuild sudo: false cache: bundler env: - JEKYLL_VERSION="~> 3.0" - JEKYLL_VERSION=">= 4.0.0.pre.alpha1" jekyll-include-cache-0.2.1/Gemfile000066400000000000000000000002041373763461200167710ustar00rootroot00000000000000# frozen_string_literal: true source "https://rubygems.org" gemspec gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"] jekyll-include-cache-0.2.1/LICENSE.md000066400000000000000000000020531373763461200171060ustar00rootroot00000000000000MIT License Copyright (c) 2016 Ben Balter Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jekyll-include-cache-0.2.1/README.md000066400000000000000000000031301373763461200167560ustar00rootroot00000000000000# Jekyll Include Cache *A Jekyll plugin to cache the rendering of Liquid includes* [![Build Status](https://travis-ci.org/benbalter/jekyll-include-cache.svg?branch=master)](https://travis-ci.org/benbalter/jekyll-include-cache) ## What it does If you have a computationally expensive include (such as a sidebar or navigation), Jekyll Include Cache renders the include once, and then reuses the output any time that includes is called with the same arguments, potentially speeding up your site's build significantly. ## Usage 1. Add the following to your site's Gemfile: ```ruby gem 'jekyll-include-cache' ``` 2. Add the following to your site's config file: ```yml plugins: - jekyll-include-cache ``` 💡 If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`. 3. Replace `{% include foo.html %}` in your template with `{% include_cached foo.html %}` ## One potential gotcha For Jekyll Include Cache to work, you cannot rely on the page context to pass variables to your include (e.g., `assign foo=bar` or `page.title`). Instead, you must explicitly pass all variables to the include as arguments, and reference them within the include as `include.foo` (instead of `page.foo` or just `foo`). ### Good In your template: ```liquid {% include_cached shirt.html size=medium color=red %} ``` In your include: ```liquid Buy our {{ include.color }} shirt in {{ include.size }}! ``` ### Bad In your template: ```liquid {% assign color=blue %} {% include_cached shirt.html %} ``` In your include: ```liquid Buy our {{ color }} shirt in {{ page.size }}! ``` jekyll-include-cache-0.2.1/docs/000077500000000000000000000000001373763461200164325ustar00rootroot00000000000000jekyll-include-cache-0.2.1/docs/CODE_OF_CONDUCT.md000066400000000000000000000062131373763461200212330ustar00rootroot00000000000000# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at ben@balter.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ jekyll-include-cache-0.2.1/docs/CONTRIBUTING.md000066400000000000000000000133121373763461200206630ustar00rootroot00000000000000# Contributing to Jekyll Include Cache Hi there! We're thrilled that you'd like to contribute to Jekyll Include Cache. Your help is essential for keeping it great. Jekyll Include Cache is an open source project supported by the efforts of an entire community and built one contribution at a time by users like you. We'd love for you to get involved. Whatever your level of skill or however much time you can give, your contribution is greatly appreciated. There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests, helping other users by commenting on issues, or writing code which can be incorporated into Jekyll Include Cache itself. Following these guidelines helps to communicate that you respect the time of the developers managing and developing this open source project. In return, they should reciprocate that respect in addressing your issue, assessing changes, and helping you finalize your pull requests. ## How to report a bug Think you found a bug? Please check [the list of open issues](https://github.com/benbalter/jekyll-include-cache/issues) to see if your bug has already been reported. If it hasn't please [submit a new issue](https://github.com/benbalter/jekyll-include-cache/issues/new). Here are a few tips for writing *great* bug reports: * Describe the specific problem (e.g., "widget doesn't turn clockwise" versus "getting an error") * Include the steps to reproduce the bug, what you expected to happen, and what happened instead * Check that you are using the latest version of the project and its dependencies * Include what version of the project your using, as well as any relevant dependencies * Only include one bug per issue. If you have discovered two bugs, please file two issues * Include screenshots or screencasts whenever possible * Even if you don't know how to fix the bug, including a failing test may help others track it down **If you find a security vulnerability, do not open an issue. Please email ben@balter.com instead.** ## How to suggest a feature or enhancement If you find yourself wishing for a feature that doesn't exist in Jekyll Include Cache, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that Jekyll Include Cache has today have been added because our users saw the need. Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and goals of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible, including describing the problem you're trying to solve. [Open an issue](https://github.com/benbalter/jekyll-include-cache/issues/new) which describes the feature you would like to see, why you want it, how it should work, etc. ## Your first contribution We'd love for you to contribute to the project. Unsure where to begin contributing to Jekyll Include Cache? You can start by looking through these "good first issue" and "help wanted" issues: * [Good first issues](https://github.com/benbalter/jekyll-include-cache/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) - issues which should only require a few lines of code and a test or two * [Help wanted issues](https://github.com/benbalter/jekyll-include-cache/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) - issues which may be a bit more involved, but are specifically seeking community contributions *p.s. Feel free to ask for help; everyone is a beginner at first* :smiley_cat: ## How to propose changes Here's a few general guidelines for proposing changes: * If you are changing any user-facing functionality, please be sure to update the documentation * If you are adding a new behavior or changing an existing behavior, please be sure to update the corresponding test(s) * Each pull request should implement **one** feature or bug fix. If you want to add or fix more than one thing, submit more than one pull request * Do not commit changes to files that are irrelevant to your feature or bug fix * Don't bump the version number in your pull request (it will be bumped prior to release) * Write [a good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) At a high level, [the process for proposing changes](https://guides.github.com/introduction/flow/) is: 1. [Fork](https://github.com/benbalter/jekyll-include-cache/fork) and clone the project 2. Configure and install the dependencies: `script/bootstrap` 3. Make sure the tests pass on your machine: `script/cibuild` 4. Create a descriptively named branch: `git checkout -b my-branch-name` 5. Make your change, add tests and documentation, and make sure the tests still pass 6. Push to your fork and [submit a pull request](https://github.com/benbalter/jekyll-include-cache/compare) describing your change 7. Pat your self on the back and wait for your pull request to be reviewed and merged **Interesting in submitting your first Pull Request?** It's easy! You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github) ## Bootstrapping your local development environment `script/bootstrap` ## Running tests `script/cibuild` ## Code of conduct This project is governed by [the Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. ## Additional Resources * [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/) * [Using Pull Requests](https://help.github.com/articles/using-pull-requests/) * [GitHub Help](https://help.github.com) jekyll-include-cache-0.2.1/docs/SECURITY.md000066400000000000000000000001551373763461200202240ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please email [ben@balter.com](mailto:ben@balter.com). jekyll-include-cache-0.2.1/jekyll-include-cache.gemspec000066400000000000000000000015061373763461200230250ustar00rootroot00000000000000# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path("lib", __dir__) require "jekyll-include-cache/version" Gem::Specification.new do |s| s.name = "jekyll-include-cache" s.version = JekyllIncludeCache::VERSION s.authors = ["Ben Balter"] s.email = ["ben.balter@github.com"] s.homepage = "https://github.com/benbalter/jekyll-include-cache" s.summary = "A Jekyll plugin to cache the rendering of Liquid includes" s.files = `git ls-files app lib`.split("\n") s.platform = Gem::Platform::RUBY s.require_paths = ["lib"] s.license = "MIT" s.add_dependency "jekyll", ">= 3.7", "< 5.0" s.add_development_dependency "rspec", "~> 3.5" s.add_development_dependency "rubocop", "~> 0.51" s.add_development_dependency "rubocop-jekyll", "~> 0.3" end jekyll-include-cache-0.2.1/lib/000077500000000000000000000000001373763461200162505ustar00rootroot00000000000000jekyll-include-cache-0.2.1/lib/jekyll-include-cache.rb000066400000000000000000000011611373763461200225500ustar00rootroot00000000000000# frozen_string_literal: true require "jekyll" module JekyllIncludeCache autoload :Tag, "jekyll-include-cache/tag" autoload :Cache, "jekyll-include-cache/cache" class << self def cache @cache ||= if defined? Jekyll::Cache Jekyll::Cache.new(self.class.name) else JekyllIncludeCache::Cache.new end end def reset JekyllIncludeCache.cache.clear end end end Liquid::Template.register_tag("include_cached", JekyllIncludeCache::Tag) Jekyll::Hooks.register :site, :pre_render do |_site| JekyllIncludeCache.reset end jekyll-include-cache-0.2.1/lib/jekyll-include-cache/000077500000000000000000000000001373763461200222245ustar00rootroot00000000000000jekyll-include-cache-0.2.1/lib/jekyll-include-cache/cache.rb000066400000000000000000000010301373763461200236060ustar00rootroot00000000000000# frozen_string_literal: true # Jekyll 4.x comptable caching class for pre-4.x compatability module JekyllIncludeCache class Cache extend Forwardable def_delegators :@cache, :[]=, :key?, :delete, :clear def initialize(_name = nil) @cache = {} end def getset(key) if key?(key) @cache[key] else value = yield @cache[key] = value value end end def [](key) if key?(key) @cache[key] else raise end end end end jekyll-include-cache-0.2.1/lib/jekyll-include-cache/tag.rb000066400000000000000000000032611373763461200233260ustar00rootroot00000000000000# frozen_string_literal: true require "digest/md5" module JekyllIncludeCache class Tag < Jekyll::Tags::IncludeTag def self.digest_cache @digest_cache ||= {} end def render(context) path = path(context) params = parse_params(context) if @params key = key(path, params) return unless path if JekyllIncludeCache.cache.key?(key) Jekyll.logger.debug "Include cache hit:", path JekyllIncludeCache.cache[key] else Jekyll.logger.debug "Include cache miss:", path JekyllIncludeCache.cache[key] = super end end private def path(context) site = context.registers[:site] file = render_variable(context) || @file locate_include_file(context, file, site.safe) end def key(path, params) path_hash = path.hash params_hash = quick_hash(params) self.class.digest_cache[path_hash] ||= {} self.class.digest_cache[path_hash][params_hash] ||= digest(path_hash, params_hash) end def quick_hash(params) return params.hash unless params md5 = Digest::MD5.new params.sort.each do |_, value| # Using the fact that Jekyll documents don't change during a build. # Instead of calculating the hash of an entire document (expensive!) # we just use its object id. if value.is_a? Jekyll::Drops::Drop md5.update value.object_id.to_s else md5.update value.hash.to_s end end md5.hexdigest end def digest(path_hash, params_hash) md5 = Digest::MD5.new md5.update path_hash.to_s md5.update params_hash.to_s md5.hexdigest end end end jekyll-include-cache-0.2.1/lib/jekyll-include-cache/version.rb000066400000000000000000000001211373763461200242300ustar00rootroot00000000000000# frozen_string_literal: true module JekyllIncludeCache VERSION = "0.2.1" end jekyll-include-cache-0.2.1/script/000077500000000000000000000000001373763461200170065ustar00rootroot00000000000000jekyll-include-cache-0.2.1/script/bootstrap000077500000000000000000000000321373763461200207440ustar00rootroot00000000000000#!/bin/sh bundle install jekyll-include-cache-0.2.1/script/cibuild000077500000000000000000000001461373763461200203500ustar00rootroot00000000000000#!/bin/sh set -e bundle exec rspec bundle exec rubocop -S -D gem build jekyll-include-cache.gemspec jekyll-include-cache-0.2.1/spec/000077500000000000000000000000001373763461200164345ustar00rootroot00000000000000jekyll-include-cache-0.2.1/spec/fixtures/000077500000000000000000000000001373763461200203055ustar00rootroot00000000000000jekyll-include-cache-0.2.1/spec/fixtures/site/000077500000000000000000000000001373763461200212515ustar00rootroot00000000000000jekyll-include-cache-0.2.1/spec/fixtures/site/_includes/000077500000000000000000000000001373763461200232165ustar00rootroot00000000000000jekyll-include-cache-0.2.1/spec/fixtures/site/_includes/foo.html000066400000000000000000000000151373763461200246630ustar00rootroot00000000000000Some content jekyll-include-cache-0.2.1/spec/jekyll-include-tag/000077500000000000000000000000001373763461200221205ustar00rootroot00000000000000jekyll-include-cache-0.2.1/spec/jekyll-include-tag/cache_spec.rb000066400000000000000000000023571373763461200245310ustar00rootroot00000000000000# frozen_string_literal: true RSpec.describe JekyllIncludeCache::Cache do before { subject["foo"] = "bar" } it "sets" do subject["foo2"] = "bar2" cache = subject.instance_variable_get("@cache") expect(cache["foo2"]).to eql("bar2") end it "gets" do expect(subject["foo"]).to eql("bar") end it "raises when a key doesn't exist" do expect { subject["doesnt_exist"] }.to raise_error(RuntimeError) end it "knows if a key exists" do expect(subject.key?("foo")).to be_truthy expect(subject.key?("bar")).to be_falsy end it "deletes" do subject["foo2"] = "bar2" expect(subject.key?("foo2")).to be_truthy subject.delete("foo2") expect(subject.key?("foo2")).to be_falsy end it "clears" do expect(subject.key?("foo")).to be_truthy subject.clear cache = subject.instance_variable_get("@cache") expect(cache).to eql({}) end context "getset" do it "returns an existing value" do value = subject.getset "foo" do "bar2" end expect(value).to eql("bar") end it "sets a new value" do value = subject.getset "foo3" do "bar3" end expect(value).to eql("bar3") expect(subject["foo3"]).to eql("bar3") end end end jekyll-include-cache-0.2.1/spec/jekyll-include-tag/tag_spec.rb000066400000000000000000000051631373763461200242370ustar00rootroot00000000000000# frozen_string_literal: true RSpec.describe JekyllIncludeCache::Tag do let(:tag_name) { "include_cached" } let(:file_path) { "foo.html" } let(:params) { "foo=bar foo2=bar2" } let(:markup) { "#{file_path} #{params}" } let(:overrides) { {} } let(:site) { fixture_site("site", overrides) } let(:environments) { {} } let(:outer_scope) { {} } let(:registers) { { :site => site } } let(:context) { Liquid::Context.new(environments, outer_scope, registers) } let(:parse_context) { Liquid::ParseContext.new } subject { described_class.send(:new, tag_name, markup, parse_context) } let(:cache) { JekyllIncludeCache.cache } let(:path) { subject.send(:path, context) } let(:parsed_params) { subject.parse_params(context) } let(:cache_key) { subject.send(:key, path, parsed_params) } it "determines the path" do expected = File.expand_path "../fixtures/site/_includes/foo.html", __dir__ expect(path).to eql(expected) end context "building the key" do it "builds the key" do key = subject.send(:key, "foo.html", "foo" => "bar", "foo2" => "bar2") params = { "foo" => "bar", "foo2" => "bar2" } expect(key).to eql( subject.send(:digest, "foo.html".hash, subject.send(:quick_hash, params)) ) end it "builds the key based on the path" do key = subject.send(:key, "foo2.html", "foo" => "bar", "foo2" => "bar2") params = { "foo" => "bar", "foo2" => "bar2" } expect(key).to eql( subject.send(:digest, "foo2.html".hash, subject.send(:quick_hash, params)) ) end it "builds the key based on the params" do key = subject.send(:key, "foo2.html", "foo" => "bar") params = { "foo" => "bar" } expect(key).to eql(subject.send(:digest, "foo2.html".hash, subject.send(:quick_hash, params))) end end context "rendering" do before { subject.render(context) } let(:rendered) { subject.render(context) } it "renders" do expect(rendered).to eql("Some content\n") end it "caches the include" do expect(cache.key?(cache_key)).to be_truthy expect(cache[cache_key]).to eql("Some content\n") end context "with the cache stubbed" do before { allow(subject).to receive(:key).and_return(cache_key) } before { cache[cache_key] = "Some other content\n" } let(:cache_key) { "asdf" } it "returns the cached value" do expect(rendered).to eql("Some other content\n") end end end context "with an invalid include" do let(:file_path) { "foo2.html" } it "raises an error" do expect { subject.render(context) }.to raise_error(IOError) end end end jekyll-include-cache-0.2.1/spec/jekyll-include-tag_spec.rb000066400000000000000000000015171373763461200234630ustar00rootroot00000000000000# frozen_string_literal: true RSpec.describe JekyllIncludeCache do subject { described_class.cache } context "with an empty cache" do it "initializess the cache" do expect(described_class.cache).to respond_to(:[]) expect(described_class.cache).to respond_to(:[]=) end end context "with something cached" do before { subject["foo"] = "bar" } it "caches" do expect(subject.key?("foo")).to be_truthy end it "returns the cache" do expect(subject["foo"]).to eql("bar") end end context "clearing the cache on render" do let(:site) { fixture_site("site") } before do subject["foo"] = "bar" Jekyll::Hooks.trigger :site, :pre_render, site, site.site_payload end it "clears the cache" do expect(subject.key?("foo")).to_not be_truthy end end end jekyll-include-cache-0.2.1/spec/spec_helper.rb000066400000000000000000000020211373763461200212450ustar00rootroot00000000000000# frozen_string_literal: true require "jekyll-include-cache" RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true end config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true end config.filter_run_when_matching :focus config.example_status_persistence_file_path = "spec/examples.txt" config.disable_monkey_patching! config.default_formatter = "doc" if config.files_to_run.one? config.order = :random Kernel.srand config.seed end Jekyll.logger.adjust_verbosity(:quiet => true) Jekyll::Cache.cache_dir = File.expand_path("../tmp", __dir__) if defined? Jekyll::Cache def fixture_path(fixture) File.expand_path "./fixtures/#{fixture}", File.dirname(__FILE__) end def fixture_site(fixture, override = {}) default_config = { "source" => fixture_path(fixture) } config = Jekyll::Utils.deep_merge_hashes(default_config, override) config = Jekyll.configuration(config) Jekyll::Site.new(config) end