Compare commits

..
Author SHA1 Message Date
Adam Hollett 977cd55d32 Adds Gemfile and GH pages gem 2016-03-18 17:05:08 -04:00
Adam HollettandTetsuro 74f478679f A few copy-edits 2016-03-15 19:36:29 -04:00
Adam HollettandTetsuro 7b50ceb955 Remove 'codescence' 2016-03-15 19:36:29 -04:00
Adam HollettandTetsuro 7fe3bfcb98 Adds Introduction page
Simplified Introdction page

Spiced up home page more, style changes to code examples
2016-03-15 19:36:27 -04:00
Adam HollettandTetsuro 4aacf3f9a1 Don't bold every sidebar link on the index page
Fixing a bunch of broken links in Tags/Basics
2016-03-15 19:36:24 -04:00
Adam HollettandTetsuro ea16fe9b24 Adds active state to sidebar links 2016-03-15 19:36:24 -04:00
Tetsuro f0883806c4 Style updates + truthy/falsy content udpate 2016-03-15 19:36:24 -04:00
Adam HollettandTetsuro 1aa4d93160 Adds map filter 2016-03-15 19:36:24 -04:00
Tetsuro f5391d0621 Links now have underlines for better visibility 2016-03-15 19:36:23 -04:00
Adam HollettandTetsuro 4d1378b4b3 Uncomplicate the sidebar 2016-03-15 19:36:23 -04:00
Adam Hollett 2790e8c339 Redcarpetify index; edit default filter 2015-12-14 11:08:34 -05:00
Adam Hollett 1579545be2 New content for nearly all filters 2015-12-13 22:39:26 -05:00
Adam Hollett f49b990e94 Simpler code snippets + magic CSS 2015-12-10 20:29:28 -05:00
Adam Hollett 66b98ca025 Don't use a border on inline code tags 2015-12-08 23:37:22 -05:00
Adam Hollett 92f9636ebe Fix front matter 2015-12-04 21:37:27 -05:00
Adam Hollett 74eb3418b6 Tiny fixes 2015-12-04 21:36:13 -05:00
Tetsuro 6ef9c176dd Fixed conflicts 2015-12-04 21:35:11 -05:00
Tetsuro 6bf836b719 Styled input/output codeblocks, going through all docs to make sure codeblocks are consistent 2015-12-04 21:34:18 -05:00
Adam Hollett 1ce90ed355 Refactor config and sidebar 2015-12-04 21:16:07 -05:00
Adam Hollett 90825277d3 Small fixes 2015-12-04 20:52:47 -05:00
Tetsuro 95dc90e503 Begin work on input/output standardization 2015-12-04 20:31:06 -05:00
Adam Hollett def9795c8f Merge remote-tracking branch 'origin/docs-update' into docs-update 2015-12-04 20:05:49 -05:00
Adam Hollett 1e769d9263 Cleanup and config reorg 2015-12-04 20:05:47 -05:00
Tetsuro c51257692d Update Gruntfile to work with Adam's changes 2015-12-04 20:02:56 -05:00
Tetsuro a33a127f81 Fix conflicts 2015-12-04 19:53:59 -05:00
Tetsuro 1504e5ad89 Updating CSS for sidebar 2015-12-04 19:51:46 -05:00
Adam Hollett a55d638690 Why use collections at all? Fixing control flow too 2015-12-04 19:50:03 -05:00
Tetsuro 88e774cb40 CSS adjustments to headers 2015-12-04 19:21:57 -05:00
Adam Hollett 8e3dcf49ba Moving to single collection 2015-12-04 18:56:07 -05:00
Tetsuro f0c7a601c3 Remove h2 classes to make the styles work in other pages 2015-10-16 11:46:03 -04:00
Tetsuro ce1d460d8a Change config file to use pygments, not rouge 2015-10-16 11:19:03 -04:00
Tetsuro fc80f30981 Merge branch 'docs-update' of github.com:Shopify/liquid into docs-update 2015-10-16 11:16:38 -04:00
Tetsuro ffe3ee3754 WIP 2015-10-16 11:16:34 -04:00
Adam Hollett 0147832a64 Polishing up boolean logic and types 2015-10-16 10:53:23 -04:00
Adam Hollett f2a1925033 Updates to types and truthiness 2015-10-15 17:01:53 -04:00
Adam Hollett d63213d463 Minor updates, switch Pigments to Rouge 2015-10-15 17:01:53 -04:00
Tetsuro 68e39b624a Adjusting layout so that every Basics and Tags' content output their own pages 2015-10-15 16:29:00 -04:00
Adam Hollett ea54777dd2 Intro page and small handles update 2015-10-15 13:43:30 -04:00
Tetsuro 34def78926 Added remainder of missing Filters 2015-10-15 13:16:36 -04:00
Tetsuro c744422d0e Added a bunch of missing filters, made some of the copy more consistent 2015-10-15 11:45:13 -04:00
Tetsuro 67b80e35f9 Adding tags, removing custom Liquid 2015-08-28 15:45:28 -04:00
Tetsuro 57ccbd4898 Re-organizing basics content, starting to remove Shopify-specific content 2015-08-28 12:28:11 -04:00
Tetsuro d4c1429ea7 Added missing dependency for Autoprefixer in package.json 2015-08-27 00:21:28 -04:00
Tetsuro ada2a87d8c Started adding Basics section 2015-08-26 19:07:55 -04:00
Tetsuro 6028ddb189 Changing sidebar to deeplinks
Fixed up navigation, collection contents are now output on one page. CSS cleanup
2015-08-26 19:07:51 -04:00
Tetsuro d9b2d50045 WIP: Adding missing filters 2015-07-25 17:48:18 -04:00
Tetsuro 7f550c8bce Left-aligned table headers 2015-07-25 17:09:54 -04:00
Tetsuro a3ceafbcd0 Removed Objects section 2015-07-25 16:50:24 -04:00
Tetsuro d9a08801c5 Added breadcrumb to post titles. Starting to fix alignment for table headers 2015-07-25 15:39:04 -04:00
Tetsuro 0ca571f58c Sidebar work: added collapsing categories
Big refactoring of SCSS

active state for sidebar links

update gitignore for node_modules folder

removing node_modules from index

Sticky Liquid link in sidebar

Cleaned up index page

Adding fixed width to buttons

Refactoring

Converted sidebar to use Collections

Refactor sidebar CSS
2015-07-25 13:49:14 -04:00
Tetsuro 82249c99b3 Set up Grunt
Fixing up Grunt file to watch for directories

Exclude node modules folder from Jekyll built site
2015-07-25 13:48:45 -04:00
tetchi ae3d14bef5 Merge pull request #537 from parkr/docs-update
WIP: Spike out the documentation
2015-03-27 23:01:16 -04:00
Parker Moore ec38c46ff6 Exclude README and CNAME from Jekyll built site. 2015-03-27 13:06:22 -07:00
Parker Moore 13532f7768 Change posts permalink to exclude categories. 2015-03-27 13:05:55 -07:00
Parker Moore 0359e54999 Use Ruby 2.1 in Travis. 2015-03-27 13:04:08 -07:00
Parker Moore b899c61bbc Add an edit link so users can contribute easily. 2015-03-27 13:02:02 -07:00
Garen Torikian 1aeb8a3305 A lot more updates 2015-03-20 16:51:51 -07:00
Garen Torikian 99db066e2a Add docs for the strip commands 2015-03-20 16:23:38 -07:00
Parker Moore 2937f1988b Merge pull request #1 from parkr/updates-to-doc-update
Continue updating documentation
2015-03-18 13:39:05 -07:00
Garen Torikian d65511e328 Add some more docs 2015-03-15 22:10:36 -07:00
Garen Torikian 601e49dc55 pretty tables 2015-03-15 18:23:17 -07:00
Garen Torikian 2232f9157c Add documentation for date 2015-03-15 18:20:32 -07:00
Garen Torikian c09cb6e05a Add scrollbar to the left sidebar 2015-03-15 18:20:25 -07:00
Parker Moore fe0809e2fa Stub out the other filters 2015-03-13 16:39:32 -07:00
Parker Moore f21311b946 Document downcase 2015-03-13 16:32:16 -07:00
Parker Moore adff96b4cf Document divided_by & make liquid raw 2015-03-13 16:29:00 -07:00
Parker Moore 43c2aab84b Add docs for default 2015-03-13 16:20:39 -07:00
Parker Moore dc7cd7704f How do I Liquid? 2015-03-13 16:20:30 -07:00
Parker Moore 57f83933fd Document ceil 2015-03-13 16:11:12 -07:00
Parker Moore 48b5f59b8e Put all the filters on one page 2015-03-13 16:11:04 -07:00
Parker Moore 1b5ff4c86f use a table to show input/output 2015-03-13 16:06:31 -07:00
Parker Moore 963cd58ab6 Add travis build script 2015-03-13 15:40:10 -07:00
Parker Moore f302fce89e Add capitalize docs 2015-03-13 15:39:58 -07:00
Parker Moore 5342f6f55a Add 'append' documentation 2015-03-13 15:29:02 -07:00
Parker Moore 5f1624d6f5 Initial munge of the site. 2015-03-13 15:28:30 -07:00
Tetsuro 447dd346c1 further work on index.md 2015-01-27 16:50:51 -05:00
Tetsuro 26f12734f8 adding readme 2015-01-27 15:30:23 -05:00
Tetsuro 67865368aa Homepage work + Readme 2015-01-27 15:29:13 -05:00
Tetsuro 1fad0e2638 Further work on the homepage 2015-01-27 15:06:23 -05:00
Tetsuro fe4253f872 Realized I don't need flexbox. Position fixed sidebar
Refactoring

