From 0437581ddaff416227f270cf196f90007430ec3a Mon Sep 17 00:00:00 2001 From: Jason Kurian Date: Thu, 15 Jul 2021 12:21:33 -0400 Subject: [PATCH] add all objects from Shopify reference --- components/prism-liquid.js | 1 + components/prism-liquid.min.js | 2 +- tests/languages/liquid/function_feature.test | 30 +- tests/languages/liquid/object_feature.test | 477 +++++++++++++++++++ tests/languages/liquid/template_feature.test | 2 +- 5 files changed, 495 insertions(+), 17 deletions(-) create mode 100644 tests/languages/liquid/object_feature.test diff --git a/components/prism-liquid.js b/components/prism-liquid.js index b337c19561..149d0bcdac 100644 --- a/components/prism-liquid.js +++ b/components/prism-liquid.js @@ -12,6 +12,7 @@ Prism.languages.liquid = { greedy: true }, 'keyword': /\b(?:as|assign|break|continue|cycle|decrement|echo|else|elsif|(?:end)?(?:capture|case|comment|for|form|if|paginate|style|raw|tablerow|unless)|in|include|increment|limit|liquid|offset|range|render|reversed|section|when|with)\b/, + 'object': /\b(?:address|all_country_option_tags|article|block|blog|cart|checkout|collection|color|comment|country|country_option_tags|currency|current_page|current_tags|customer|customer_address|date|discount_allocation|discount_application|external_video|filter|filter_value|font|forloop|form|fulfillment|generic_file|gift_card|group|handle|image|line_item|link|linklist|localization|location|measurement|media|metafield|model|model_source|order|page|page_description|page_image|page_title|paginate|part|policy|product|product_option|recommendations|request|robots|routes|rule|script|search|section|selling_plan|selling_plan_allocation|selling_plan_group|shipping_method|shop|shop_locale|sitemap|store_availability|tablerow|tax_line|template|theme|transaction|unit_price_measurement|user_agent|variant|video|video_source)\b/, 'function': [ { pattern: /(\|\s*)\w+/, diff --git a/components/prism-liquid.min.js b/components/prism-liquid.min.js index f33aafeba5..677b29ab72 100644 --- a/components/prism-liquid.min.js +++ b/components/prism-liquid.min.js @@ -1 +1 @@ -Prism.languages.liquid={comment:{pattern:/(^\{%\s*comment\s*%\})[\s\S]+(?=\{%\s*endcomment\s*%\}$)/,lookbehind:!0},delimiter:{pattern:/^\{(?:\{\{|[%\{])-?|-?(?:\}\}|[%\}])\}$/,alias:"punctuation"},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},keyword:/\b(?:as|assign|break|continue|cycle|decrement|echo|else|elsif|(?:end)?(?:capture|case|comment|for|form|if|paginate|style|raw|tablerow|unless)|in|include|increment|limit|liquid|offset|range|render|reversed|section|when|with)\b/,function:[{pattern:/(\|\s*)\w+/,lookbehind:!0,alias:"filter"},{pattern:/(\.\s*)(?:first|last|size)/,lookbehind:!0}],boolean:/\b(?:true|false|nil)\b/,range:{pattern:/\.\./,alias:"operator"},number:/\b\d+(?:\.\d+)?\b/,operator:/[!=]=|<>|[<>]=?|[|?:=-]|\b(?:and|or|contains(?=\s))\b/,punctuation:/[.,\[\]()]/,empty:{pattern:/\bempty\b/,alias:"keyword"}},Prism.hooks.add("before-tokenize",function(e){var r=!1;Prism.languages["markup-templating"].buildPlaceholders(e,"liquid",/\{%\s*comment\s*%\}[\s\S]*?\{%\s*endcomment\s*%\}|\{(?:%[\s\S]*?%|\{\{[\s\S]*?\}\}|\{[\s\S]*?\})\}/g,function(e){var n=/^\{%-?\s*(\w+)/.exec(e);if(n){var t=n[1];if("raw"===t&&!r)return r=!0;if("endraw"===t)return!(r=!1)}return!r})}),Prism.hooks.add("after-tokenize",function(e){Prism.languages["markup-templating"].tokenizePlaceholders(e,"liquid")}); \ No newline at end of file +Prism.languages.liquid={comment:{pattern:/(^\{%\s*comment\s*%\})[\s\S]+(?=\{%\s*endcomment\s*%\}$)/,lookbehind:!0},delimiter:{pattern:/^\{(?:\{\{|[%\{])-?|-?(?:\}\}|[%\}])\}$/,alias:"punctuation"},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},keyword:/\b(?:as|assign|break|continue|cycle|decrement|echo|else|elsif|(?:end)?(?:capture|case|comment|for|form|if|paginate|style|raw|tablerow|unless)|in|include|increment|limit|liquid|offset|range|render|reversed|section|when|with)\b/,object:/\b(?:address|all_country_option_tags|article|block|blog|cart|checkout|collection|color|comment|country|country_option_tags|currency|current_page|current_tags|customer|customer_address|date|discount_allocation|discount_application|external_video|filter|filter_value|font|forloop|form|fulfillment|generic_file|gift_card|group|handle|image|line_item|link|linklist|localization|location|measurement|media|metafield|model|model_source|order|page|page_description|page_image|page_title|paginate|part|policy|product|product_option|recommendations|request|robots|routes|rule|script|search|section|selling_plan|selling_plan_allocation|selling_plan_group|shipping_method|shop|shop_locale|sitemap|store_availability|tablerow|tax_line|template|theme|transaction|unit_price_measurement|user_agent|variant|video|video_source)\b/,function:[{pattern:/(\|\s*)\w+/,lookbehind:!0,alias:"filter"},{pattern:/(\.\s*)(?:first|last|size)/,lookbehind:!0}],boolean:/\b(?:true|false|nil)\b/,range:{pattern:/\.\./,alias:"operator"},number:/\b\d+(?:\.\d+)?\b/,operator:/[!=]=|<>|[<>]=?|[|?:=-]|\b(?:and|or|contains(?=\s))\b/,punctuation:/[.,\[\]()]/,empty:{pattern:/\bempty\b/,alias:"keyword"}},Prism.hooks.add("before-tokenize",function(e){var a=!1;Prism.languages["markup-templating"].buildPlaceholders(e,"liquid",/\{%\s*comment\s*%\}[\s\S]*?\{%\s*endcomment\s*%\}|\{(?:%[\s\S]*?%|\{\{[\s\S]*?\}\}|\{[\s\S]*?\})\}/g,function(e){var t=/^\{%-?\s*(\w+)/.exec(e);if(t){var n=t[1];if("raw"===n&&!a)return a=!0;if("endraw"===n)return!(a=!1)}return!a})}),Prism.hooks.add("after-tokenize",function(e){Prism.languages["markup-templating"].tokenizePlaceholders(e,"liquid")}); \ No newline at end of file diff --git a/tests/languages/liquid/function_feature.test b/tests/languages/liquid/function_feature.test index 021bba9c1b..4853addaba 100644 --- a/tests/languages/liquid/function_feature.test +++ b/tests/languages/liquid/function_feature.test @@ -46,7 +46,7 @@ [ ["liquid", [ ["delimiter", "{{"], - " product", + ["object", "product"], ["punctuation", "."], "tags ", ["operator", "|"], @@ -56,7 +56,7 @@ ["liquid", [ ["delimiter", "{%"], ["keyword", "if"], - " product", + ["object", "product"], ["punctuation", "."], "tags", ["punctuation", "."], @@ -67,7 +67,7 @@ ]], ["liquid", [ ["delimiter", "{{"], - " product", + ["object", "product"], ["punctuation", "."], "tags ", ["operator", "|"], @@ -77,7 +77,7 @@ ["liquid", [ ["delimiter", "{%"], ["keyword", "if"], - " product", + ["object", "product"], ["punctuation", "."], "tags", ["punctuation", "."], @@ -136,7 +136,7 @@ ["keyword", "assign"], " products ", ["operator", "="], - " collection", + ["object", "collection"], ["punctuation", "."], "products ", ["operator", "|"], @@ -150,7 +150,7 @@ ["keyword", "assign"], " kitchen_products ", ["operator", "="], - " collection", + ["object", "collection"], ["punctuation", "."], "products ", ["operator", "|"], @@ -224,7 +224,7 @@ ]], ["liquid", [ ["delimiter", "{{"], - " article", + ["object", "article"], ["punctuation", "."], "published_at ", ["operator", "|"], @@ -253,7 +253,7 @@ ]], ["liquid", [ ["delimiter", "{{"], - " product", + ["object", "product"], ["punctuation", "."], "price ", ["operator", "|"], @@ -264,7 +264,7 @@ ]], ["liquid", [ ["delimiter", "{{"], - " product", + ["object", "product"], ["punctuation", "."], "price ", ["operator", "|"], @@ -276,7 +276,7 @@ ["liquid", [ ["delimiter", "{{"], - " product", + ["object", "product"], ["punctuation", "."], "featured_media ", ["operator", "|"], @@ -289,7 +289,7 @@ ]], ["liquid", [ ["delimiter", "{{"], - " product", + ["object", "product"], ["punctuation", "."], "featured_media ", ["operator", "|"], @@ -300,7 +300,7 @@ ]], ["liquid", [ ["delimiter", "{{"], - " product", + ["object", "product"], ["punctuation", "."], "featured_media ", ["operator", "|"], @@ -402,11 +402,11 @@ ["liquid", [ ["delimiter", "{{"], - " article", + ["object", "article"], ["punctuation", "."], "published_at ", ["operator", "|"], - ["function", "date"], + ["object", "date"], ["operator", ":"], ["string", "\"%a, %b %d, %y\""], ["delimiter", "}}"] @@ -428,7 +428,7 @@ ]], ["liquid", [ ["delimiter", "{{"], - " product", + ["object", "product"], ["punctuation", "."], "variants", ["punctuation", "."], diff --git a/tests/languages/liquid/object_feature.test b/tests/languages/liquid/object_feature.test new file mode 100644 index 0000000000..441e8edc5d --- /dev/null +++ b/tests/languages/liquid/object_feature.test @@ -0,0 +1,477 @@ +{{ address }} +{{ all_country_option_tags }} +{{ article }} +{{ block }} +{{ blog }} +{{ cart }} +{{ checkout }} +{{ collection }} +{{ color }} +{{ comment }} +{{ country }} +{{ country_option_tags }} +{{ currency }} +{{ current_page }} +{{ current_tags }} +{{ customer }} +{{ customer_address }} +{{ date }} +{{ discount_allocation }} +{{ discount_application }} +{{ external_video }} +{{ filter }} +{{ filter_value }} +{{ font }} +{{ forloop }} +{{ form }} +{{ fulfillment }} +{{ generic_file }} +{{ gift_card }} +{{ group }} +{{ handle }} +{{ image }} +{{ line_item }} +{{ link }} +{{ linklist }} +{{ localization }} +{{ location }} +{{ measurement }} +{{ media }} +{{ metafield }} +{{ model }} +{{ model_source }} +{{ order }} +{{ page }} +{{ page_description }} +{{ page_image }} +{{ page_title }} +{{ paginate }} +{{ part }} +{{ policy }} +{{ product }} +{{ product_option }} +{{ recommendations }} +{{ request }} +{{ robots }} +{{ routes }} +{{ rule }} +{{ script }} +{{ search }} +{{ section }} +{{ selling_plan }} +{{ selling_plan_allocation }} +{{ selling_plan_group }} +{{ shipping_method }} +{{ shop }} +{{ shop_locale }} +{{ sitemap }} +{{ store_availability }} +{{ tablerow }} +{{ tax_line }} +{{ template }} +{{ theme }} +{{ transaction }} +{{ unit_price_measurement }} +{{ user_agent }} +{{ variant }} +{{ video }} +{{ video_source }} + +---------------------------------------------------- + +[ + ["liquid", [ + ["delimiter", "{{"], + ["object", "address"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "all_country_option_tags"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "article"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "block"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "blog"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "cart"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "checkout"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "collection"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "color"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["keyword", "comment"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "country"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "country_option_tags"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "currency"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "current_page"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "current_tags"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "customer"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "customer_address"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "date"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "discount_allocation"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "discount_application"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "external_video"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "filter"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "filter_value"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "font"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "forloop"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["keyword", "form"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "fulfillment"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "generic_file"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "gift_card"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "group"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "handle"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "image"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "line_item"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "link"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "linklist"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "localization"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "location"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "measurement"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "media"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "metafield"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "model"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "model_source"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "order"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "page"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "page_description"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "page_image"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "page_title"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["keyword", "paginate"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "part"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "policy"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "product"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "product_option"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "recommendations"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "request"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "robots"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "routes"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "rule"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "script"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "search"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["keyword", "section"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "selling_plan"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "selling_plan_allocation"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "selling_plan_group"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "shipping_method"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "shop"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "shop_locale"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "sitemap"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "store_availability"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["keyword", "tablerow"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "tax_line"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "template"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "theme"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "transaction"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "unit_price_measurement"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "user_agent"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "variant"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "video"], + ["delimiter", "}}"] + ]], + ["liquid", [ + ["delimiter", "{{"], + ["object", "video_source"], + ["delimiter", "}}"] + ]] +] + +---------------------------------------------------- + +Liquid objects sourced from https://shopify.dev/api/liquid/objects diff --git a/tests/languages/liquid/template_feature.test b/tests/languages/liquid/template_feature.test index 19e2af3710..ac6b44c550 100644 --- a/tests/languages/liquid/template_feature.test +++ b/tests/languages/liquid/template_feature.test @@ -16,7 +16,7 @@ [ ["liquid", [ ["delimiter", "{{"], - " page", + ["object", "page"], ["punctuation", "."], "title ", ["delimiter", "}}"]