Cleaned up some styles
2015-01-27 14:00:57 -05:00
Tetsuro a8dc349f01 starting sidebar coding 2015-01-26 20:41:04 -05:00
Tetsuro 79ec1506de cleaning up stylesheets 2015-01-26 20:32:10 -05:00
Tetsuro e661b5a275 big gutting job 2015-01-26 20:19:33 -05:00
Tetsuro 955a1fae98 Forgot to add files... 2015-01-26 17:53:33 -05:00
Tetsuro ecda8ff57b initial commit, setting up Jekyll 2015-01-26 17:52:23 -05:00
John Duff ba56db81e1 Doesn't look like you can have multiple CNAMEs listed 2011-09-07 12:20:02 -04:00
John Duff 8de5aa2fb4 Add liquidmarkup.com to CNAME as well 2011-09-07 12:08:41 -04:00
John Duff 64b297a180 Move liquidmarkup.org to github pages 2011-09-07 11:44:28 -04:00
Emanuele Vicentini 0239efd826 github generated gh-pages branch 2011-09-07 08:15:23 -07:00
271 changed files with 3201 additions and 21243 deletions
-22
View File
@@ -1,22 +0,0 @@
name: Contributor License Agreement (CLA)
on:
pull_request_target:
types: [opened, synchronize]
issue_comment:
types: [created]
jobs:
cla:
runs-on: ubuntu-latest
if: |
(github.event.issue.pull_request
&& !github.event.issue.pull_request.merged_at
&& contains(github.event.comment.body, 'signed')
)
|| (github.event.pull_request && !github.event.pull_request.merged)
steps:
- uses: Shopify/shopify-cla-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
cla-token: ${{ secrets.CLA_TOKEN }}
-37
View File
@@ -1,37 +0,0 @@
name: Liquid
on: [push, pull_request]
env:
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
entry:
- { ruby: 3.0, allowed-failure: false } # minimum supported
- { ruby: 3.2, allowed-failure: false }
- { ruby: 3.3, allowed-failure: false }
- { ruby: 3.4, allowed-failure: false } # latest
- { ruby: ruby-head, allowed-failure: false }
name: Test Ruby ${{ matrix.entry.ruby }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.entry.ruby }}
bundler-cache: true
bundler: latest
- run: bundle exec rake
continue-on-error: ${{ matrix.entry.allowed-failure }}
memory_profile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bundle exec rake memory_profile:run
+41 -9
View File
@@ -1,9 +1,41 @@
*~
*.gem
*.swp
pkg
*.rbc
.rvmrc
.bundle
.byebug_history
Gemfile.lock
_site/
.sass-cache/
node_modules/
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
-28
View File
@@ -1,28 +0,0 @@
inherit_gem:
rubocop-shopify: rubocop.yml
inherit_from:
- .rubocop_todo.yml
require: rubocop-performance
Performance:
Enabled: true
AllCops:
NewCops: disable
SuggestExtensions: false
Exclude:
- 'vendor/bundle/**/*'
Naming/MethodName:
Exclude:
- 'example/server/liquid_servlet.rb'
Style/ClassMethodsDefinitions:
Enabled: false
# liquid filter calls were being mistaken to be calls on arrays
Style/ConcatArrayLiterals:
Exclude:
- 'test/integration/standard_filter_test.rb'
-180
View File
@@ -1,180 +0,0 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-05-18 19:25:47 UTC using RuboCop version 1.29.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
# Include: **/*.gemspec
Gemspec/OrderedDependencies:
Exclude:
- 'liquid.gemspec'
# Offense count: 6
# This cop supports safe auto-correction (--auto-correct).
Layout/ClosingHeredocIndentation:
Exclude:
- 'test/integration/tags/for_tag_test.rb'
# Offense count: 34
# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'lib/liquid/block.rb'
- 'lib/liquid/block_body.rb'
- 'lib/liquid/context.rb'
- 'lib/liquid/drop.rb'
- 'lib/liquid/lexer.rb'
- 'lib/liquid/parser.rb'
- 'lib/liquid/profiler/hooks.rb'
- 'lib/liquid/standardfilters.rb'
- 'lib/liquid/tags/for.rb'
- 'lib/liquid/tags/if.rb'
- 'lib/liquid/utils.rb'
- 'lib/liquid/variable.rb'
- 'lib/liquid/variable_lookup.rb'
- 'performance/shopify/money_filter.rb'
- 'performance/shopify/paginate.rb'
# Offense count: 8
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowAliasSyntax, AllowedMethods.
# AllowedMethods: alias_method, public, protected, private
Layout/EmptyLinesAroundAttributeAccessor:
Exclude:
- 'lib/liquid/template.rb'
- 'test/integration/filter_test.rb'
- 'test/integration/tags/include_tag_test.rb'
- 'test/unit/strainer_template_unit_test.rb'
# Offense count: 17
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented
Layout/LineEndStringConcatenationIndentation:
Exclude:
- 'test/integration/tags/for_tag_test.rb'
- 'test/integration/tags/increment_tag_test.rb'
# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented
Layout/MultilineOperationIndentation:
Exclude:
- 'lib/liquid/expression.rb'
# Offense count: 9
Lint/MissingSuper:
Exclude:
- 'lib/liquid/forloop_drop.rb'
- 'lib/liquid/tablerowloop_drop.rb'
- 'test/integration/assign_test.rb'
- 'test/integration/context_test.rb'
- 'test/integration/filter_test.rb'
- 'test/integration/standard_filter_test.rb'
- 'test/integration/tags/for_tag_test.rb'
- 'test/integration/tags/table_row_test.rb'
# Offense count: 44
Naming/ConstantName:
Exclude:
- 'lib/liquid.rb'
- 'lib/liquid/block_body.rb'
- 'lib/liquid/tags/assign.rb'
- 'lib/liquid/tags/capture.rb'
- 'lib/liquid/tags/case.rb'
- 'lib/liquid/tags/cycle.rb'
- 'lib/liquid/tags/for.rb'
- 'lib/liquid/tags/if.rb'
- 'lib/liquid/tags/raw.rb'
- 'lib/liquid/tags/table_row.rb'
- 'lib/liquid/variable.rb'
- 'performance/shopify/comment_form.rb'
- 'performance/shopify/paginate.rb'
- 'test/integration/tags/include_tag_test.rb'
# Offense count: 9
# Configuration parameters: CheckIdentifiers, CheckConstants, CheckVariables, CheckStrings, CheckSymbols, CheckComments, CheckFilepaths, FlaggedTerms.
Naming/InclusiveLanguage:
Exclude:
- 'lib/liquid/drop.rb'
- 'lib/liquid/parse_context.rb'
- 'test/integration/drop_test.rb'
- 'test/integration/tags/if_else_tag_test.rb'
# Offense count: 2
Style/ClassVars:
Exclude:
- 'lib/liquid/condition.rb'
# Offense count: 3
# This cop supports safe auto-correction (--auto-correct).
Style/ExplicitBlockArgument:
Exclude:
- 'test/integration/context_test.rb'
- 'test/integration/tag/disableable_test.rb'
- 'test/integration/tags/for_tag_test.rb'
# Offense count: 2982
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false
# Offense count: 20
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiteralsInInterpolation:
Exclude:
- 'lib/liquid/condition.rb'
- 'lib/liquid/strainer_template.rb'
- 'lib/liquid/tag/disableable.rb'
- 'performance/shopify/shop_filter.rb'
- 'performance/shopify/tag_filter.rb'
# Offense count: 6
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInArrayLiteral:
Exclude:
- 'example/server/example_servlet.rb'
- 'lib/liquid/condition.rb'
- 'test/integration/context_test.rb'
- 'test/integration/standard_filter_test.rb'
- 'test/unit/parse_tree_visitor_test.rb'
# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInHashLiteral:
Exclude:
- 'lib/liquid/expression.rb'
# Offense count: 19
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, MinSize, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
Exclude:
- 'lib/liquid/tags/if.rb'
- 'liquid.gemspec'
- 'test/integration/assign_test.rb'
- 'test/integration/context_test.rb'
- 'test/integration/drop_test.rb'
- 'test/integration/standard_filter_test.rb'
# Offense count: 117
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 260
-1
View File
@@ -1 +0,0 @@
3.4.1
+4
View File
@@ -0,0 +1,4 @@
install: gem install github-pages
script: jekyll build --trace
sudo: false
rvm: 2.1
+1
View File
@@ -0,0 +1 @@
liquidmarkup.org
-36
View File
@@ -1,36 +0,0 @@
# How to contribute
## Things we will merge
* Bugfixes
* Performance improvements
* Features that are likely to be useful to the majority of Liquid users
* Documentation updates that are concise and likely to be useful to the majority of Liquid users
## Things we won't merge
* Code that introduces considerable performance degrations
* Code that touches performance-critical parts of Liquid and comes without benchmarks
* Features that are not important for most people (we want to keep the core Liquid code small and tidy)
* Features that can easily be implemented on top of Liquid (for example as a custom filter or custom filesystem)
* Code that does not include tests
* Code that breaks existing tests
* Documentation changes that are verbose, incorrect or not important to most people (we want to keep it simple and easy to understand)
## Workflow
* [Sign the CLA](https://cla.shopify.com/) if you haven't already
* Fork the Liquid repository
* Create a new branch in your fork
* For updating [Liquid documentation](https://shopify.github.io/liquid/), create it from `gh-pages` branch. (You can skip tests.)
* If it makes sense, add tests for your code and/or run a performance benchmark
* Make sure all tests pass (`bundle exec rake`)
* Create a pull request
## Releasing
* Bump the version in `lib/liquid/version.rb`
* Update the `History.md` file
* Open a PR like [this one](https://github.com/Shopify/liquid/pull/1894) and merge it to `main`
* Create a new release using the [GitHub UI](https://github.com/Shopify/liquid/releases/new)
+1 -29
View File
@@ -1,31 +1,3 @@
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end
gemspec
gem "base64"
group :benchmark, :test do
gem 'benchmark-ips'
gem 'memory_profiler'
gem 'terminal-table'
gem "lru_redux"
install_if -> { RUBY_PLATFORM !~ /mingw|mswin|java/ && RUBY_ENGINE != 'truffleruby' } do
gem 'stackprof'
end
end
group :development do
gem "webrick"
end
group :test do
gem 'rubocop', '~> 1.61.0'
gem 'rubocop-shopify', '~> 2.12.0', require: false
gem 'rubocop-performance', require: false
end
gem 'github-pages', group: :jekyll_plugins
+133
View File
@@ -0,0 +1,133 @@
GEM
remote: https://rubygems.org/
specs:
RedCloth (4.2.9)
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
colorator (0.1)
ethon (0.8.1)
ffi (>= 1.3.0)
execjs (2.6.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.10)
gemoji (2.1.0)
github-pages (64)
RedCloth (= 4.2.9)
github-pages-health-check (= 1.1.0)
jekyll (= 3.0.3)
jekyll-coffeescript (= 1.0.1)
jekyll-feed (= 0.4.0)
jekyll-gist (= 1.4.0)
jekyll-github-metadata (= 1.9.0)
jekyll-mentions (= 1.0.1)
jekyll-paginate (= 1.1.0)
jekyll-redirect-from (= 0.10.0)
jekyll-sass-converter (= 1.3.0)
jekyll-seo-tag (= 1.3.2)
jekyll-sitemap (= 0.10.0)
jekyll-textile-converter (= 0.1.0)
jemoji (= 0.5.1)
kramdown (= 1.10.0)
liquid (= 3.0.6)
mercenary (~> 0.3)
rdiscount (= 2.1.8)
redcarpet (= 3.3.3)
rouge (= 1.10.1)
terminal-table (~> 1.4)
github-pages-health-check (1.1.0)
addressable (~> 2.3)
net-dns (~> 0.8)
octokit (~> 4.0)
public_suffix (~> 1.4)
typhoeus (~> 0.7)
html-pipeline (2.3.0)
activesupport (>= 2, < 5)
nokogiri (>= 1.4)
i18n (0.7.0)
jekyll (3.0.3)
colorator (~> 0.1)
jekyll-sass-converter (~> 1.0)
jekyll-watch (~> 1.1)
kramdown (~> 1.3)
liquid (~> 3.0)
mercenary (~> 0.3.3)
rouge (~> 1.7)
safe_yaml (~> 1.0)
jekyll-coffeescript (1.0.1)
coffee-script (~> 2.2)
jekyll-feed (0.4.0)
jekyll-gist (1.4.0)
octokit (~> 4.2)
jekyll-github-metadata (1.9.0)
octokit (~> 4.0)
jekyll-mentions (1.0.1)
html-pipeline (~> 2.3)
jekyll (~> 3.0)
jekyll-paginate (1.1.0)
jekyll-redirect-from (0.10.0)
jekyll (>= 2.0)
jekyll-sass-converter (1.3.0)
sass (~> 3.2)
jekyll-seo-tag (1.3.2)
jekyll (~> 3.0)
jekyll-sitemap (0.10.0)
jekyll-textile-converter (0.1.0)
RedCloth (~> 4.0)
jekyll-watch (1.3.1)
listen (~> 3.0)
jemoji (0.5.1)
gemoji (~> 2.0)
html-pipeline (~> 2.2)
jekyll (>= 2.0)
json (1.8.3)
kramdown (1.10.0)
liquid (3.0.6)
listen (3.0.6)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9.7)
mercenary (0.3.5)
mini_portile2 (2.0.0)
minitest (5.8.4)
multipart-post (2.0.0)
net-dns (0.8.0)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
octokit (4.3.0)
sawyer (~> 0.7.0, >= 0.5.3)
public_suffix (1.5.3)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
rdiscount (2.1.8)
redcarpet (3.3.3)
rouge (1.10.1)
safe_yaml (1.0.4)
sass (3.4.21)
sawyer (0.7.0)
addressable (>= 2.3.5, < 2.5)
faraday (~> 0.8, < 0.10)
terminal-table (1.5.2)
thread_safe (0.3.5)
typhoeus (0.8.0)
ethon (>= 0.8.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
PLATFORMS
ruby
DEPENDENCIES
github-pages
BUNDLED WITH
1.11.2
+72
View File
@@ -0,0 +1,72 @@
// Gruntfile
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
css: {
files: ['_sass/**/*.scss'],
tasks: ['sass', 'postcss', 'shell:jekyllBuild'],
options: {
atBegin: true
}
},
jekyll: {
files: ['index.md', '_includes/*.html', 'filters/*.*', '_layouts/*.*', 'tags/*.*', 'basics/*.*'],
tasks: ['shell:jekyllBuild']
}
},
sass: {
dist: {
options: {
style: 'expanded',
sourcemap: 'none'
},
files: {
'_site/css/main.css':'_sass/main.scss'
}
}
},
shell: {
jekyllServe: {
command: 'jekyll serve --no-watch'
},
jekyllBuild: {
command: 'jekyll build'
}
},
postcss: {
options: {
map: true,
processors: [
require('autoprefixer-core')({browsers: 'last 2 versions'})
]
},
dist: {
src: '_site/css/*.css'
}
},
concurrent: {
tasks: ['shell:jekyllServe', 'watch'],
options: {
logConcurrentOutput: true
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-concurrent');
grunt.registerTask('default', ['concurrent']);
};
-440
View File
@@ -1,440 +0,0 @@
# Liquid Change Log
## 5.8.0 (unreleased)
## 5.7.2 2025-01-31
* Fix array filters to not support nested properties
## 5.7.1 2025-01-24
* Fix the `find` and `find_index`filters to return `nil` when filtering empty arrays
* Fix the `has` filter to return `false` when filtering empty arrays
## 5.7.0 2025-01-16
### Features
* Add `find`, `find_index`, `has`, and `reject` filters to arrays
* Compatibility with Ruby 3.4
## 5.6.4 2025-01-14
### Fixes
* Add a default `string_scanner` to avoid errors with `Liquid::VariableLookup.parse("foo.bar")` [Ian Ker-Seymer]
## 5.6.3 2025-01-13
* Remove `lru_redux` dependency [Michael Go]
## 5.6.2 2025-01-13
### Fixes
* Preserve the old behavior of requiring floats to start with a digit [Michael Go]
## 5.6.1 2025-01-13
### Performance improvements
* Faster Expression parser / Tokenizer with StringScanner [Michael Go]
## 5.6.0 2024-12-19
### Architectural changes
* Added new `Environment` class to manage configuration and state that was previously stored in `Template` [Ian Ker-Seymer]
* Moved tag registration from `Template` to `Environment` [Ian Ker-Seymer]
* Removed `StrainerFactory` in favor of `Environment`-based strainer creation [Ian Ker-Seymer]
* Consolidated standard tags into a new `Tags` module with `STANDARD_TAGS` constant [Ian Ker-Seymer]
### Performance improvements
* Optimized `Lexer` with a new `Lexer2` implementation using jump tables for faster tokenization, requires Ruby 3.4 [Ian Ker-Seymer]
* Improved variable rendering with specialized handling for different types [Michael Go]
* Reduced array allocations by using frozen empty constants [Michael Go]
### API changes
* Deprecated several `Template` class methods in favor of `Environment` methods [Ian Ker-Seymer]
* Added deprecation warnings system [Ian Ker-Seymer]
* Changed how filters and tags are registered to use Environment [Ian Ker-Seymer]
### Fixes
* Fixed table row handling of break interrupts [Alex Coco]
* Improved variable output handling for arrays [Ian Ker-Seymer]
* Fix Tokenizer to handle null source value (#1873) [Bahar Pourazar]
## 5.5.0 2024-03-21
Please reference the GitHub release for more information.
## 5.4.0 2022-07-29
### Breaking Changes
* Drop support for end-of-life Ruby versions (2.5 and 2.6) (#1578) [Andy Waite]
### Features
* Allow `#` to be used as an inline comment tag (#1498) [CP Clermont]
### Fixes
* `PartialCache` now shares snippet cache with subcontexts by default (#1553) [Chris AtLee]
* Hash registers no longer leak into subcontexts as static registers (#1564) [Chris AtLee]
* Fix `ParseTreeVisitor` for `with` variable expressions in `Render` tag (#1596) [CP Clermont]
### Changed
* Liquid::Context#registers now always returns a Liquid::Registers object, though supports the most used Hash functions for compatibility (#1553)
## 5.3.0 2022-03-22
### Fixes
* StandardFilter: Fix missing @context on iterations (#1525) [Thierry Joyal]
* Fix warning about block and default value in `static_registers.rb` (#1531) [Peter Zhu]
### Deprecation
* Condition#evaluate to require mandatory context argument in Liquid 6.0.0 (#1527) [Thierry Joyal]
## 5.2.0 2022-03-01
### Features
* Add `remove_last`, and `replace_last` filters (#1422) [Anders Hagbard]
* Eagerly cache global filters (#1524) [Jean Boussier]
### Fixes
* Fix some internal errors in filters from invalid input (#1476) [Dylan Thacker-Smith]
* Allow dash in filter kwarg name for consistency with Liquid::C (#1518) [CP Clermont]
## 5.1.0 / 2021-09-09
### Features
* Add `base64_encode`, `base64_decode`, `base64_url_safe_encode`, and `base64_url_safe_decode` filters (#1450) [Daniel Insley]
* Introduce `to_liquid_value` in `Liquid::Drop` (#1441) [Michael Go]
### Fixes
* Fix support for using a String subclass for the liquid source (#1421) [Dylan Thacker-Smith]
* Add `ParseTreeVisitor` to `RangeLookup` (#1470) [CP Clermont]
* Translate `RangeError` to `Liquid::Error` for `truncatewords` with large int (#1431) [Dylan Thacker-Smith]
## 5.0.1 / 2021-03-24
### Fixes
* Add ParseTreeVisitor to Echo tag (#1414) [CP Clermont]
* Test with ruby 3.0 as the latest ruby version (#1398) [Dylan Thacker-Smith]
* Handle carriage return in newlines_to_br (#1391) [Unending]
### Performance Improvements
* Use split limit in truncatewords (#1361) [Dylan Thacker-Smith]
## 5.0.0 / 2021-01-06
### Features
* Add new `{% render %}` tag (#1122) [Samuel Doiron]
* Add support for `as` in `{% render %}` and `{% include %}` (#1181) [Mike Angell]
* Add `{% liquid %}` and `{% echo %}` tags (#1086) [Justin Li]
* Add [usage tracking](README.md#usage-tracking) [Mike Angell]
* Add `Tag.disable_tags` for disabling tags that prepend `Tag::Disableable` at render time (#1162, #1274, #1275) [Mike Angell]
* Support using a profiler for multiple renders (#1365, #1366) [Dylan Thacker-Smith]
### Fixes
* Fix catastrophic backtracking in `RANGES_REGEX` regular expression (#1357) [Dylan Thacker-Smith]
* Make sure the for tag's limit and offset are integers (#1094) [David Cornu]
* Invokable methods for enumerable reject include (#1151) [Thierry Joyal]
* Allow `default` filter to handle `false` as value (#1144) [Mike Angell]
* Fix render length resource limit so it doesn't multiply nested output (#1285) [Dylan Thacker-Smith]
* Fix duplication of text in raw tags (#1304) [Peter Zhu]
* Fix strict parsing of find variable with a name expression (#1317) [Dylan Thacker-Smith]
* Use monotonic time to measure durations in Liquid::Profiler (#1362) [Dylan Thacker-Smith]
### Breaking Changes
* Require Ruby >= 2.5 (#1131, #1310) [Mike Angell, Dylan Thacker-Smith]
* Remove support for taint checking (#1268) [Dylan Thacker-Smith]
* Split Strainer class into StrainerFactory and StrainerTemplate (#1208) [Thierry Joyal]
* Remove handling of a nil context in the Strainer class (#1218) [Thierry Joyal]
* Handle `BlockBody#blank?` at parse time (#1287) [Dylan Thacker-Smith]
* Pass the tag markup and tokenizer to `Document#unknown_tag` (#1290) [Dylan Thacker-Smith]
* And several internal changes
### Performance Improvements
* Reduce allocations (#1073, #1091, #1115, #1099, #1117, #1141, #1322, #1341) [Richard Monette, Florian Weingarten, Ashwin Maroli]
* Improve resources limits performance (#1093, #1323) [Florian Weingarten, Dylan Thacker-Smith]
## 4.0.3 / 2019-03-12
### Fixed
* Fix break and continue tags inside included templates in loops (#1072) [Justin Li]
## 4.0.2 / 2019-03-08
### Changed
* Add `where` filter (#1026) [Samuel Doiron]
* Add `ParseTreeVisitor` to iterate the Liquid AST (#1025) [Stephen Paul Weber]
* Improve `strip_html` performance (#1032) [printercu]
### Fixed
* Add error checking for invalid combinations of inputs to sort, sort_natural, where, uniq, map, compact filters (#1059) [Garland Zhang]
* Validate the character encoding in url_decode (#1070) [Clayton Smith]
## 4.0.1 / 2018-10-09
### Changed
* Add benchmark group in Gemfile (#855) [Jerry Liu]
* Allow benchmarks to benchmark render by itself (#851) [Jerry Liu]
* Avoid calling `line_number` on String node when rescuing a render error. (#860) [Dylan Thacker-Smith]
* Avoid duck typing to detect whether to call render on a node. [Dylan Thacker-Smith]
* Clarify spelling of `reversed` on `for` block tag (#843) [Mark Crossfield]
* Replace recursion with loop to avoid potential stack overflow from malicious input (#891, #892) [Dylan Thacker-Smith]
* Limit block tag nesting to 100 (#894) [Dylan Thacker-Smith]
* Replace `assert_equal nil` with `assert_nil` (#895) [Dylan Thacker-Smith]
* Remove Spy Gem (#896) [Dylan Thacker-Smith]
* Add `collection_name` and `variable_name` reader to `For` block (#909)
* Symbols render as strings (#920) [Justin Li]
* Remove default value from Hash objects (#932) [Maxime Bedard]
* Remove one level of nesting (#944) [Dylan Thacker-Smith]
* Update Rubocop version (#952) [Justin Li]
* Add `at_least` and `at_most` filters (#954, #958) [Nithin Bekal]
* Add a regression test for a liquid-c trim mode bug (#972) [Dylan Thacker-Smith]
* Use https rather than git protocol to fetch liquid-c [Dylan Thacker-Smith]
* Add tests against Ruby 2.4 (#963) and 2.5 (#981)
* Replace RegExp literals with constants (#988) [Ashwin Maroli]
* Replace unnecessary `#each_with_index` with `#each` (#992) [Ashwin Maroli]
* Improve the unexpected end delimiter message for block tags. (#1003) [Dylan Thacker-Smith]
* Refactor and optimize rendering (#1005) [Christopher Aue]
* Add installation instruction (#1006) [Ben Gift]
* Remove Circle CI (#1010)
* Rename deprecated `BigDecimal.new` to `BigDecimal` (#1024) [Koichi ITO]
* Rename deprecated Rubocop name (#1027) [Justin Li]
### Fixed
* Handle `join` filter on non String joiners (#857) [Richard Monette]
* Fix duplicate inclusion condition logic error of `Liquid::Strainer.add_filter` method (#861)
* Fix `escape`, `url_encode`, `url_decode` not handling non-string values (#898) [Thierry Joyal]
* Fix raise when variable is defined but nil when using `strict_variables` [Pascal Betz]
* Fix `sort` and `sort_natural` to handle arrays with nils (#930) [Eric Chan]
## 4.0.0 / 2016-12-14 / branch "4-0-stable"
### Changed
* Render an opaque internal error by default for non-Liquid::Error (#835) [Dylan Thacker-Smith]
* Ruby 2.0 support dropped (#832) [Dylan Thacker-Smith]
* Add to_number Drop method to allow custom drops to work with number filters (#731)
* Add strict_variables and strict_filters options to detect undefined references (#691)
* Improve loop performance (#681) [Florian Weingarten]
* Rename Drop method `before_method` to `liquid_method_missing` (#661) [Thierry Joyal]
* Add url_decode filter to invert url_encode (#645) [Larry Archer]
* Add global_filter to apply a filter to all output (#610) [Loren Hale]
* Add compact filter (#600) [Carson Reinke]
* Rename deprecated "has_key?" and "has_interrupt?" methods (#593) [Florian Weingarten]
* Include template name with line numbers in render errors (574) [Dylan Thacker-Smith]
* Add sort_natural filter (#554) [Martin Hanzel]
* Add forloop.parentloop as a reference to the parent loop (#520) [Justin Li]
* Block parsing moved to BlockBody class (#458) [Dylan Thacker-Smith]
* Add concat filter to concatenate arrays (#429) [Diogo Beato]
* Ruby 1.9 support dropped (#491) [Justin Li]
* Liquid::Template.file_system's read_template_file method is no longer passed the context. (#441) [James Reid-Smith]
* Remove `liquid_methods` (See https://github.com/Shopify/liquid/pull/568 for replacement)
* Liquid::Template.register_filter raises when the module overrides registered public methods as private or protected (#705) [Gaurav Chande]
### Fixed
* Fix variable names being detected as an operator when starting with contains (#788) [Michael Angell]
* Fix include tag used with strict_variables (#828) [QuickPay]
* Fix map filter when value is a Proc (#672) [Guillaume Malette]
* Fix truncate filter when value is not a string (#672) [Guillaume Malette]
* Fix behaviour of escape filter when input is nil (#665) [Tanel Jakobsoo]
* Fix sort filter behaviour with empty array input (#652) [Marcel Cary]
* Fix test failure under certain timezones (#631) [Dylan Thacker-Smith]
* Fix bug in uniq filter (#595) [Florian Weingarten]
* Fix bug when "blank" and "empty" are used as variable names (#592) [Florian Weingarten]
* Fix condition parse order in strict mode (#569) [Justin Li]
* Fix naming of the "context variable" when dynamically including a template (#559) [Justin Li]
* Gracefully accept empty strings in the date filter (#555) [Loren Hale]
* Fix capturing into variables with a hyphen in the name (#505) [Florian Weingarten]
* Fix case sensitivity regression in date standard filter (#499) [Kelley Reynolds]
* Disallow filters with no variable in strict mode (#475) [Justin Li]
* Disallow variable names in the strict parser that are not valid in the lax parser (#463) [Justin Li]
* Fix BlockBody#warnings taking exponential time to compute (#486) [Justin Li]
## 3.0.5 / 2015-07-23 / branch "3-0-stable"
* Fix test failure under certain timezones [Dylan Thacker-Smith]
## 3.0.4 / 2015-07-17
* Fix chained access to multi-dimensional hashes [Florian Weingarten]
## 3.0.3 / 2015-05-28
* Fix condition parse order in strict mode (#569) [Justin Li]
## 3.0.2 / 2015-04-24
* Expose VariableLookup private members (#551) [Justin Li]
* Documentation fixes
## 3.0.1 / 2015-01-23
* Remove duplicate `index0` key in TableRow tag (#502) [Alfred Xing]
## 3.0.0 / 2014-11-12
* Removed Block#end_tag. Instead, override parse with `super` followed by your code. See #446 [Dylan Thacker-Smith]
* Fixed condition with wrong data types (#423) [Bogdan Gusiev]
* Add url_encode to standard filters (#421) [Derrick Reimer]
* Add uniq to standard filters [Florian Weingarten]
* Add exception_handler feature (#397) and #254 [Bogdan Gusiev, Florian Weingarten]
* Optimize variable parsing to avoid repeated regex evaluation during template rendering #383 [Jason Hiltz-Laforge]
* Optimize checking for block interrupts to reduce object allocation #380 [Jason Hiltz-Laforge]
* Properly set context rethrow_errors on render! #349 [Thierry Joyal]
* Fix broken rendering of variables which are equal to false (#345) [Florian Weingarten]
* Remove ActionView template handler [Dylan Thacker-Smith]
* Freeze lots of string literals for new Ruby 2.1 optimization (#297) [Florian Weingarten]
* Allow newlines in tags and variables (#324) [Dylan Thacker-Smith]
* Tag#parse is called after initialize, which now takes options instead of tokens as the 3rd argument. See #321 [Dylan Thacker-Smith]
* Raise `Liquid::ArgumentError` instead of `::ArgumentError` when filter has wrong number of arguments #309 [Bogdan Gusiev]
* Add a to_s default for liquid drops (#306) [Adam Doeler]
* Add strip, lstrip, and rstrip to standard filters [Florian Weingarten]
* Make if, for & case tags return complete and consistent nodelists (#250) [Nick Jones]
* Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
* Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
* Fix resource counting bug with respond_to?(:length) (#263) [Florian Weingarten]
* Allow specifying custom patterns for template filenames (#284) [Andrei Gladkyi]
* Allow drops to optimize loading a slice of elements (#282) [Tom Burns]
* Support for passing variables to snippets in subdirs (#271) [Joost Hietbrink]
* Add a class cache to avoid runtime extend calls (#249) [James Tucker]
* Remove some legacy Ruby 1.8 compatibility code (#276) [Florian Weingarten]
* Add default filter to standard filters (#267) [Derrick Reimer]
* Add optional strict parsing and warn parsing (#235) [Tristan Hume]
* Add I18n syntax error translation (#241) [Simon Hørup Eskildsen, Sirupsen]
* Make sort filter work on enumerable drops (#239) [Florian Weingarten]
* Fix clashing method names in enumerable drops (#238) [Florian Weingarten]
* Make map filter work on enumerable drops (#233) [Florian Weingarten]
* Improved whitespace stripping for blank blocks, related to #216 [Florian Weingarten]
## 2.6.3 / 2015-07-23 / branch "2-6-stable"
* Fix test failure under certain timezones [Dylan Thacker-Smith]
## 2.6.2 / 2015-01-23
* Remove duplicate hash key [Parker Moore]
## 2.6.1 / 2014-01-10
Security fix, cherry-picked from master (4e14a65):
* Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
* Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
## 2.6.0 / 2013-11-25
IMPORTANT: Liquid 2.6 is going to be the last version of Liquid which maintains explicit Ruby 1.8 compatability.
The following releases will only be tested against Ruby 1.9 and Ruby 2.0 and are likely to break on Ruby 1.8.
* Bugfix for #106: fix example servlet [gnowoel]
* Bugfix for #97: strip_html filter supports multi-line tags [Jo Liss]
* Bugfix for #114: strip_html filter supports style tags [James Allardice]
* Bugfix for #117: 'now' support for date filter in Ruby 1.9 [Notre Dame Webgroup]
* Bugfix for #166: truncate filter on UTF-8 strings with Ruby 1.8 [Florian Weingarten]
* Bugfix for #204: 'raw' parsing bug [Florian Weingarten]
* Bugfix for #150: 'for' parsing bug [Peter Schröder]
* Bugfix for #126: Strip CRLF in strip_newline [Peter Schröder]
* Bugfix for #174, "can't convert Fixnum into String" for "replace" [jsw0528]
* Allow a Liquid::Drop to be passed into Template#render [Daniel Huckstep]
* Resource limits [Florian Weingarten]
* Add reverse filter [Jay Strybis]
* Add utf-8 support
* Use array instead of Hash to keep the registered filters [Tasos Stathopoulos]
* Cache tokenized partial templates [Tom Burns]
* Avoid warnings in Ruby 1.9.3 [Marcus Stollsteimer]
* Better documentation for 'include' tag (closes #163) [Peter Schröder]
* Use of BigDecimal on filters to have better precision (closes #155) [Arthur Nogueira Neves]
## 2.5.5 / 2014-01-10 / branch "2-5-stable"
Security fix, cherry-picked from master (4e14a65):
* Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
* Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
## 2.5.4 / 2013-11-11
* Fix "can't convert Fixnum into String" for "replace" (#173), [jsw0528]
## 2.5.3 / 2013-10-09
* #232, #234, #237: Fix map filter bugs [Florian Weingarten]
## 2.5.2 / 2013-09-03 / deleted
Yanked from rubygems, as it contained too many changes that broke compatibility. Those changes will be on following major releases.
## 2.5.1 / 2013-07-24
* #230: Fix security issue with map filter, Use invoke_drop in map filter [Florian Weingarten]
## 2.5.0 / 2013-03-06
* Prevent Object methods from being called on drops
* Avoid symbol injection from liquid
* Added break and continue statements
* Fix filter parser for args without space separators
* Add support for filter keyword arguments
## 2.4.0 / 2012-08-03
* Performance improvements
* Allow filters in `assign`
* Add `modulo` filter
* Ruby 1.8, 1.9, and Rubinius compatibility fixes
* Add support for `quoted['references']` in `tablerow`
* Add support for Enumerable to `tablerow`
* `strip_html` filter removes html comments
## 2.3.0 / 2011-10-16
* Several speed/memory improvements
* Numerous bug fixes
* Added support for MRI 1.9, Rubinius, and JRuby
* Added support for integer drop parameters
* Added epoch support to `date` filter
* New `raw` tag that suppresses parsing
* Added `else` option to `for` tag
* New `increment` tag
* New `split` filter
## 2.2.1 / 2010-08-23
* Added support for literal tags
## 2.2.0 / 2010-08-22
* Compatible with Ruby 1.8.7, 1.9.1 and 1.9.2-p0
* Merged some changed made by the community
## 1.9.0 / 2008-03-04
* Fixed gem install rake task
* Improve Error encapsulation in liquid by maintaining a own set of exceptions instead of relying on ruby build ins
## Before 1.9.0
* Added If with or / and expressions
* Implemented .to_liquid for all objects which can be passed to liquid like Strings Arrays Hashes Numerics and Booleans. To export new objects to liquid just implement .to_liquid on them and return objects which themselves have .to_liquid methods.
* Added more tags to standard library
* Added include tag ( like partials in rails )
* [...] Gazillion of detail improvements
* Added strainers as filter hosts for better security [Tobias Luetke]
* Fixed that rails integration would call filter with the wrong "self" [Michael Geary]
* Fixed bad error reporting when a filter called a method which doesn't exist. Liquid told you that it couldn't find the filter which was obviously misleading [Tobias Luetke]
* Removed count helper from standard lib. use size [Tobias Luetke]
* Fixed bug with string filter parameters failing to tolerate commas in strings. [Paul Hammond]
* Improved filter parameters. Filter parameters are now context sensitive; Types are resolved according to the rules of the context. Multiple parameters are now separated by the Liquid::ArgumentSeparator: , by default [Paul Hammond]
{{ 'Typo' | link_to: 'http://typo.leetsoft.com', 'Typo - a modern weblog engine' }}
* Added Liquid::Drop. A base class which you can use for exporting proxy objects to liquid which can acquire more data when used in liquid. [Tobias Luetke]
class ProductDrop < Liquid::Drop
def top_sales
Shop.current.products.find(:all, :order => 'sales', :limit => 10 )
end
end
t = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {% endfor %} ' )
t.render('product' => ProductDrop.new )
* Added filter parameters support. Example: {{ date | format_date: "%Y" }} [Paul Hammond]
-20
View File
@@ -1,20 +0,0 @@
Copyright (c) 2005, 2006 Tobias Luetke
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.
+6 -153
View File
@@ -1,156 +1,9 @@
[![Build status](https://github.com/Shopify/liquid/actions/workflows/liquid.yml/badge.svg)](https://github.com/Shopify/liquid/actions/workflows/liquid.yml)
[![Inline docs](http://inch-ci.org/github/Shopify/liquid.svg?branch=master)](http://inch-ci.org/github/Shopify/liquid)
# New Liquid Docs
# Liquid template engine
To run, follow these steps:
* [Contributing guidelines](CONTRIBUTING.md)
* [Version history](History.md)
* [Liquid documentation from Shopify](https://shopify.dev/docs/api/liquid)
* [Liquid Wiki at GitHub](https://github.com/Shopify/liquid/wiki)
* [Website](http://liquidmarkup.org/)
1. Download ZIP or clone in GitHub
2. Navigate to `liquid` folder
3. Run `jekyll watch`
4. Open `http://127.0.0.1:4000` in your browser
## Introduction
Liquid is a template engine which was written with very specific requirements:
* It has to have beautiful and simple markup. Template engines which don't produce good looking markup are no fun to use.
* It needs to be non evaling and secure. Liquid templates are made so that users can edit them. You don't want to run code on your server which your users wrote.
* It has to be stateless. Compile and render steps have to be separate so that the expensive parsing and compiling can be done once and later on you can just render it passing in a hash with local variables and objects.
## Why you should use Liquid
* You want to allow your users to edit the appearance of your application but don't want them to run **insecure code on your server**.
* You want to render templates directly from the database.
* You like smarty (PHP) style template engines.
* You need a template engine which does HTML just as well as emails.
* You don't like the markup of your current templating engine.
## What does it look like?
```html
<ul id="products">
{% for product in products %}
<li>
<h2>{{ product.name }}</h2>
Only {{ product.price | price }}
{{ product.description | prettyprint | paragraph }}
</li>
{% endfor %}
</ul>
```
## How to use Liquid
Install Liquid by adding `gem 'liquid'` to your gemfile.
Liquid supports a very simple API based around the Liquid::Template class.
For standard use you can just pass it the content of a file and call render with a parameters hash.
```ruby
@template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template
@template.render('name' => 'tobi') # => "hi tobi"
```
### Concept of Environments
In Liquid, a "Environment" is a scoped environment that encapsulates custom tags, filters, and other configurations. This allows you to define and isolate different sets of functionality for different contexts, avoiding global overrides that can lead to conflicts and unexpected behavior.
By using environments, you can:
1. **Encapsulate Logic**: Keep the logic for different parts of your application separate.
2. **Avoid Conflicts**: Prevent custom tags and filters from clashing with each other.
3. **Improve Maintainability**: Make it easier to manage and understand the scope of customizations.
4. **Enhance Security**: Limit the availability of certain tags and filters to specific contexts.
We encourage the use of Environments over globally overriding things because it promotes better software design principles such as modularity, encapsulation, and separation of concerns.
Here's an example of how you can define and use Environments in Liquid:
```ruby
user_environment = Liquid::Environment.build do |environment|
environment.register_tag("renderobj", RenderObjTag)
end
Liquid::Template.parse(<<~LIQUID, environment: user_environment)
{% renderobj src: "path/to/model.obj" %}
LIQUID
```
In this example, `RenderObjTag` is a custom tag that is only available within the `user_environment`.
Similarly, you can define another environment for a different context, such as email templates:
```ruby
email_environment = Liquid::Environment.build do |environment|
environment.register_tag("unsubscribe_footer", UnsubscribeFooter)
end
Liquid::Template.parse(<<~LIQUID, environment: email_environment)
{% unsubscribe_footer %}
LIQUID
```
By using Environments, you ensure that custom tags and filters are only available in the contexts where they are needed, making your Liquid templates more robust and easier to manage. For smaller projects, a global environment is available via `Liquid::Environment.default`.
### Error Modes
Setting the error mode of Liquid lets you specify how strictly you want your templates to be interpreted.
Normally the parser is very lax and will accept almost anything without error. Unfortunately this can make
it very hard to debug and can lead to unexpected behaviour.
Liquid also comes with a stricter parser that can be used when editing templates to give better error messages
when templates are invalid. You can enable this new parser like this:
```ruby
Liquid::Environment.default.error_mode = :strict
Liquid::Environment.default.error_mode = :strict # Raises a SyntaxError when invalid syntax is used
Liquid::Environment.default.error_mode = :warn # Adds strict errors to template.errors but continues as normal
Liquid::Environment.default.error_mode = :lax # The default mode, accepts almost anything.
```
If you want to set the error mode only on specific templates you can pass `:error_mode` as an option to `parse`:
```ruby
Liquid::Template.parse(source, error_mode: :strict)
```
This is useful for doing things like enabling strict mode only in the theme editor.
It is recommended that you enable `:strict` or `:warn` mode on new apps to stop invalid templates from being created.
It is also recommended that you use it in the template editors of existing apps to give editors better error messages.
### Undefined variables and filters
By default, the renderer doesn't raise or in any other way notify you if some variables or filters are missing, i.e. not passed to the `render` method.
You can improve this situation by passing `strict_variables: true` and/or `strict_filters: true` options to the `render` method.
When one of these options is set to true, all errors about undefined variables and undefined filters will be stored in `errors` array of a `Liquid::Template` instance.
Here are some examples:
```ruby
template = Liquid::Template.parse("{{x}} {{y}} {{z.a}} {{z.b}}")
template.render({ 'x' => 1, 'z' => { 'a' => 2 } }, { strict_variables: true })
#=> '1 2 ' # when a variable is undefined, it's rendered as nil
template.errors
#=> [#<Liquid::UndefinedVariable: Liquid error: undefined variable y>, #<Liquid::UndefinedVariable: Liquid error: undefined variable b>]
```
```ruby
template = Liquid::Template.parse("{{x | filter1 | upcase}}")
template.render({ 'x' => 'foo' }, { strict_filters: true })
#=> '' # when at least one filter in the filter chain is undefined, a whole expression is rendered as nil
template.errors
#=> [#<Liquid::UndefinedFilter: Liquid error: undefined filter filter1>]
```
If you want to raise on a first exception instead of pushing all of them in `errors`, you can use `render!` method:
```ruby
template = Liquid::Template.parse("{{x}} {{y}}")
template.render!({ 'x' => 1}, { strict_variables: true })
#=> Liquid::UndefinedVariable: Liquid error: undefined variable y
```
### Usage tracking
To help track usages of a feature or code path in production, we have released opt-in usage tracking. To enable this, we provide an empty `Liquid:: Usage.increment` method which you can customize to your needs. The feature is well suited to https://github.com/Shopify/statsd-instrument. However, the choice of implementation is up to you.
Once you have enabled usage tracking, we recommend reporting any events through Github Issues that your system may be logging. It is highly likely this event has been added to consider deprecating or improving code specific to this event, so please raise any concerns.
-137
View File
@@ -1,137 +0,0 @@
# frozen_string_literal: true
require 'rake'
require 'rake/testtask'
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
require "liquid/version"
task(default: [:test, :rubocop])
desc('run test suite with default parser')
Rake::TestTask.new(:base_test) do |t|
t.libs << 'lib' << 'test'
t.test_files = FileList['test/{integration,unit}/**/*_test.rb']
t.verbose = false
end
Rake::TestTask.new(:integration_test) do |t|
t.libs << 'lib' << 'test'
t.test_files = FileList['test/integration/**/*_test.rb']
t.verbose = false
end
desc('run test suite with warn error mode')
task :warn_test do
ENV['LIQUID_PARSER_MODE'] = 'warn'
Rake::Task['base_test'].invoke
end
task :rubocop do
if RUBY_ENGINE == 'ruby'
require 'rubocop/rake_task'
RuboCop::RakeTask.new
end
end
desc('runs test suite with both strict and lax parsers')
task :test do
ENV['LIQUID_PARSER_MODE'] = 'lax'
Rake::Task['base_test'].invoke
ENV['LIQUID_PARSER_MODE'] = 'strict'
Rake::Task['base_test'].reenable
Rake::Task['base_test'].invoke
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'truffleruby'
ENV['LIQUID_PARSER_MODE'] = 'lax'
Rake::Task['integration_test'].reenable
Rake::Task['integration_test'].invoke
ENV['LIQUID_PARSER_MODE'] = 'strict'
Rake::Task['integration_test'].reenable
Rake::Task['integration_test'].invoke
end
end
task(gem: :build)
task :build do
system "gem build liquid.gemspec"
end
task install: :build do
system "gem install liquid-#{Liquid::VERSION}.gem"
end
task release: :build do
system "git tag -a v#{Liquid::VERSION} -m 'Tagging #{Liquid::VERSION}'"
system "git push --tags"
system "gem push liquid-#{Liquid::VERSION}.gem"
system "rm liquid-#{Liquid::VERSION}.gem"
end
namespace :benchmark do
desc "Run the liquid benchmark with lax parsing"
task :lax do
ruby "./performance/benchmark.rb lax"
end
desc "Run the liquid benchmark with strict parsing"
task :strict do
ruby "./performance/benchmark.rb strict"
end
desc "Run the liquid benchmark with both lax and strict parsing"
task run: [:lax, :strict]
desc "Run unit benchmarks"
namespace :unit do
task :all do
Dir["./performance/unit/*_benchmark.rb"].each do |file|
puts "🧪 Running #{file}"
ruby file
end
end
task :lexer do
Dir["./performance/unit/lexer_benchmark.rb"].each do |file|
puts "🧪 Running #{file}"
ruby file
end
end
task :expression do
Dir["./performance/unit/expression_benchmark.rb"].each do |file|
puts "🧪 Running #{file}"
ruby file
end
end
end
end
namespace :profile do
desc "Run the liquid profile/performance coverage"
task :run do
ruby "./performance/profile.rb"
end
desc "Run the liquid profile/performance coverage with strict parsing"
task :strict do
ruby "./performance/profile.rb strict"
end
end
namespace :memory_profile do
desc "Run memory profiler"
task :run do
ruby "./performance/memory_profile.rb"
end
end
desc("Run example")
task :example do
ruby "-w -d -Ilib example/server/server.rb"
end
task :console do
exec 'irb -I lib -r liquid'
end
+25
View File
@@ -0,0 +1,25 @@
title: Liquid Templating Engine
description: "Liquid is a template language and accompanying rendering engine. It is built for security, so is perfect for rendering custom templates from your users."
repository: https://github.com/Shopify/liquid
# Build settings
baseurl: "" # the subpath of your site, e.g. /blog/
url: http://liquidmarkup.org # the base hostname & protocol for your site
markdown: redcarpet
redcarpet:
extensions: ["with_toc_data", "tables", "disable_indented_code_blocks", "no_intra_emphasis"]
highlighter: pygments
permalink: pretty
exclude:
- README.md
- CNAME
- node_modules
keep_files: ["css"]
# Front matter defaults
defaults:
- scope:
path: "" # an empty string here means all files in the project
values:
layout: default
+8
View File
@@ -0,0 +1,8 @@
<header class="home-banner">
<h1>Liquid</h1>
<p>Safe, customer facing template language for flexible web apps.</p>
<p class="btn-row">
<a href="https://github.com/Shopify/liquid/archive/master.zip" target="_blank" class="btn"><i class="icon fa fa-2x fa-arrow-circle-down"></i>Download</a>
<a href="https://github.com/Shopify/liquid" target="_blank" class="btn"><i class="icon fa fa-2x fa-github"></i>View on Github</a>
</p>
</header>
+24
View File
@@ -0,0 +1,24 @@
<div class="home-users-grid">
<div class="home-users-grid__item">
<a href="http://jekyllrb.com/" target="_blank">
<img src="/images/jekyll-logo.png" />
</a>
</div>
<div class="home-users-grid__item">
<a href="http://www.desk.com/" target="_blank">
<img src="/images/salesforcedesk-logo.png" />
</a>
</div>
<div class="home-users-grid__item">
<a href="https://www.zendesk.com/ " target="_blank">
<img src="/images/zendesk-logo.png" />
</a>
</div>
<div class="home-users-grid__item">
<a href="http://500px.com/" target="_blank">
<img src="/images/500px-logo.png" />
</a>
</div>
</div>
<p class="home-users-blurb">...and <a href="https://github.com/Shopify/liquid/wiki#who-uses-liquid" target="_blank">many more!</a></p>
+18
View File
@@ -0,0 +1,18 @@
<div class="sidebar">
<div class="sidebar--logo">
<a href="/">Liquid</a>
</div>
<nav class="sidebar--nav"> {% assign sections = "basics, tags, filters" | split: ", " %}
{% for section in sections %}
<h3 class="section__header">{{ section | capitalize }}</h3>
<ul class="section__links">
{% for item in site.pages %}{% if item.url contains section/ %}{% unless item.path contains "index" %}
<li><a href="{{ item.url | prepend: site.baseurl }}" class="section__link{% if item.url contains page.url and page.url != "/" %} section__link--is-active {% endif %}">{{ item.title }}</a></li>
{% endunless %}{% endif %}{% endfor %}
</ul>
{% endfor %}
</nav>
</div>
+29
View File
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>{% if page.title %}{{ page.title }} {% endif %}{{ site.title }}</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}">
<link rel="stylesheet" href="{{ '/css/main.css' | prepend: site.baseurl }}">
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}">
<link rel="alternate" type="application/rss+xml" title="{{ site.title }}" href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}" />
</head>
<body>
{% include sidebar.html %}
<div class="content__area">
<div class="content">
<h1>{{ page.title }}</h1>
{{ content }}
</div>
</div>
</body>
</html>
+17
View File
@@ -0,0 +1,17 @@
@charset "utf-8";
@import "partials/defaults";
@import "partials/colors";
@import "partials/helpers";
@import "modules/base";
@import "modules/layout";
@import "modules/buttons";
@import "modules/home-banner";
@import "modules/home-users-grid";
@import "modules/content-area";
@import "vendors/syntax-highlighting";
+185
View File
@@ -0,0 +1,185 @@
* {
box-sizing: border-box;
}
/**
* Reset some basic elements
*/
body, h1, h2, h3, h4, h5, h6,
p, blockquote, pre, hr,
dl, dd, ol, ul, figure {
margin: 0;
padding: 0;
}
/**
* Basic styling
*/
body {
font-family: $base-font-family;
font-size: $base-font-size;
line-height: $base-line-height;
font-weight: 300;
color: $color-slate;
-webkit-text-size-adjust: 100%;
}
/** Set `margin-bottom` to maintain vertical rhythm */
h1, h2, h3, h4, h5, h6,
p, blockquote, pre,
ul, ol, dl, figure,
%vertical-rhythm {
margin-bottom: $spacing-unit / 2;
}
/** Images */
img {
max-width: 100%;
vertical-align: middle;
}
/** Figures */
figure > img {
display: block;
}
figcaption {
font-size: $small-font-size;
}
/** Lists */
ul, ol {
margin-left: $spacing-unit;
}
li {
> ul, > ol {
margin-bottom: 0;
}
}
/** Headings */
h1, h2, h3, h4, h5, h6 {
font-weight: bold;
}
/** Links */
a {
color: $color-blue-5;
&:visited {
color: #609;
}
&:hover {
text-decoration: underline;
}
}
h1 {
font-size: 2em;
}
h2 {
font-size: 1.5em;
text-decoration: underline;
margin-top: $spacing-unit;
}
h3 {
font-size: 1em;
text-decoration: underline;
}
h4 {
font-size: 1em;
}
blockquote {
color: lighten($color-slate, 30%);
border-left: 2px solid lighten($color-slate, 50%);
padding-left: $spacing-unit / 2;
letter-spacing: -1px;
font-style: italic;
> :last-child {
margin-bottom: 0;
}
}
pre, code {
font-size: 15px;
border-radius: 3px;
background-color: lighten($color-blue-1, 0.9);
}
code {
padding: 1px 5px;
}
pre {
padding: 8px 12px;
border: 1px solid $color-blue-2;
word-wrap: break-word;
> code {
border: 0;
padding-right: 0;
padding-left: 0;
}
}
hr {
display: block;
height: 1px;
border: 0;
background-color: lighten($color-slate, 50%);
margin-bottom: $spacing-unit/2;
}
table {
width: 100%;
overflow: auto;
display: block;
margin: 15px 0;
border-collapse: collapse;
thead {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
th {
border: 1px solid #ddd;
padding: 6px 13px;
font-weight: bold;
text-align: center;
}
tbody {
vertical-align: middle;
border-color: inherit;
}
tr {
border-top: 1px solid #ccc;
background-color: #fff;
vertical-align: inherit;
}
td {
border: 1px solid #ddd;
padding: 6px 13px;
}
/* Don't use a margin on code samples within tables */
pre {
margin-bottom: 0;
}
}
p {
line-height: 1.8;
}
+34
View File
@@ -0,0 +1,34 @@
.btn {
color: $color-white;
display: flex;
background: $color-blue-5;
align-items: center;
padding: $spacing-unit/4 $spacing-unit/2;
border-radius: 8px;
text-decoration: none;
&:hover {
background: $color-blue-4;
cursor: pointer;
text-decoration: none;
}
}
.btn:visited {
color: $color-white;
}
.btn-row {
display: flex;
justify-content: center;
margin-bottom: 0;
.btn:not(:first-child) {
margin-left: $spacing-unit / 2;
}
}
.icon {
vertical-align: middle;
margin-right: $spacing-unit / 4;
}
+31
View File
@@ -0,0 +1,31 @@
.content__item {
margin-bottom: $spacing-unit * 2;
}
.highlight {
pre {
border-top: none;
border-radius: 0 0 3px 3px;
}
&:before {
content: "Example";
display: block;
padding: 8px 12px;
color: $color-slate;
background: #fff;
border: 1px solid $color-blue-2;
border-radius: 3px 3px 0 0;
font-size: 16px;
font-weight: bold;
}
// Label every second code block with "Output"
& + .highlight:nth-of-type(2n) {
&:before {
content: "Output";
}
}
}
+11
View File
@@ -0,0 +1,11 @@
.home-banner {
text-align: center;
border-bottom: 1px solid lighten($color-slate, 50%);
padding-bottom: $spacing-unit;
margin-bottom: $spacing-unit;
h1 {
font-weight: bold;
font-size: 5em;
}
}
+20
View File
@@ -0,0 +1,20 @@
.home-users-grid {
display: flex;
align-items: center;
flex-wrap: wrap;
margin-bottom: $spacing-unit / 2;
}
.home-users-grid__item{
flex: 1;
margin-right: $spacing-unit / 2;
max-width: 50%;
&:last-child {
margin-right: 0;
}
}
.home-users-blurb {
text-align: right;
}
+112
View File
@@ -0,0 +1,112 @@
$sidebar-width: 250px;
$logo-height: 130px;
$wrapper-width: 800px;
/*============================================================================
Content Area
==============================================================================*/
.content__area {
padding: $spacing-unit $spacing-unit $spacing-unit ($spacing-unit + $sidebar-width);
width: 100%;
}
.content {
max-width: $wrapper-width;
margin: 0 auto;
padding: 0 $spacing-unit;
@extend %clearfix;
}
/*============================================================================
Sidebar
==============================================================================*/
.sidebar {
background: $color-blue-5;
width: $sidebar-width;
height: 100vh;
position: fixed;
}
.sidebar--logo {
font-size: $base-font-size * 2;
font-weight: bold;
text-align: center;
height: $logo-height;
line-height: $logo-height;
margin-bottom: 0;
border-bottom: 1px solid $color-blue-4;
a {
color: $color-white;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
}
.sidebar--nav {
padding: $spacing-unit $spacing-unit ($spacing-unit + $logo-height); // Add a bit more padding at the bottom for consistency.
font-weight: bold;
max-height: 100%;
overflow-y: scroll;
li {
list-style: none;
a {
color: $color-white;
&:hover {
text-decoration: none;
}
}
}
}
.section {
margin: 0px;
> li {
margin-bottom: $spacing-unit / 2;
&:last-child {
margin-bottom: $spacing-unit;
}
}
}
.section__header {
font-weight: bold;
font-size: 1em;
text-decoration: none;
color: $color-white;
margin-bottom: $spacing-unit / 4;
}
.section__links {
margin-left: $spacing-unit / 2;
margin-bottom: $spacing-unit;
font-weight: normal;
font-size: 0.9em;
}
.section__link {
display: inline-block;
margin-top: $spacing-unit/4;
opacity: 0.75;
text-decoration: none;
&:hover {
opacity: 1;
}
}
.section__link--is-active {
font-weight: bold;
opacity: 1;
}
+10
View File
@@ -0,0 +1,10 @@
// I got the blues, man.
// 1 --> 5, lightest --> darkest.
$color-blue-1: #E8F8FF;
$color-blue-2: #B4DCED;
$color-blue-3: #91C9E8;
$color-blue-4: #67B8DE;
$color-blue-5: #3399CC;
$color-white: #ffffff;
$color-slate: #5E5E5E;
+6
View File
@@ -0,0 +1,6 @@
$base-font-family: 'Droid Sans', sans-serif;
$base-font-size: 18px;
$small-font-size: $base-font-size * 0.875;
$base-line-height: 1.5;
$spacing-unit: 40px;
+7
View File
@@ -0,0 +1,7 @@
%clearfix {
&:after {
content: "";
display: table;
clear: both;
}
}
+67
View File
@@ -0,0 +1,67 @@
/**
* Syntax highlighting styles
*/
.highlight {
background: #fff;
@extend %vertical-rhythm;
.c { color: #998; font-style: italic } // Comment
.err { color: #a61717; background-color: #e3d2d2 } // Error
.k { font-weight: bold } // Keyword
.o { font-weight: bold } // Operator
.cm { color: #998; font-style: italic } // Comment.Multiline
.cp { color: #999; font-weight: bold } // Comment.Preproc
.c1 { color: #998; font-style: italic } // Comment.Single
.cs { color: #999; font-weight: bold; font-style: italic } // Comment.Special
.gd { color: #000; background-color: #fdd } // Generic.Deleted
.gd .x { color: #000; background-color: #faa } // Generic.Deleted.Specific
.ge { font-style: italic } // Generic.Emph
.gr { color: #a00 } // Generic.Error
.gh { color: #999 } // Generic.Heading
.gi { color: #000; background-color: #dfd } // Generic.Inserted
.gi .x { color: #000; background-color: #afa } // Generic.Inserted.Specific
.go { color: #888 } // Generic.Output
.gp { color: #555 } // Generic.Prompt
.gs { font-weight: bold } // Generic.Strong
.gu { color: #aaa } // Generic.Subheading
.gt { color: #a00 } // Generic.Traceback
.kc { font-weight: bold } // Keyword.Constant
.kd { font-weight: bold } // Keyword.Declaration
.kp { font-weight: bold } // Keyword.Pseudo
.kr { font-weight: bold } // Keyword.Reserved
.kt { color: #458; font-weight: bold } // Keyword.Type
.m { color: #099 } // Literal.Number
.s { color: #d14 } // Literal.String
.na { color: #008080 } // Name.Attribute
.nb { color: #0086B3 } // Name.Builtin
.nc { color: #458; font-weight: bold } // Name.Class
.no { color: #008080 } // Name.Constant
.ni { color: #800080 } // Name.Entity
.ne { color: #900; font-weight: bold } // Name.Exception
.nf { color: #900; font-weight: bold } // Name.Function
.nn { color: #555 } // Name.Namespace
.nt { color: #000080 } // Name.Tag
.nv { color: #008080 } // Name.Variable
.ow { font-weight: bold } // Operator.Word
.w { color: #bbb } // Text.Whitespace
.mf { color: #099 } // Literal.Number.Float
.mh { color: #099 } // Literal.Number.Hex
.mi { color: #099 } // Literal.Number.Integer
.mo { color: #099 } // Literal.Number.Oct
.sb { color: #d14 } // Literal.String.Backtick
.sc { color: #d14 } // Literal.String.Char
.sd { color: #d14 } // Literal.String.Doc
.s2 { color: #d14 } // Literal.String.Double
.se { color: #d14 } // Literal.String.Escape
.sh { color: #d14 } // Literal.String.Heredoc
.si { color: #d14 } // Literal.String.Interpol
.sx { color: #d14 } // Literal.String.Other
.sr { color: #009926 } // Literal.String.Regex
.s1 { color: #d14 } // Literal.String.Single
.ss { color: #990073 } // Literal.String.Symbol
.bp { color: #999 } // Name.Builtin.Pseudo
.vc { color: #008080 } // Name.Variable.Class
.vg { color: #008080 } // Name.Variable.Global
.vi { color: #008080 } // Name.Variable.Instance
.il { color: #099 } // Literal.Number.Integer.Long
}
+48
View File
@@ -0,0 +1,48 @@
---
title: Handles
---
A handle is used to access the attributes of a Liquid object. By default, the handle is the object's title in lowercase with any spaces and special characters replaced by hyphens (-).
For example, a page with the title "About Us" can be accessed in Liquid via its handle `about-us` as shown below:
{% highlight liquid %}
{% raw %}
<!-- the content of the About Us page -->
{{ pages.about-us.content }}
{% endraw %}
{% endhighlight %}
## Creating handles
An object with the title "Shirt" will automatically be given the handle `shirt`. If there is already an object with the handle `shirt`, the handle will auto-increment. In other words, "Shirt" objects created after the first one will receive the handle `shirt-1`, `shirt-2`, and so on.
Whitespace in titles is replaced by hyphens in handles. For example, the title "My Shiny New Title" will be given the handle `my-shiny-new-title`.
Handles also determine the URL of their corresponding objects. For example, a page with the handle `about-us` would have the url `/pages/about-us`.
Websites often rely on static handles for pages, posts, or objects. To preserve design elements and avoid broken links, if you modify the title of an object, **its handle is not automatically updated**. For example, if you were to change a page title from "About Us" to "About This Website", its handle would still be `about-us`.
You can change an object's handle manually (TK how to change a handle manually)
## Accessing handle attributes
In many cases you may know the handle of a object whose attributes you want to access. You can access its attributes by pluralizing the name of the object, then using either the square bracket ( [ ] ) or dot ( . ) notation.
<div class="code-block code-block--input">
{% highlight liquid %}
{% raw %}
{{ pages.about-us.title }}
{{ pages["about-us"].title }}
{% endraw %}
{% endhighlight %}
</div>
<div class="code-block code-block--output">
{% highlight text %}
About Us
About Us
{% endhighlight %}
</div>
In the example above, notice that we are using `pages` as opposed to `page`.
+4
View File
@@ -0,0 +1,4 @@
---
layout: default
---
+64
View File
@@ -0,0 +1,64 @@
---
title: Introduction
---
Liquid code can be categorized into [**objects**](#objects), [**tags**](#tags), and [**filters**](#filters).
## Objects
**Objects** tell Liquid where to show content on a page. Objects and variable names are denoted by double curly braces: `{% raw %}{{{% endraw %}` and `{% raw %}}}{% endraw %}`.
```liquid
{% raw %}
{{ page.title }}
{% endraw %}
```
```text
Introduction
```
In this case, Liquid is rendering the content of an object called `page.title`, and that object contains the text `Introduction`.
## Tags
**Tags** create the logic and control flow for templates. They are denoted by curly braces and percent signs: `{% raw %}{%{% endraw %}` and `{% raw %}%}{% endraw %}`.
The markup used in tags does not produce any visible text. This means that you can assign variables and create conditions and loops without showing any of the Liquid logic on the page.
```liquid
{% raw %}
{% if user %}
Hello {{ user.name }}!
{% endif %}
{% endraw %}
```
```text
Hello Adam!
```
Tags can be categorized into three types:
- [Control flow](/tags/control-flow)
- [Iteration](/tags/iteration)
- [Variable assignments](/tags/variable)
You can read more about each type of tag in their respective sections.
## Filters
**Filters** change the output of a Liquid object. They are using within an output and are separated by a `|`.
```liquid
{% raw %}
{{ "/my/fancy/url" | append: ".html" }}
{% endraw %}
```
```text
{{ "/my/fancy/url" | append: ".html" }}
```
+88
View File
@@ -0,0 +1,88 @@
---
title: Operators
---
Liquid includes many logical and comparison operators.
## Basic operators
<table>
<tbody>
<tr>
<td><code>==</code></td>
<td>equals</td>
</tr>
<tr>
<td><code>!=</code></td>
<td>does not equal</td>
</tr>
<tr>
<td><code>&gt;</code></td>
<td>greater than</td>
</tr>
<tr>
<td><code>&lt;</code></td>
<td>less than</td>
</tr>
<tr>
<td><code>&gt;=</code></td>
<td>greater than or equal to</td>
</tr>
<tr>
<td><code>&lt;=</code></td>
<td>less than or equal to</td>
</tr>
<tr>
<td><code>or</code></td>
<td>logical or</td>
</tr>
<tr>
<td><code>and</code></td>
<td>logical and</td>
</tr>
</tbody>
</table>
For example:
```liquid
{% raw %}
{% if product.title == "Awesome Shoes" %}
These shoes are awesome!
{% endif %}
{% endraw %}
```
You can use multiple operators in a tag:
```liquid
{% raw %}
{% if product.type == "Shirt" or product.type == "Shoes" %}
This is a shirt or a pair of shoes.
{% endif %}
{% endraw %}
```
## contains
`contains` checks for the presence of a substring inside a string.
```liquid
{% raw %}
{% if product.title contains 'Pack' %}
This product's title contains the word Pack.
{% endif %}
{% endraw %}
```
`contains` can also check for the presence of a string in an array of strings.
```liquid
{% raw %}
{% if product.tags contains 'Hello' %}
This product has been tagged with 'Hello'.
{% endif %}
{% endraw %}
```
`contains` can only search strings. You cannot use it to check for an object in an array of objects.
+76
View File
@@ -0,0 +1,76 @@
---
title: Truthy and falsy
---
In programming, anything that returns `true` in a conditional is called **truthy**. Anything that returns `false` in a conditional is called **falsy**. All object types can be described as either truthy or falsy.
- [Truthy](#truthy)
- [Falsy](#falsy)
- [Summary](#summary)
## Truthy
All values in Liquid are truthy except `nil` and `false`.
In the example below, the string "Tobi" is not a boolean, but it is truthy in a conditional:
```liquid
{% raw %}
{% assign tobi = "Tobi" %}
{% if tobi == true %}
This condition will always be true.
{% endif %}
{% endraw %}
```
[Strings](/basics/types/#string), even when empty, are truthy. The example below will result in empty HTML tags if `settings.fp_heading` is empty:
```liquid
{% raw %}
{% if settings.fp_heading %}
<h1>{{ settings.fp_heading }}</h1>
{% endif %}
{% endraw %}
```
```html
<h1></h1>
```
[EmptyDrops](/basics/types/#emptydrop) are also truthy. In the example below, if `settings.page` is an empty string or set to a hidden or deleted object, you will end up with an EmptyDrop. The result is an empty `div`:
```liquid
{% raw %}
{% if pages[settings.page] %}
<div>{{ pages[settings.page].content }}</div>
{% endif %}
{% endraw %}
```
```html
<div></div>
```
## Falsy
The falsy values in Liquid are [`nil`](/basics/types/#nil) and [`false`](/basics/types/#boolean).
## Summary
The table below summarizes what is truthy or falsy in Liquid.
| | truthy | falsy |
| ------------- |:-------------:|:-------------:|
| true | • | |
| false | | • |
| nil | | • |
| string | • | |
| empty string | • | |
| 0 | • | |
| integer | • | |
| float | • | |
| array | • | |
| empty array | • | |
| page | • | |
| EmptyDrop | • | |
+160
View File
@@ -0,0 +1,160 @@
---
title: Types
---
Liquid objects can have one of six types:
- [String](#string)
- [Number](#number)
- [Boolean](#boolean)
- [Nil](#nil)
- [Array](#array)
- [EmptyDrop](#emptydrop)
You can initialize Liquid variables with the [assign](/tags/#assign) or [capture](/tags/#capture) tags.
## String
Declare a string by wrapping a variable's value in single or double quotes:
```liquid
{% raw %}
{% assign my_string = "Hello World!" %}
{% endraw %}
```
## Number
Numbers include floats and integers:
```liquid
{% raw %}
{% assign my_int = 25 %}
{% assign my_float = 39.756 %}
{% endraw %}
```
## Boolean
Booleans are either `true` or `false`. No quotations are necessary when declaring a boolean:
```liquid
{% raw %}
{% assign foo = true %}
{% assign bar = false %}
{% endraw %}
```
## Nil
Nil is a special empty value that is returned when Liquid code has no results. It is **not** a string with the characters "nil".
Nil is [treated as false](/basics/truthy-and-falsy) in the conditions of `if` blocks and other Liquid tags that check the truthfulness of a statement.
In the following example, if the user does not exist (that is, `user` returns `nil`), Liquid will not print the greeting:
```liquid
{% raw %}
{% if user %}
Hello {{ user.name }}!
{% endif %}
{% endraw %}
```
Tags or outputs that return `nil` will not print anything to the page.
```liquid
{% raw %}
The current user is {{ user.name }}
{% endraw %}
```
```text
The current user is
```
## Array
Arrays hold lists of variables of any type.
### Accessing items in arrays
To access all the items in an array, you can loop through each item in the array using an [iteration tag](/tags/iteration/).
```liquid
{% raw %}
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" -->
{% for user in site.users %}
{{ user }}
{% endfor %}
{% endraw %}
```
```text
{% raw %}
Tobi Laura Tetsuro Adam
{% endraw %}
```
### Accessing specific items in arrays
You can use square bracket `[` `]` notation to access a specific item in an array. Array indexing starts at zero.
```liquid
{% raw %}
<!-- if site.users = "Tobi", "Laura", "Tetsuro", "Adam" -->
{{ site.users[0] }}
{{ site.users[1] }}
{{ site.users[3] }}
{% endraw %}
```
```text
Tobi
Laura
Adam
```
### Initializing arrays
You cannot initialize arrays using only Liquid.
You can, however, use the [split](/filters/split) filter to break a string into an array of substrings.
## EmptyDrop
An EmptyDrop object is returned if you try to access a deleted object by name. In the example below, `page_1`, `page_2` and `page_3` are all EmptyDrop objects.
```liquid
{% raw %}
{% assign variable = "hello" %}
{% assign page_1 = pages[variable] %}
{% assign page_2 = pages["does-not-exist"] %}
{% assign page_3 = pages.this-handle-does-not-exist %}
{% endraw %}
```
EmptyDrop objects only have one attribute, `empty?`, which is always *true*.
Collections and pages that *do* exist do not have an `empty?` attribute. Their `empty?` is "falsy", which means that calling it inside an if statement will return *false*. When using an `unless` statement on existing collections and pages, `empty?` will return `true`.
### Checking for emptiness
Using the `empty?` attribute, you can check to see if an object exists or not before you access any of its attributes.
```liquid
{% raw %}
{% unless pages.about.empty? %}
<!-- This will only print if the page with handle 'about' is not empty -->
<h1>{{ pages.frontpage.title }}</h1>
<div>{{ pages.frontpage.content }}</div>
{% endunless %}
{% endraw %}
```
If you don't check for emptiness first, Liquid might print empty HTML elements to the page:
```html
<h1></h1>
<div></div>
```
-50
View File
@@ -1,50 +0,0 @@
# frozen_string_literal: true
module ProductsFilter
def price(integer)
format("$%.2d USD", integer / 100.0)
end
def prettyprint(text)
text.gsub(/\*(.*)\*/, '<b>\1</b>')
end
def count(array)
array.size
end
def paragraph(p)
"<p>#{p}</p>"
end
end
class Servlet < LiquidServlet
def index
{ 'date' => Time.now }
end
def products
{ 'products' => products_list, 'more_products' => more_products_list, 'description' => description, 'section' => 'Snowboards', 'cool_products' => true }
end
private
def products_list
[
{ 'name' => 'Arbor Draft', 'price' => 39900, 'description' => 'the *arbor draft* is a excellent product' },
{ 'name' => 'Arbor Element', 'price' => 40000, 'description' => 'the *arbor element* rocks for freestyling' },
{ 'name' => 'Arbor Diamond', 'price' => 59900, 'description' => 'the *arbor diamond* is a made up product because im obsessed with arbor and have no creativity' }
]
end
def more_products_list
[
{ 'name' => 'Arbor Catalyst', 'price' => 39900, 'description' => 'the *arbor catalyst* is an advanced drop-through for freestyle and flatground performance and versatility' },
{ 'name' => 'Arbor Fish', 'price' => 40000, 'description' => 'the *arbor fish* is a compact pin that features an extended wheelbase and time-honored teardrop shape' }
]
end
def description
"List of Products ~ This is a list of products with price and description."
end
end
-30
View File
@@ -1,30 +0,0 @@
# frozen_string_literal: true
class LiquidServlet < WEBrick::HTTPServlet::AbstractServlet
def do_GET(req, res)
handle(:get, req, res)
end
def do_POST(req, res)
handle(:post, req, res)
end
private
def handle(_type, req, res)
@request = req
@response = res
@request.path_info =~ /(\w+)\z/
@action = Regexp.last_match(1) || 'index'
@assigns = send(@action) if respond_to?(@action)
@response['Content-Type'] = "text/html"
@response.status = 200
@response.body = Liquid::Template.parse(read_template).render(@assigns, filters: [ProductsFilter])
end
def read_template(filename = @action)
File.read("#{__dir__}/templates/#{filename}.liquid")
end
end
-14
View File
@@ -1,14 +0,0 @@
# frozen_string_literal: true
require 'webrick'
require 'rexml/document'
require_relative '../../lib/liquid'
require_relative 'liquid_servlet'
require_relative 'example_servlet'
# Setup webrick
server = WEBrick::HTTPServer.new(Port: ARGV[1] || 3000)
server.mount('/', Servlet)
trap("INT") { server.shutdown }
server.start
-6
View File
@@ -1,6 +0,0 @@
<p>Hello world!</p>
<p>It is {{date}}</p>
<p>Check out the <a href="/products">Products</a> screen </p>
-49
View File
@@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
<title>products</title>
<meta name="ROBOTS" content="ALL" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="Copyright" content="(c) 2005 Copyright content: Copyright design: Tobias Luetke" />
<!-- (c) Copyright 2005 by Tobias Luetke All Rights Reserved. -->
</head>
<body>
{% assign all_products = products | concat: more_products %}
<h1>{{ description | split: '~' | first }}</h1>
<h2>{{ description | split: '~' | last }}</h2>
<h2>There are currently {{all_products | count}} products in the {{section}} catalog</h2>
{% if cool_products %}
Cool products :)
{% else %}
Uncool products :(
{% endif %}
<ul id="products">
{% for product in all_products %}
<li>
<h2>{{product.name}}</h2>
Only {{product.price | price }}
{{product.description | prettyprint | paragraph }}
{{ 'it rocks!' | paragraph }}
</li>
{% endfor %}
</ul>
</body>
</html>
+30
View File
@@ -0,0 +1,30 @@
---
layout: null
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ site.title | xml_escape }}</title>
<description>{{ site.description | xml_escape }}</description>
<link>{{ site.url }}{{ site.baseurl }}/</link>
<atom:link href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.url }}" rel="self" type="application/rss+xml"/>
<pubDate>{{ site.time | date_to_rfc822 }}</pubDate>
<lastBuildDate>{{ site.time | date_to_rfc822 }}</lastBuildDate>
<generator>Jekyll v{{ jekyll.version }}</generator>
{% for post in site.posts limit:10 %}
<item>
<title>{{ post.title | xml_escape }}</title>
<description>{{ post.content | xml_escape }}</description>
<pubDate>{{ post.date | date_to_rfc822 }}</pubDate>
<link>{{ post.url | prepend: site.baseurl | prepend: site.url }}</link>
<guid isPermaLink="true">{{ post.url | prepend: site.baseurl | prepend: site.url }}</guid>
{% for tag in post.tags %}
<category>{{ tag | xml_escape }}</category>
{% endfor %}
{% for cat in post.categories %}
<category>{{ cat | xml_escape }}</category>
{% endfor %}
</item>
{% endfor %}
</channel>
</rss>
+29
View File
@@ -0,0 +1,29 @@
---
title: append
---
Concatenates two strings and returns the concatenated value.
```liquid
{% raw %}
{{ "/my/fancy/url" | append: ".html" }}
{% endraw %}
```
```text
{{ "/my/fancy/url" | append: ".html" }}
```
`append` can also be used with variables:
```liquid
{% raw %}
{% assign filename = "/index.html" %}
{{ "website.com" | append: filename }}
{% endraw %}
```
```text
{% assign filename = "/index.html" %}
{{ "website.com" | append: filename }}
```
+27
View File
@@ -0,0 +1,27 @@
---
title: capitalize
---
Makes the first character of a string capitalized.
```liquid
{% raw %}
{{ "title" | capitalize }}
{% endraw %}
```
```text
Title
```
`capitalize` only capitalizes the first character of the string, so later words are not affected:
```liquid
{% raw %}
{{ "my great title" | capitalize }}
{% endraw %}
```
```text
My great title
```
+47
View File
@@ -0,0 +1,47 @@
---
title: ceil
---
Rounds the input up to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
```liquid
{% raw %}
{{ 1.2 | ceil }}
{% endraw %}
```
```text
{{ 1.2 | ceil }}
```
```liquid
{% raw %}
{{ 2.0 | ceil }}
{% endraw %}
```
```text
{{ 2.0 | ceil }}
```
```liquid
{% raw %}
{{ 183.357 | ceil }}
{% endraw %}
```
```text
{{ 183.357 | ceil }}
```
Here the input value is a string:
```liquid
{% raw %}
{{ "3.5" | ceil }}
{% endraw %}
```
```text
{{ "3.5" | ceil }}
```
+37
View File
@@ -0,0 +1,37 @@
---
title: date
---
Converts a timestamp into another date format. The format for this syntax is the same as [`strftime`](//strftime.net).
```liquid
{% raw %}
{{ article.published_at | date: "%a, %b %d, %y" }}
{% endraw %}
```
```text
Fri, Jul 17, 15
```
```liquid
{% raw %}
{{ article.published_at | date: "%Y" }}
{% endraw %}
```
```text
2015
```
`date` works on strings if they contain well-formatted dates:
```liquid
{% raw %}
{{ "March 14, 2016" | date: "%b %d, %y" }}
{% endraw %}
```
```text
{{ "March 14, 2016" | date: "%b %d, %y" }}
```
+44
View File
@@ -0,0 +1,44 @@
---
title: default
---
Allows you to specify a fallback in case a value doesn't exist. `default` will show its value if the left side is `nil`, `false`, or empty.
In this example, `product_price` is not defined, so the default value is used.
```liquid
{% raw %}
{{ product_price | default: 2.99 }}
{% endraw %}
```
```text
2.99
```
In this example, `product_price` is defined, so the default value is not used.
```liquid
{% raw %}
{% assign product_price = 4.99 %}
{{ product_price | default: 2.99 }}
{% endraw %}
```
```text
4.99
```
In this example, `product_price` is empty, so the default value is used.
```liquid
{% raw %}
{% assign product_price = "" %}
{{ product_price | default: 2.99 }}
{% endraw %}
```
```text
2.99
```
+37
View File
@@ -0,0 +1,37 @@
---
title: divided_by
---
Divides a number by the specified number.
The result is rounded down to the nearest integer (that is, the [floor](/filters/floor)).
```liquid
{% raw %}
{{ 4 | divided_by: 2 }}
{% endraw %}
```
```text
{{ 4 | divided_by: 2 }}
```
```liquid
{% raw %}
{{ 16 | divided_by: 4 }}
{% endraw %}
```
```text
{{ 16 | divided_by: 4 }}
```
```liquid
{% raw %}
{{ 5 | divided_by: 3 }}
{% endraw %}
```
```text
{{ 5 | divided_by: 3 }}
```
+25
View File
@@ -0,0 +1,25 @@
---
title: downcase
---
Makes each character in a string lowercase. It has no effect on strings which are already all lowercase.
```liquid
{% raw %}
{{ "Parker Moore" | downcase }}
{% endraw %}
```
```text
{{ "Parker Moore" | downcase }}
```
```liquid
{% raw %}
{{ "apple" | downcase }}
{% endraw %}
```
```text
{{ "apple" | downcase }}
```
+25
View File
@@ -0,0 +1,25 @@
---
title: escape
---
Escapes a string by replacing characters with escape sequences (so that the string can be used in a URL, for example). It doesn't change strings that don't have anything to escape.
```liquid
{% raw %}
{{ "Have you read 'James & the Giant Peach'?" | escape }}
{% endraw %}
```
```text
{{ "Have you read 'James & the Giant Peach'?" | escape }}
```
```liquid
{% raw %}
{{ "Tetsuro Takara" | escape }}
{% endraw %}
```
```text
{{ "Tetsuro Takara" | escape }}
```
+25
View File
@@ -0,0 +1,25 @@
---
title: escape_once
---
Escapes a string without changing existing escaped entities. It doesn't change strings that don't have anything to escape.
```liquid
{% raw %}
{{ "1 < 2 & 3" | escape_once }}
{% endraw %}
```
```text
{{ "1 < 2 & 3" | escape_once }}
```
```liquid
{% raw %}
{{ "1 &lt; 2 &amp; 3" | escape_once }}
{% endraw %}
```
```text
{{ "1 &lt; 2 &amp; 3" | escape_once }}
```
+33
View File
@@ -0,0 +1,33 @@
---
title: first
---
Returns the first item of an array.
```liquid
{% raw %}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.first }}
{% endraw %}
```
```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.first }}
```
```liquid
{% raw %}
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.first }}
{% endraw %}
```
```text
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.first }}
```
+47
View File
@@ -0,0 +1,47 @@
---
title: floor
---
Rounds a number down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.
```liquid
{% raw %}
{{ 1.2 | floor }}
{% endraw %}
```
```text
{{ 1.2 | floor }}
```
```liquid
{% raw %}
{{ 2.0 | floor }}
{% endraw %}
```
```text
{{ 2.0 | floor }}
```
```liquid
{% raw %}
{{ 183.357 | floor }}
{% endraw %}
```
```text
{{ 183.357 | floor }}
```
Here the input value is a string:
```liquid
{% raw %}
{{ "3.5" | floor }}
{% endraw %}
```
```text
{{ "3.5" | floor }}
```
+10
View File
@@ -0,0 +1,10 @@
---
layout: default
---
{% for doc in site.collections["filters"].docs %}
<h2 id="{{ doc.title | slugify }}">{{ doc.title }}</h2>
<div class="content">
{{ doc.content }}
</div>
{% endfor %}
+19
View File
@@ -0,0 +1,19 @@
---
title: join
---
Combines the items in an array into a single string using the argument as a separator.
```liquid
{% raw %}
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{{ beatles | join: " and " }}
{% endraw %}
```
```text
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{{ beatles | join: " and " }}
```
+33
View File
@@ -0,0 +1,33 @@
---
title: last
---
Returns the last item of an array.
```liquid
{% raw %}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.last }}
{% endraw %}
```
```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array.last }}
```
```liquid
{% raw %}
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.last }}
{% endraw %}
```
```text
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
{{ my_array.last }}
```
+15
View File
@@ -0,0 +1,15 @@
---
title: lstrip
---
Removes all whitespaces (tabs, spaces, and newlines) from the beginning of a string. The filter does not affect spaces between words.
```liquid
{% raw %}
{{ " So much room for activities! " | lstrip }}
{% endraw %}
```
```text
{{ " So much room for activities! " | lstrip }}
```
+25
View File
@@ -0,0 +1,25 @@
---
title: map
---
Creates an array of values by extracting the values of a named property from another object.
In this example, assume the object `site.pages` contains all the metadata for a website. Using `assign` with the `map` filter creates a variable that contains only the values of the `category` properties of everything in the `site.pages` object.
```liquid
{% raw %}
{% assign all_categories = site.pages | map: "category" %}
{% for item in all_categories %}
{{ item }}
{% endfor %}
{% endraw %}
```
```text
business
celebrities
lifestyle
sports
technology
```
+35
View File
@@ -0,0 +1,35 @@
---
title: minus
---
Subtracts a number from another number.
```liquid
{% raw %}
{{ 4 | minus: 2 }}
{% endraw %}
```
```text
{{ 4 | minus: 2 }}
```
```liquid
{% raw %}
{{ 16 | minus: 4 }}
{% endraw %}
```
```text
{{ 16 | minus: 4 }}
```
```liquid
{% raw %}
{{ 183.357 | minus: 12 }}
{% endraw %}
```
```text
{{ 183.357 | minus: 12 }}
```
+35
View File
@@ -0,0 +1,35 @@
---
title: modulo
---
Returns the remainder of a division operation.
```liquid
{% raw %}
{{ 3 | modulo: 2 }}
{% endraw %}
```
```text
{{ 3 | modulo: 2 }}
```
```liquid
{% raw %}
{{ 24 | modulo: 7 }}
{% endraw %}
```
```text
{{ 24 | modulo: 7 }}
```
```liquid
{% raw %}
{{ 183.357 | modulo: 12 }}
{% endraw %}
```
```text
{{ 183.357 | modulo: 12 }}
```
+25
View File
@@ -0,0 +1,25 @@
---
title: newline_to_br
---
Replaces every newline (`\n`) with an HTML line break (`<br>`).
```liquid
{% raw %}
{% capture string_with_newlines %}
Hello
there
{% endcapture %}
{{ string_with_newlines | newline_to_br }}
{% endraw %}
```
```html
{% capture string_with_newlines %}
Hello
there
{% endcapture %}
{{ string_with_newlines | newline_to_br }}
```
+35
View File
@@ -0,0 +1,35 @@
---
title: plus
---
Adds a number to another number.
```liquid
{% raw %}
{{ 4 | plus: 2 }}
{% endraw %}
```
```text
{{ 4 | plus: 2 }}
```
```liquid
{% raw %}
{{ 16 | plus: 4 }}
{% endraw %}
```
```text
{{ 16 | plus: 4 }}
```
```liquid
{% raw %}
{{ 183.357 | plus: 12 }}
{% endraw %}
```
```text
{{ 183.357 | plus: 12 }}
```
+31
View File
@@ -0,0 +1,31 @@
---
title: prepend
---
Adds the specified string to the beginning of another string.
```liquid
{% raw %}
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
{% endraw %}
```
```text
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
```
You can also `prepend` variables:
```liquid
{% raw %}
{% assign url = "liquidmarkup.com" %}
{{ "/index.html" | prepend: url }}
{% endraw %}
```
```text
{% assign url = "liquidmarkup.com" %}
{{ "/index.html" | prepend: url }}
```
+15
View File
@@ -0,0 +1,15 @@
---
title: remove
---
Removes every occurrence of the specified substring from a string.
```liquid
{% raw %}
{{ "I strained to see the train through the rain" | remove: "rain" }}
{% endraw %}
```
```text
{{ "I strained to see the train through the rain" | remove: "rain" }}
```
+15
View File
@@ -0,0 +1,15 @@
---
title: remove_first
---
Removes only the first occurrence of the specified substring from a string.
```liquid
{% raw %}
{{ "I strained to see the train through the rain" | remove_first: "rain" }}
{% endraw %}
```
```text
{{ "I strained to see the train through the rain" | remove_first: "rain" }}
```
+15
View File
@@ -0,0 +1,15 @@
---
title: replace
---
Replaces every occurrence of an argument in a string with the second argument.
```liquid
{% raw %}
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
{% endraw %}
```
```text
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
```
+17
View File
@@ -0,0 +1,17 @@
---
title: replace_first
---
Replaces only the first occurrence of the first argument in a string with the second argument.
```liquid
{% raw %}
{% assign my_string = "Take my protein pills and put my helmet on" %}
{{ my_string | replace_first: "my", "your" }}
{% endraw %}
```
```text
{% assign my_string = "Take my protein pills and put my helmet on" %}
{{ my_string | replace_first: "my", "your" }}
```
+31
View File
@@ -0,0 +1,31 @@
---
title: reverse
---
Reverses the order of the items in an array. `reverse` cannot reverse a string.
```liquid
{% raw %}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | reverse | join: ", " }}
{% endraw %}
```
```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | reverse | join: ", " }}
```
`reverse` cannot be used directly on a string, but you can split a string into an array, reverse the array, and rejoin it by chaining together filters:
```liquid
{% raw %}
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}
{% endraw %}
```
```text
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}
```
+35
View File
@@ -0,0 +1,35 @@
---
title: round
---
Rounds an input number to the nearest integer or, if a number is specified as an argument, to that number of decimal places.
```liquid
{% raw %}
{{ 1.2 | round }}
{% endraw %}
```
```text
{{ 1.2 | round }}
```
```liquid
{% raw %}
{{ 2.7 | round }}
{% endraw %}
```
```text
{{ 2.7 | round }}
```
```liquid
{% raw %}
{{ 183.357 | round: 2 }}
{% endraw %}
```
```text
{{ 183.357 | round: 2 }}
```
+15
View File
@@ -0,0 +1,15 @@
---
title: rstrip
---
Removes all whitespace (tabs, spaces, and newlines) from the right side of a string.
```liquid
{% raw %}
{{ " So much room for activities! " | rstrip }}
{% endraw %}
```
```text
{{ " So much room for activities! " | rstrip }}
```
+39
View File
@@ -0,0 +1,39 @@
---
title: size
---
Returns the number of characters in a string or the number of items in an array. `size` can also be used with dot notation (for example, `{% raw %}{{ my_string.size }}{% endraw %}`). This allows you to use `size` inside tags such as conditionals.
```liquid
{% raw %}
{{ "Ground control to Major Tom." | size }}
{% endraw %}
```
```text
{{ "Ground control to Major Tom." | size }}
```
```liquid
{% raw %}
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | size }}
{% endraw %}
```
```text
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
{{ my_array | size }}
```
Using dot notation:
```liquid
{% raw %}
{% if site.pages.size > 10 %}
This is a big website!
{% endif %}
{% endraw %}
```
+49
View File
@@ -0,0 +1,49 @@
---
title: slice
---
Returns a substring of 1 character beginning at the index specified by the argument passed in. An optional second argument specifies the length of the substring to be returned.
String indices are numbered starting from 0.
```liquid
{% raw %}
{{ "Liquid" | slice: 0 }}
{% endraw %}
```
```text
{{ "Liquid" | slice: 0 }}
```
```liquid
{% raw %}
{{ "Liquid" | slice: 2 }}
{% endraw %}
```
```text
{{ "Liquid" | slice: 2 }}
```
```liquid
{% raw %}
{{ "Liquid" | slice: 2, 5 }}
{% endraw %}
```
```text
{{ "Liquid" | slice: 2, 5 }}
```
If the first parameter is a negative number, the indices are counted from the end of the string:
```liquid
{% raw %}
{{ "Liquid" | slice: -3, 2 }}
{% endraw %}
```
```text
{{ "Liquid" | slice: -3, 2 }}
```
+19
View File
@@ -0,0 +1,19 @@
---
title: sort
---
Sorts items in an array by a property of an item in the array. The order of the sorted array is case-sensitive.
```liquid
{% raw %}
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort | join: ", " }}
{% endraw %}
```
```text
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
{{ my_array | sort | join: ", " }}
```
+23
View File
@@ -0,0 +1,23 @@
---
title: split
---
Divides an input string into an array using the argument as a separator. `split` is commonly used to convert comma-separated items from a string to an array.
```liquid
{% raw %}
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{% for member in beatles %}
{{ member }}
{% endfor %}
{% endraw %}
```
```text
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{% for member in beatles %}
{{ member }}
{% endfor %}
```
+15
View File
@@ -0,0 +1,15 @@
---
title: strip
---
Removes all whitespace (tabs, spaces, and newlines) from both the left and right side of a string. It does not affect spaces between words.
```liquid
{% raw %}
{{ " So much room for activities! " | strip }}
{% endraw %}
```
```text
{{ " So much room for activities! " | strip }}
```
+15
View File
@@ -0,0 +1,15 @@
---
title: strip_html
---
Removes any HTML tags from a string.
```liquid
{% raw %}
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
{% endraw %}
```
```text
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
```
+26
View File
@@ -0,0 +1,26 @@
---
title: strip_newlines
---
Removes any newline characters (line breaks) from a string.
```liquid
{% raw %}
{% capture string_with_newlines %}
Hello
there
{% endcapture %}
{{ string_with_newlines | strip_newlines }}
{% endraw %}
```
```html
{% capture string_with_newlines %}
Hello
there
{% endcapture %}
{{ string_with_newlines | strip_newlines }}
```
+35
View File
@@ -0,0 +1,35 @@
---
title: times
---
Multiplies a number by another number.
```liquid
{% raw %}
{{ 3 | times: 2 }}
{% endraw %}
```
```text
{{ 3 | times: 2 }}
```
```liquid
{% raw %}
{{ 24 | times: 7 }}
{% endraw %}
```
```text
{{ 24 | times: 7 }}
```
```liquid
{% raw %}
{{ 183.357 | times: 12 }}
{% endraw %}
```
```text
{{ 183.357 | times: 12 }}
```
+15
View File
@@ -0,0 +1,15 @@
---
title: truncate
---
`truncate` shortens a string down to the number of characters passed as a parameter. If the number of characters specified is less than the length of the string, an ellipsis (...) is appended to the string and is included in the character count.
```liquid
{% raw %}
{{ "Ground control to Major Tom." | truncate: 20 }}
{% endraw %}
```
```text
{{ "Ground control to Major Tom." | truncate: 20 }}
```
+15
View File
@@ -0,0 +1,15 @@
---
title: truncatewords
---
Shortens a string down to the number of words passed as the argument. If the specified number of words is less than the number of words in the string, an ellipsis (...) is appended to the string.
```liquid
{% raw %}
{{ "Ground control to Major Tom." | truncatewords: 3 }}
{% endraw %}
```
```text
{{ "Ground control to Major Tom." | truncatewords: 3 }}
```
+19
View File
@@ -0,0 +1,19 @@
---
title: uniq
---
Removes any duplicate elements in an array.
```liquid
{% raw %}
{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}
{{ my_array | uniq | join: ", " }}
{% endraw %}
```
```text
{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}
{{ my_array | uniq | join: ", " }}
```
+25
View File
@@ -0,0 +1,25 @@
---
title: upcase
---
Makes each character in a string uppercase. It has no effect on strings which are already all uppercase.
```liquid
{% raw %}
{{ "Parker Moore" | upcase }}
{% endraw %}
```
```text
{{ "Parker Moore" | upcase }}
```
```liquid
{% raw %}
{{ "APPLE" | upcase }}
{% endraw %}
```
```text
{{ "APPLE" | upcase }}
```
+25
View File
@@ -0,0 +1,25 @@
---
title: url_encode
---
Converts any URL-unsafe characters in a string into percent-encoded characters.
```liquid
{% raw %}
{{ "john@liquid.com" | url_encode }}
{% endraw %}
```
```text
{{ "john@liquid.com" | url_encode }}
```
```liquid
{% raw %}
{{ "Tetsuro Takara" | url_encode }}
{% endraw %}
```
```text
{{ "Tetsuro Takara" | url_encode }}
```
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

+16
View File
@@ -0,0 +1,16 @@
---
layout: default
---
{% include home-banner.html %}
## What is Liquid?
Liquid is an open-source template language created by [Shopify](https://www.shopify.com) and written in Ruby. It is the backbone of Shopify themes and is used to load dynamic content on storefronts.
Liquid has been in production use since June 2006 and is now used by many other hosted web applications.
## Who uses Liquid?
{% include home-users-grid.html %}
-91
View File
@@ -1,91 +0,0 @@
# frozen_string_literal: true
# Copyright (c) 2005 Tobias Luetke
#
# 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.
require "strscan"
module Liquid
FilterSeparator = /\|/
ArgumentSeparator = ','
FilterArgumentSeparator = ':'
VariableAttributeSeparator = '.'
WhitespaceControl = '-'
TagStart = /\{\%/
TagEnd = /\%\}/
TagName = /#|\w+/
VariableSignature = /\(?[\w\-\.\[\]]\)?/
VariableSegment = /[\w\-]/
VariableStart = /\{\{/
VariableEnd = /\}\}/
VariableIncompleteEnd = /\}\}?/
QuotedString = /"[^"]*"|'[^']*'/
QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
TagAttributes = /(\w[\w-]*)\s*\:\s*(#{QuotedFragment})/o
AnyStartingTag = /#{TagStart}|#{VariableStart}/o
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
VariableParser = /\[(?>[^\[\]]+|\g<0>)*\]|#{VariableSegment}+\??/o
RAISE_EXCEPTION_LAMBDA = ->(_e) { raise }
HAS_STRING_SCANNER_SCAN_BYTE = StringScanner.instance_methods.include?(:scan_byte)
end
require "liquid/version"
require "liquid/deprecations"
require "liquid/const"
require 'liquid/standardfilters'
require 'liquid/file_system'
require 'liquid/parser_switching'
require 'liquid/tag'
require 'liquid/block'
require 'liquid/parse_tree_visitor'
require 'liquid/interrupts'
require 'liquid/tags'
require "liquid/environment"
require 'liquid/lexer'
require 'liquid/parser'
require 'liquid/i18n'
require 'liquid/drop'
require 'liquid/tablerowloop_drop'
require 'liquid/forloop_drop'
require 'liquid/extensions'
require 'liquid/errors'
require 'liquid/interrupts'
require 'liquid/strainer_template'
require 'liquid/context'
require 'liquid/tag'
require 'liquid/block_body'
require 'liquid/document'
require 'liquid/variable'
require 'liquid/variable_lookup'
require 'liquid/range_lookup'
require 'liquid/resource_limits'
require 'liquid/expression'
require 'liquid/template'
require 'liquid/condition'
require 'liquid/utils'
require 'liquid/tokenizer'
require 'liquid/parse_context'
require 'liquid/partial_cache'
require 'liquid/usage'
require 'liquid/registers'
require 'liquid/template_factory'
-98
View File
@@ -1,98 +0,0 @@
# frozen_string_literal: true
module Liquid
class Block < Tag
MAX_DEPTH = 100
def initialize(tag_name, markup, options)
super
@blank = true
end
def parse(tokens)
@body = new_body
while parse_body(@body, tokens)
end
@body.freeze
end
# For backwards compatibility
def render(context)
@body.render(context)
end
def blank?
@blank
end
def nodelist
@body.nodelist
end
def unknown_tag(tag_name, _markup, _tokenizer)
Block.raise_unknown_tag(tag_name, block_name, block_delimiter, parse_context)
end
# @api private
def self.raise_unknown_tag(tag, block_name, block_delimiter, parse_context)
if tag == 'else'
raise SyntaxError, parse_context.locale.t(
"errors.syntax.unexpected_else",
block_name: block_name,
)
elsif tag.start_with?('end')
raise SyntaxError, parse_context.locale.t(
"errors.syntax.invalid_delimiter",
tag: tag,
block_name: block_name,
block_delimiter: block_delimiter,
)
else
raise SyntaxError, parse_context.locale.t("errors.syntax.unknown_tag", tag: tag)
end
end
def raise_tag_never_closed(block_name)
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_never_closed", block_name: block_name)
end
def block_name
@tag_name
end
def block_delimiter
@block_delimiter ||= "end#{block_name}"
end
private
# @api public
def new_body
parse_context.new_block_body
end
# @api public
def parse_body(body, tokens)
if parse_context.depth >= MAX_DEPTH
raise StackLevelError, "Nesting too deep"
end
parse_context.depth += 1
begin
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
@blank &&= body.blank?
return false if end_tag_name == block_delimiter
raise_tag_never_closed(block_name) unless end_tag_name
# this tag is not registered with the system
# pass it to the current block for special handling or error reporting
unknown_tag(end_tag_name, end_tag_params, tokens)
end
ensure
parse_context.depth -= 1
end
true
end
end
end
-273
View File
@@ -1,273 +0,0 @@
# frozen_string_literal: true
require 'English'
module Liquid
class BlockBody
LiquidTagToken = /\A\s*(#{TagName})\s*(.*?)\z/o
FullToken = /\A#{TagStart}#{WhitespaceControl}?(\s*)(#{TagName})(\s*)(.*?)#{WhitespaceControl}?#{TagEnd}\z/om
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}#{WhitespaceControl}?\s*(\w+)\s*(.*)?#{WhitespaceControl}?#{TagEnd}\z/om
ContentOfVariable = /\A#{VariableStart}#{WhitespaceControl}?(.*?)#{WhitespaceControl}?#{VariableEnd}\z/om
WhitespaceOrNothing = /\A\s*\z/
TAGSTART = "{%"
VARSTART = "{{"
attr_reader :nodelist
def initialize
@nodelist = []
@blank = true
end
def parse(tokenizer, parse_context, &block)
raise FrozenError, "can't modify frozen Liquid::BlockBody" if frozen?
parse_context.line_number = tokenizer.line_number
if tokenizer.for_liquid_tag
parse_for_liquid_tag(tokenizer, parse_context, &block)
else
parse_for_document(tokenizer, parse_context, &block)
end
end
def freeze
@nodelist.freeze
super
end
private def parse_for_liquid_tag(tokenizer, parse_context)
while (token = tokenizer.shift)
unless token.empty? || token.match?(WhitespaceOrNothing)
unless token =~ LiquidTagToken
# line isn't empty but didn't match tag syntax, yield and let the
# caller raise a syntax error
return yield token, token
end
tag_name = Regexp.last_match(1)
markup = Regexp.last_match(2)
if tag_name == 'liquid'
parse_context.line_number -= 1
next parse_liquid_tag(markup, parse_context)
end
unless (tag = parse_context.environment.tag_for_name(tag_name))
# end parsing if we reach an unknown tag and let the caller decide
# determine how to proceed
return yield tag_name, markup
end
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
@blank &&= new_tag.blank?
@nodelist << new_tag
end
parse_context.line_number = tokenizer.line_number
end
yield nil, nil
end
# @api private
def self.unknown_tag_in_liquid_tag(tag, parse_context)
Block.raise_unknown_tag(tag, 'liquid', '%}', parse_context)
end
# @api private
def self.raise_missing_tag_terminator(token, parse_context)
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_termination", token: token, tag_end: TagEnd.inspect)
end
# @api private
def self.raise_missing_variable_terminator(token, parse_context)
raise SyntaxError, parse_context.locale.t("errors.syntax.variable_termination", token: token, tag_end: VariableEnd.inspect)
end
# @api private
def self.render_node(context, output, node)
node.render_to_output_buffer(context, output)
rescue => exc
blank_tag = !node.instance_of?(Variable) && node.blank?
rescue_render_node(context, output, node.line_number, exc, blank_tag)
end
# @api private
def self.rescue_render_node(context, output, line_number, exc, blank_tag)
case exc
when MemoryError
raise
when UndefinedVariable, UndefinedDropMethod, UndefinedFilter
context.handle_error(exc, line_number)
else
error_message = context.handle_error(exc, line_number)
unless blank_tag # conditional for backwards compatibility
output << error_message
end
end
end
private def parse_liquid_tag(markup, parse_context)
liquid_tag_tokenizer = parse_context.new_tokenizer(
markup, start_line_number: parse_context.line_number, for_liquid_tag: true
)
parse_for_liquid_tag(liquid_tag_tokenizer, parse_context) do |end_tag_name, _end_tag_markup|
if end_tag_name
BlockBody.unknown_tag_in_liquid_tag(end_tag_name, parse_context)
end
end
end
private def handle_invalid_tag_token(token, parse_context)
if token.end_with?('%}')
yield token, token
else
BlockBody.raise_missing_tag_terminator(token, parse_context)
end
end
private def parse_for_document(tokenizer, parse_context, &block)
while (token = tokenizer.shift)
next if token.empty?
case
when token.start_with?(TAGSTART)
whitespace_handler(token, parse_context)
unless token =~ FullToken
return handle_invalid_tag_token(token, parse_context, &block)
end
tag_name = Regexp.last_match(2)
markup = Regexp.last_match(4)
if parse_context.line_number
# newlines inside the tag should increase the line number,
# particularly important for multiline {% liquid %} tags
parse_context.line_number += Regexp.last_match(1).count("\n") + Regexp.last_match(3).count("\n")
end
if tag_name == 'liquid'
parse_liquid_tag(markup, parse_context)
next
end
unless (tag = parse_context.environment.tag_for_name(tag_name))
# end parsing if we reach an unknown tag and let the caller decide
# determine how to proceed
return yield tag_name, markup
end
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
@blank &&= new_tag.blank?
@nodelist << new_tag
when token.start_with?(VARSTART)
whitespace_handler(token, parse_context)
@nodelist << create_variable(token, parse_context)
@blank = false
else
if parse_context.trim_whitespace
token.lstrip!
end
parse_context.trim_whitespace = false
@nodelist << token
@blank &&= token.match?(WhitespaceOrNothing)
end
parse_context.line_number = tokenizer.line_number
end
yield nil, nil
end
def whitespace_handler(token, parse_context)
if token[2] == WhitespaceControl
previous_token = @nodelist.last
if previous_token.is_a?(String)
first_byte = previous_token.getbyte(0)
previous_token.rstrip!
if previous_token.empty? && parse_context[:bug_compatible_whitespace_trimming] && first_byte
previous_token << first_byte
end
end
end
parse_context.trim_whitespace = (token[-3] == WhitespaceControl)
end
def blank?
@blank
end
# Remove blank strings in the block body for a control flow tag (e.g. `if`, `for`, `case`, `unless`)
# with a blank body.
#
# For example, in a conditional assignment like the following
#
# ```
# {% if size > max_size %}
# {% assign size = max_size %}
# {% endif %}
# ```
#
# we assume the intention wasn't to output the blank spaces in the `if` tag's block body, so this method
# will remove them to reduce the render output size.
#
# Note that it is now preferred to use the `liquid` tag for this use case.
def remove_blank_strings
raise "remove_blank_strings only support being called on a blank block body" unless @blank
@nodelist.reject! { |node| node.instance_of?(String) }
end
def render(context)
render_to_output_buffer(context, +'')
end
def render_to_output_buffer(context, output)
freeze unless frozen?
context.resource_limits.increment_render_score(@nodelist.length)
idx = 0
while (node = @nodelist[idx])
if node.instance_of?(String)
output << node
else
render_node(context, output, node)
# If we get an Interrupt that means the block must stop processing. An
# Interrupt is any command that stops block execution such as {% break %}
# or {% continue %}. These tags may also occur through Block or Include tags.
break if context.interrupt? # might have happened in a for-block
end
idx += 1
context.resource_limits.increment_write_score(output)
end
output
end
private
def render_node(context, output, node)
BlockBody.render_node(context, output, node)
end
def create_variable(token, parse_context)
if token.end_with?("}}")
i = 2
i = 3 if token[i] == "-"
parse_end = token.length - 3
parse_end -= 1 if token[parse_end] == "-"
markup_end = parse_end - i + 1
markup = markup_end <= 0 ? "" : token.slice(i, markup_end)
return Variable.new(markup, parse_context)
end
BlockBody.raise_missing_variable_terminator(token, parse_context)
end
# @deprecated Use {.raise_missing_tag_terminator} instead
def raise_missing_tag_terminator(token, parse_context)
BlockBody.raise_missing_tag_terminator(token, parse_context)
end
# @deprecated Use {.raise_missing_variable_terminator} instead
def raise_missing_variable_terminator(token, parse_context)
BlockBody.raise_missing_variable_terminator(token, parse_context)
end
end
end
-183
View File
@@ -1,183 +0,0 @@
# frozen_string_literal: true
module Liquid
# Container for liquid nodes which conveniently wraps decision making logic
#
# Example:
#
# c = Condition.new(1, '==', 1)
# c.evaluate #=> true
#
class Condition # :nodoc:
@@operators = {
'==' => ->(cond, left, right) { cond.send(:equal_variables, left, right) },
'!=' => ->(cond, left, right) { !cond.send(:equal_variables, left, right) },
'<>' => ->(cond, left, right) { !cond.send(:equal_variables, left, right) },
'<' => :<,
'>' => :>,
'>=' => :>=,
'<=' => :<=,
'contains' => lambda do |_cond, left, right|
if left && right && left.respond_to?(:include?)
right = right.to_s if left.is_a?(String)
left.include?(right)
else
false
end
rescue Encoding::CompatibilityError
# "✅".b.include?("✅") raises Encoding::CompatibilityError despite being materially equal
left.b.include?(right.b)
end,
}
class MethodLiteral
attr_reader :method_name, :to_s
def initialize(method_name, to_s)
@method_name = method_name
@to_s = to_s
end
end
@@method_literals = {
'blank' => MethodLiteral.new(:blank?, '').freeze,
'empty' => MethodLiteral.new(:empty?, '').freeze,
}
def self.operators
@@operators
end
def self.parse_expression(parse_context, markup)
@@method_literals[markup] || parse_context.parse_expression(markup)
end
attr_reader :attachment, :child_condition
attr_accessor :left, :operator, :right
def initialize(left = nil, operator = nil, right = nil)
@left = left
@operator = operator
@right = right
@child_relation = nil
@child_condition = nil
end
def evaluate(context = deprecated_default_context)
condition = self
result = nil
loop do
result = interpret_condition(condition.left, condition.right, condition.operator, context)
case condition.child_relation
when :or
break if Liquid::Utils.to_liquid_value(result)
when :and
break unless Liquid::Utils.to_liquid_value(result)
else
break
end
condition = condition.child_condition
end
result
end
def or(condition)
@child_relation = :or
@child_condition = condition
end
def and(condition)
@child_relation = :and
@child_condition = condition
end
def attach(attachment)
@attachment = attachment
end
def else?
false
end
def inspect
"#<Condition #{[@left, @operator, @right].compact.join(' ')}>"
end
protected
attr_reader :child_relation
private
def equal_variables(left, right)
if left.is_a?(MethodLiteral)
if right.respond_to?(left.method_name)
return right.send(left.method_name)
else
return nil
end
end
if right.is_a?(MethodLiteral)
if left.respond_to?(right.method_name)
return left.send(right.method_name)
else
return nil
end
end
left == right
end
def interpret_condition(left, right, op, context)
# If the operator is empty this means that the decision statement is just
# a single variable. We can just poll this variable from the context and
# return this as the result.
return context.evaluate(left) if op.nil?
left = Liquid::Utils.to_liquid_value(context.evaluate(left))
right = Liquid::Utils.to_liquid_value(context.evaluate(right))
operation = self.class.operators[op] || raise(Liquid::ArgumentError, "Unknown operator #{op}")
if operation.respond_to?(:call)
operation.call(self, left, right)
elsif left.respond_to?(operation) && right.respond_to?(operation) && !left.is_a?(Hash) && !right.is_a?(Hash)
begin
left.send(operation, right)
rescue ::ArgumentError => e
raise Liquid::ArgumentError, e.message
end
end
end
def deprecated_default_context
warn("DEPRECATION WARNING: Condition#evaluate without a context argument is deprecated" \
" and will be removed from Liquid 6.0.0.")
Context.new
end
class ParseTreeVisitor < Liquid::ParseTreeVisitor
def children
[
@node.left,
@node.right,
@node.child_condition,
@node.attachment
].compact
end
end
end
class ElseCondition < Condition
def else?
true
end
def evaluate(_context)
true
end
end
end
-8
View File
@@ -1,8 +0,0 @@
# frozen_string_literal: true
module Liquid
module Const
EMPTY_HASH = {}.freeze
EMPTY_ARRAY = [].freeze
end
end
-295
View File
@@ -1,295 +0,0 @@
# frozen_string_literal: true
module Liquid
# Context keeps the variable stack and resolves variables, as well as keywords
#
# context['variable'] = 'testing'
# context['variable'] #=> 'testing'
# context['true'] #=> true
# context['10.2232'] #=> 10.2232
#
# context.stack do
# context['bob'] = 'bobsen'
# end
#
# context['bob'] #=> nil class Context
class Context
attr_reader :scopes, :errors, :registers, :environments, :resource_limits, :static_registers, :static_environments
attr_accessor :exception_renderer, :template_name, :partial, :global_filter, :strict_variables, :strict_filters, :environment
# rubocop:disable Metrics/ParameterLists
def self.build(environment: Environment.default, environments: {}, outer_scope: {}, registers: {}, rethrow_errors: false, resource_limits: nil, static_environments: {}, &block)
new(environments, outer_scope, registers, rethrow_errors, resource_limits, static_environments, environment, &block)
end
def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = nil, static_environments = {}, environment = Environment.default)
@environment = environment
@environments = [environments]
@environments.flatten!
@static_environments = [static_environments].flatten(1).freeze
@scopes = [outer_scope || {}]
@registers = registers.is_a?(Registers) ? registers : Registers.new(registers)
@errors = []
@partial = false
@strict_variables = false
@resource_limits = resource_limits || ResourceLimits.new(environment.default_resource_limits)
@base_scope_depth = 0
@interrupts = []
@filters = []
@global_filter = nil
@disabled_tags = {}
# Instead of constructing new StringScanner objects for each Expression parse,
# we recycle the same one.
@string_scanner = StringScanner.new("")
@registers.static[:cached_partials] ||= {}
@registers.static[:file_system] ||= environment.file_system
@registers.static[:template_factory] ||= Liquid::TemplateFactory.new
self.exception_renderer = environment.exception_renderer
if rethrow_errors
self.exception_renderer = Liquid::RAISE_EXCEPTION_LAMBDA
end
yield self if block_given?
# Do this last, since it could result in this object being passed to a Proc in the environment
squash_instance_assigns_with_environments
end
# rubocop:enable Metrics/ParameterLists
def warnings
@warnings ||= []
end
def strainer
@strainer ||= @environment.create_strainer(self, @filters)
end
# Adds filters to this context.
#
# Note that this does not register the filters with the main Template object. see <tt>Template.register_filter</tt>
# for that
def add_filters(filters)
filters = [filters].flatten.compact
@filters += filters
@strainer = nil
end
def apply_global_filter(obj)
global_filter.nil? ? obj : global_filter.call(obj)
end
# are there any not handled interrupts?
def interrupt?
!@interrupts.empty?
end
# push an interrupt to the stack. this interrupt is considered not handled.
def push_interrupt(e)
@interrupts.push(e)
end
# pop an interrupt from the stack
def pop_interrupt
@interrupts.pop
end
def handle_error(e, line_number = nil)
e = internal_error unless e.is_a?(Liquid::Error)
e.template_name ||= template_name
e.line_number ||= line_number
errors.push(e)
exception_renderer.call(e).to_s
end
def invoke(method, *args)
strainer.invoke(method, *args).to_liquid
end
# Push new local scope on the stack. use <tt>Context#stack</tt> instead
def push(new_scope = {})
@scopes.unshift(new_scope)
check_overflow
end
# Merge a hash of variables in the current local scope
def merge(new_scopes)
@scopes[0].merge!(new_scopes)
end
# Pop from the stack. use <tt>Context#stack</tt> instead
def pop
raise ContextError if @scopes.size == 1
@scopes.shift
end
# Pushes a new local scope on the stack, pops it at the end of the block
#
# Example:
# context.stack do
# context['var'] = 'hi'
# end
#
# context['var'] #=> nil
def stack(new_scope = {})
push(new_scope)
yield
ensure
pop
end
# Creates a new context inheriting resource limits, filters, environment etc.,
# but with an isolated scope.
def new_isolated_subcontext
check_overflow
self.class.build(
environment: @environment,
resource_limits: resource_limits,
static_environments: static_environments,
registers: Registers.new(registers),
).tap do |subcontext|
subcontext.base_scope_depth = base_scope_depth + 1
subcontext.exception_renderer = exception_renderer
subcontext.filters = @filters
subcontext.strainer = nil
subcontext.errors = errors
subcontext.warnings = warnings
subcontext.disabled_tags = @disabled_tags
end
end
def clear_instance_assigns
@scopes[0] = {}
end
# Only allow String, Numeric, Hash, Array, Proc, Boolean or <tt>Liquid::Drop</tt>
def []=(key, value)
@scopes[0][key] = value
end
# Look up variable, either resolve directly after considering the name. We can directly handle
# Strings, digits, floats and booleans (true,false).
# If no match is made we lookup the variable in the current scope and
# later move up to the parent blocks to see if we can resolve the variable somewhere up the tree.
# Some special keywords return symbols. Those symbols are to be called on the rhs object in expressions
#
# Example:
# products == empty #=> products.empty?
def [](expression)
evaluate(Expression.parse(expression, @string_scanner))
end
def key?(key)
self[key] != nil
end
def evaluate(object)
object.respond_to?(:evaluate) ? object.evaluate(self) : object
end
# Fetches an object starting at the local scope and then moving up the hierachy
def find_variable(key, raise_on_not_found: true)
# This was changed from find() to find_index() because this is a very hot
# path and find_index() is optimized in MRI to reduce object allocation
index = @scopes.find_index { |s| s.key?(key) }
variable = if index
lookup_and_evaluate(@scopes[index], key, raise_on_not_found: raise_on_not_found)
else
try_variable_find_in_environments(key, raise_on_not_found: raise_on_not_found)
end
# update variable's context before invoking #to_liquid
variable.context = self if variable.respond_to?(:context=)
liquid_variable = variable.to_liquid
liquid_variable.context = self if variable != liquid_variable && liquid_variable.respond_to?(:context=)
liquid_variable
end
def lookup_and_evaluate(obj, key, raise_on_not_found: true)
if @strict_variables && raise_on_not_found && obj.respond_to?(:key?) && !obj.key?(key)
raise Liquid::UndefinedVariable, "undefined variable #{key}"
end
value = obj[key]
if value.is_a?(Proc) && obj.respond_to?(:[]=)
obj[key] = value.arity == 0 ? value.call : value.call(self)
else
value
end
end
def with_disabled_tags(tag_names)
tag_names.each do |name|
@disabled_tags[name] = @disabled_tags.fetch(name, 0) + 1
end
yield
ensure
tag_names.each do |name|
@disabled_tags[name] -= 1
end
end
def tag_disabled?(tag_name)
@disabled_tags.fetch(tag_name, 0) > 0
end
protected
attr_writer :base_scope_depth, :warnings, :errors, :strainer, :filters, :disabled_tags
private
attr_reader :base_scope_depth
def try_variable_find_in_environments(key, raise_on_not_found:)
@environments.each do |environment|
found_variable = lookup_and_evaluate(environment, key, raise_on_not_found: raise_on_not_found)
if !found_variable.nil? || @strict_variables && raise_on_not_found
return found_variable
end
end
@static_environments.each do |environment|
found_variable = lookup_and_evaluate(environment, key, raise_on_not_found: raise_on_not_found)
if !found_variable.nil? || @strict_variables && raise_on_not_found
return found_variable
end
end
nil
end
def check_overflow
raise StackLevelError, "Nesting too deep" if overflow?
end
def overflow?
base_scope_depth + @scopes.length > Block::MAX_DEPTH
end
def internal_error
# raise and catch to set backtrace and cause on exception
raise Liquid::InternalError, 'internal'
rescue Liquid::InternalError => exc
exc
end
def squash_instance_assigns_with_environments
@scopes.last.each_key do |k|
@environments.each do |env|
if env.key?(k)
scopes.last[k] = lookup_and_evaluate(env, k)
break
end
end
end
end # squash_instance_assigns_with_environments
end # Context
end # Liquid
-22
View File
@@ -1,22 +0,0 @@
# frozen_string_literal: true
require "set"
module Liquid
class Deprecations
class << self
attr_accessor :warned
Deprecations.warned = Set.new
def warn(name, alternative)
return if warned.include?(name)
warned << name
caller_location = caller_locations(2, 1).first
Warning.warn("[DEPRECATION] #{name} is deprecated. Use #{alternative} instead. Called from #{caller_location}\n")
end
end
end
end
-65
View File
@@ -1,65 +0,0 @@
# frozen_string_literal: true
module Liquid
class Document
def self.parse(tokens, parse_context)
doc = new(parse_context)
doc.parse(tokens, parse_context)
doc
end
attr_reader :parse_context, :body
def initialize(parse_context)
@parse_context = parse_context
@body = new_body
end
def nodelist
@body.nodelist
end
def parse(tokenizer, parse_context)
while parse_body(tokenizer)
end
@body.freeze
rescue SyntaxError => e
e.line_number ||= parse_context.line_number
raise
end
def unknown_tag(tag, _markup, _tokenizer)
case tag
when 'else', 'end'
raise SyntaxError, parse_context.locale.t("errors.syntax.unexpected_outer_tag", tag: tag)
else
raise SyntaxError, parse_context.locale.t("errors.syntax.unknown_tag", tag: tag)
end
end
def render_to_output_buffer(context, output)
@body.render_to_output_buffer(context, output)
end
def render(context)
render_to_output_buffer(context, +'')
end
private
def new_body
parse_context.new_block_body
end
def parse_body(tokenizer)
@body.parse(tokenizer, parse_context) do |unknown_tag_name, unknown_tag_markup|
if unknown_tag_name
unknown_tag(unknown_tag_name, unknown_tag_markup, tokenizer)
true
else
false
end
end
end
end
end
-84
View File
@@ -1,84 +0,0 @@
# frozen_string_literal: true
require 'set'
module Liquid
# A drop in liquid is a class which allows you to export DOM like things to liquid.
# Methods of drops are callable.
# The main use for liquid drops is to implement lazy loaded objects.
# If you would like to make data available to the web designers which you don't want loaded unless needed then
# a drop is a great way to do that.
#
# Example:
#
# class ProductDrop < Liquid::Drop
# def top_sales
# Shop.current.products.find(:all, :order => 'sales', :limit => 10 )
# end
# end
#
# tmpl = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {%endfor%} ' )
# tmpl.render('product' => ProductDrop.new ) # will invoke top_sales query.
#
# Your drop can either implement the methods sans any parameters
# or implement the liquid_method_missing(name) method which is a catch all.
class Drop
attr_writer :context
def initialize
@context = nil
end
# Catch all for the method
def liquid_method_missing(method)
return nil unless @context&.strict_variables
raise Liquid::UndefinedDropMethod, "undefined method #{method}"
end
# called by liquid to invoke a drop
def invoke_drop(method_or_key)
if self.class.invokable?(method_or_key)
send(method_or_key)
else
liquid_method_missing(method_or_key)
end
end
def key?(_name)
true
end
def inspect
self.class.to_s
end
def to_liquid
self
end
def to_s
self.class.name
end
alias_method :[], :invoke_drop
# Check for method existence without invoking respond_to?, which creates symbols
def self.invokable?(method_name)
invokable_methods.include?(method_name.to_s)
end
def self.invokable_methods
@invokable_methods ||= begin
blacklist = Liquid::Drop.public_instance_methods + [:each]
if include?(Enumerable)
blacklist += Enumerable.public_instance_methods
blacklist -= [:sort, :count, :first, :min, :max]
end
whitelist = [:to_liquid] + (public_instance_methods - blacklist)
Set.new(whitelist.map(&:to_s))
end
end
end
end
-159
View File
@@ -1,159 +0,0 @@
# frozen_string_literal: true
module Liquid
# The Environment is the container for all configuration options of Liquid, such as
# the registered tags, filters, and the default error mode.
class Environment
# The default error mode for all templates. This can be overridden on a
# per-template basis.
attr_accessor :error_mode
# The tags that are available to use in the template.
attr_accessor :tags
# The strainer template which is used to store filters that are available to
# use in templates.
attr_accessor :strainer_template
# The exception renderer that is used to render exceptions that are raised
# when rendering a template
attr_accessor :exception_renderer
# The default file system that is used to load templates from.
attr_accessor :file_system
# The default resource limits that are used to limit the resources that a
# template can consume.
attr_accessor :default_resource_limits
class << self
# Creates a new environment instance.
#
# @param tags [Hash] The tags that are available to use in
# the template.
# @param file_system The default file system that is used
# to load templates from.
# @param error_mode [Symbol] The default error mode for all templates
# (either :strict, :warn, or :lax).
# @param exception_renderer [Proc] The exception renderer that is used to
# render exceptions.
# @yieldparam environment [Environment] The environment instance that is being built.
# @return [Environment] The new environment instance.
def build(tags: nil, file_system: nil, error_mode: nil, exception_renderer: nil)
ret = new
ret.tags = tags if tags
ret.file_system = file_system if file_system
ret.error_mode = error_mode if error_mode
ret.exception_renderer = exception_renderer if exception_renderer
yield ret if block_given?
ret.freeze
end
# Returns the default environment instance.
#
# @return [Environment] The default environment instance.
def default
@default ||= new
end
# Sets the default environment instance for the duration of the block
#
# @param environment [Environment] The environment instance to use as the default for the
# duration of the block.
# @yield
# @return [Object] The return value of the block.
def dangerously_override(environment)
original_default = @default
@default = environment
yield
ensure
@default = original_default
end
end
# Initializes a new environment instance.
# @api private
def initialize
@tags = Tags::STANDARD_TAGS.dup
@error_mode = :lax
@strainer_template = Class.new(StrainerTemplate).tap do |klass|
klass.add_filter(StandardFilters)
end
@exception_renderer = ->(exception) { exception }
@file_system = BlankFileSystem.new
@default_resource_limits = Const::EMPTY_HASH
@strainer_template_class_cache = {}
end
# Registers a new tag with the environment.
#
# @param name [String] The name of the tag.
# @param klass [Liquid::Tag] The class that implements the tag.
# @return [void]
def register_tag(name, klass)
@tags[name] = klass
end
# Registers a new filter with the environment.
#
# @param filter [Module] The module that contains the filter methods.
# @return [void]
def register_filter(filter)
@strainer_template_class_cache.clear
@strainer_template.add_filter(filter)
end
# Registers multiple filters with this environment.
#
# @param filters [Array<Module>] The modules that contain the filter methods.
# @return [self]
def register_filters(filters)
@strainer_template_class_cache.clear
filters.each { |f| @strainer_template.add_filter(f) }
self
end
# Creates a new strainer instance with the given filters, caching the result
# for faster lookup.
#
# @param context [Liquid::Context] The context that the strainer will be
# used in.
# @param filters [Array<Module>] The filters that the strainer will have
# access to.
# @return [Liquid::Strainer] The new strainer instance.
def create_strainer(context, filters = Const::EMPTY_ARRAY)
return @strainer_template.new(context) if filters.empty?
strainer_template = @strainer_template_class_cache[filters] ||= begin
klass = Class.new(@strainer_template)
filters.each { |f| klass.add_filter(f) }
klass
end
strainer_template.new(context)
end
# Returns the names of all the filter methods that are available to use in
# the strainer template.
#
# @return [Array<String>] The names of all the filter methods.
def filter_method_names
@strainer_template.filter_method_names
end
# Returns the tag class for the given tag name.
#
# @param name [String] The name of the tag.
# @return [Liquid::Tag] The tag class.
def tag_for_name(name)
@tags[name]
end
def freeze
@tags.freeze
# TODO: freeze the tags, currently this is not possible because of liquid-c
# @strainer_template.freeze
super
end
end
end

Some files were not shown because too many files have changed in this diff Show More