+ Continue Shopping
+ Browse more {{ product.type | link_to_type }} or additional {{ product.vendor | link_to_vendor }} products.
+
+
diff --git a/fluid-bench/shop_filter.rb b/fluid-bench/shop_filter.rb
new file mode 100644
index 00000000..3558c6fc
--- /dev/null
+++ b/fluid-bench/shop_filter.rb
@@ -0,0 +1,106 @@
+# frozen_string_literal: true
+
+module ShopFilter
+ def asset_url(input)
+ "/files/1/[shop_id]/[shop_id]/assets/#{input}"
+ end
+
+ def global_asset_url(input)
+ "/global/#{input}"
+ end
+
+ def shopify_asset_url(input)
+ "/shopify/#{input}"
+ end
+
+ def script_tag(url)
+ %()
+ end
+
+ def stylesheet_tag(url, media = "all")
+ %()
+ end
+
+ def link_to(link, url, title = "")
+ %(#{link})
+ end
+
+ def img_tag(url, alt = "")
+ %()
+ end
+
+ def link_to_vendor(vendor)
+ if vendor
+ link_to(vendor, url_for_vendor(vendor), vendor)
+ else
+ 'Unknown Vendor'
+ end
+ end
+
+ def link_to_type(type)
+ if type
+ link_to(type, url_for_type(type), type)
+ else
+ 'Unknown Vendor'
+ end
+ end
+
+ def url_for_vendor(vendor_title)
+ "/collections/#{to_handle(vendor_title)}"
+ end
+
+ def url_for_type(type_title)
+ "/collections/#{to_handle(type_title)}"
+ end
+
+ def product_img_url(url, style = 'small')
+ unless url =~ %r{\Aproducts/([\w\-\_]+)\.(\w{2,4})}
+ raise ArgumentError, 'filter "size" can only be called on product images'
+ end
+
+ case style
+ when 'original'
+ '/files/shops/random_number/' + url
+ when 'grande', 'large', 'medium', 'compact', 'small', 'thumb', 'icon'
+ "/files/shops/random_number/products/#{Regexp.last_match(1)}_#{style}.#{Regexp.last_match(2)}"
+ else
+ raise ArgumentError, 'valid parameters for filter "size" are: original, grande, large, medium, compact, small, thumb and icon '
+ end
+ end
+
+ def default_pagination(paginate)
+ html = []
+ html << %(#{link_to(paginate['previous']['title'], paginate['previous']['url'])}) if paginate['previous']
+
+ paginate['parts'].each do |part|
+ html << if part['is_link']
+ %(#{link_to(part['title'], part['url'])})
+ elsif part['title'].to_i == paginate['current_page'].to_i
+ %(#{part['title']})
+ else
+ %(#{part['title']})
+ end
+ end
+
+ html << %(#{link_to(paginate['next']['title'], paginate['next']['url'])}) if paginate['next']
+ html.join(' ')
+ end
+
+ # Accepts a number, and two words - one for singular, one for plural
+ # Returns the singular word if input equals 1, otherwise plural
+ def pluralize(input, singular, plural)
+ input == 1 ? singular : plural
+ end
+
+ private
+
+ def to_handle(str)
+ result = str.dup
+ result.downcase!
+ result.delete!("'\"()[]")
+ result.gsub!(/\W+/, '-')
+ result.gsub!(/-+\z/, '') if result[-1] == '-'
+ result.gsub!(/\A-+/, '') if result[0] == '-'
+ result
+ end
+end
diff --git a/fluid-bench/stackprof.dump b/fluid-bench/stackprof.dump
new file mode 100644
index 00000000..65a94e1f
Binary files /dev/null and b/fluid-bench/stackprof.dump differ
diff --git a/fluid-bench/vision.database.yml b/fluid-bench/vision.database.yml
new file mode 100644
index 00000000..9f38c304
--- /dev/null
+++ b/fluid-bench/vision.database.yml
@@ -0,0 +1,945 @@
+# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+# Variants
+# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
+product_variants:
+ - &product-1-var-1
+ id: 1
+ title: 151cm / Normal
+ price: 19900
+ weight: 1000
+ compare_at_price: 49900
+ available: true
+ inventory_quantity: 5
+ option1: 151cm
+ option2: Normal
+ option3:
+ - &product-1-var-2
+ id: 2
+ title: 155cm / Normal
+ price: 31900
+ weight: 1000
+ compare_at_price: 50900
+ available: true
+ inventory_quantity: 2
+ option1: 155cm
+ option2: Normal
+ option3:
+ - &product-2-var-1
+ id: 3
+ title: 162cm
+ price: 29900
+ weight: 1000
+ compare_at_price: 52900
+ available: true
+ inventory_quantity: 3
+ option1: 162cm
+ option2:
+ option3:
+ - &product-3-var-1
+ id: 4
+ title: 159cm
+ price: 19900
+ weight: 1000
+ compare_at_price:
+ available: true
+ inventory_quantity: 4
+ option1: 159cm
+ option2:
+ option3:
+ - &product-4-var-1
+ id: 5
+ title: 159cm
+ price: 19900
+ weight: 1000
+ compare_at_price: 32900
+ available: true
+ inventory_quantity: 6
+ option1: 159cm
+ option2:
+ option3:
+ - &product-1-var-3
+ id: 6
+ title: 158cm / Wide
+ price: 23900
+ weight: 1000
+ compare_at_price: 99900
+ available: false
+ inventory_quantity: 0
+ option1: 158cm
+ option2: Wide
+ option3:
+ - &product-3-var-2
+ id: 7
+ title: 162cm
+ price: 19900
+ weight: 1000
+ compare_at_price:
+ available: false
+ inventory_quantity: 0
+ option1: 162cm
+ option2:
+ option3:
+ - &product-3-var-3
+ id: 8
+ title: 165cm
+ price: 22900
+ weight: 1000
+ compare_at_price:
+ available: true
+ inventory_quantity: 4
+ option1: 165cm
+ option2:
+ option3:
+ - &product-5-var-1
+ id: 9
+ title: black / 42
+ price: 11900
+ weight: 500
+ compare_at_price: 22900
+ available: true
+ inventory_quantity: 1
+ option1: black
+ option2: 42
+ option3:
+ - &product-5-var-2
+ id: 10
+ title: beige / 42
+ price: 11900
+ weight: 500
+ compare_at_price: 22900
+ available: true
+ inventory_quantity: 3
+ option1: beige
+ option2: 42
+ option3:
+ - &product-5-var-3
+ id: 11
+ title: white / 42
+ price: 13900
+ weight: 500
+ compare_at_price: 24900
+ available: true
+ inventory_quantity: 1
+ option1: white
+ option2: 42
+ option3:
+ - &product-5-var-4
+ id: 12
+ title: black / 44
+ price: 11900
+ weight: 500
+ compare_at_price: 22900
+ available: true
+ inventory_quantity: 2
+ option1: black
+ option2: 44
+ option3:
+ - &product-5-var-5
+ id: 13
+ title: beige / 44
+ price: 11900
+ weight: 500
+ compare_at_price: 22900
+ available: false
+ inventory_quantity: 0
+ option1: beige
+ option2: 44
+ option3:
+ - &product-5-var-6
+ id: 14
+ title: white / 44
+ price: 13900
+ weight: 500
+ compare_at_price: 24900
+ available: false
+ inventory_quantity: 0
+ option1: white
+ option2: 44
+ option3:
+ - &product-6-var-1
+ id: 15
+ title: red
+ price: 2179500
+ weight: 200000
+ compare_at_price:
+ available: true
+ inventory_quantity: 0
+ option1: red
+ option2:
+ option3:
+ - &product-7-var-1
+ id: 16
+ title: black / small
+ price: 1900
+ weight: 200
+ compare_at_price:
+ available: true
+ inventory_quantity: 20
+ option1: black
+ option2: small
+ option3:
+ - &product-7-var-2
+ id: 17
+ title: black / medium
+ price: 1900
+ weight: 200
+ compare_at_price:
+ available: false
+ inventory_quantity: 0
+ option1: black
+ option2: medium
+ option3:
+ - &product-7-var-3
+ id: 18
+ title: black / large
+ price: 1900
+ weight: 200
+ compare_at_price:
+ available: true
+ inventory_quantity: 10
+ option1: black
+ option2: large
+ option3:
+ - &product-7-var-4
+ id: 19
+ title: black / extra large
+ price: 1900
+ weight: 200
+ compare_at_price:
+ available: false
+ inventory_quantity: 0
+ option1: black
+ option2: extra large
+ option3:
+ - &product-8-var-1
+ id: 20
+ title: brown / small
+ price: 5900
+ weight: 400
+ compare_at_price: 6900
+ available: true
+ inventory_quantity: 5
+ option1: brown
+ option2: small
+ option3:
+ - &product-8-var-2
+ id: 21
+ title: brown / medium
+ price: 5900
+ weight: 400
+ compare_at_price: 6900
+ available: false
+ inventory_quantity: 0
+ option1: brown
+ option2: medium
+ option3:
+ - &product-8-var-3
+ id: 22
+ title: brown / large
+ price: 5900
+ weight: 400
+ compare_at_price: 6900
+ available: true
+ inventory_quantity: 10
+ option1: brown
+ option2: large
+ option3:
+ - &product-8-var-4
+ id: 23
+ title: black / small
+ price: 5900
+ weight: 400
+ compare_at_price: 6900
+ available: true
+ inventory_quantity: 10
+ option1: black
+ option2: small
+ option3:
+ - &product-8-var-5
+ id: 24
+ title: black / medium
+ price: 5900
+ weight: 400
+ compare_at_price: 6900
+ available: true
+ inventory_quantity: 10
+ option1: black
+ option2: medium
+ option3:
+ - &product-8-var-6
+ id: 25
+ title: black / large
+ price: 5900
+ weight: 400
+ compare_at_price: 6900
+ available: false
+ inventory_quantity: 0
+ option1: black
+ option2: large
+ option3:
+ - &product-9-var-1
+ id: 26
+ title: Body Only
+ price: 499995
+ weight: 2000
+ compare_at_price:
+ available: true
+ inventory_quantity: 3
+ option1: Body Only
+ option2:
+ option3:
+ - &product-9-var-2
+ id: 27
+ title: Kit with 18-55mm VR lens
+ price: 523995
+ weight: 2000
+ compare_at_price:
+ available: true
+ inventory_quantity: 2
+ option1: Kit with 18-55mm VR lens
+ option2:
+ option3:
+ - &product-9-var-3
+ id: 28
+ title: Kit with 18-200 VR lens
+ price: 552500
+ weight: 2000
+ compare_at_price:
+ available: true
+ inventory_quantity: 3
+ option1: Kit with 18-200 VR lens
+ option2:
+ option3:
+
+# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+# Products
+# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+
+products:
+ - &product-1
+ id: 1
+ title: Arbor Draft
+ handle: arbor-draft
+ type: Snowboards
+ vendor: Arbor
+ price: 23900
+ price_max: 31900
+ price_min: 23900
+ price_varies: true
+ available: true
+ tags:
+ - season2005
+ - pro
+ - intermediate
+ - wooden
+ - freestyle
+ options:
+ - Length
+ - Style
+ compare_at_price: 49900
+ compare_at_price_max: 50900
+ compare_at_price_min: 49900
+ compare_at_price_varies: true
+ url: /products/arbor-draft
+ featured_image: products/arbor_draft.jpg
+ images:
+ - products/arbor_draft.jpg
+ description:
+ The Arbor Draft snowboard wouldn't exist if Polynesians hadn't figured out how to surf hundreds of years ago. But the Draft does exist, and it's here to bring your urban and park riding to a new level. The board's freaky Tiki design pays homage to culture that inspired snowboarding. It's designed to spin with ease, land smoothly, lock hook-free onto rails, and take the abuse of a pavement pounding or twelve. The Draft will pop off kickers with authority and carve solidly across the pipe. The Draft features targeted Koa wood die cuts inlayed into the deck that enhance the flex pattern. Now bow down to riding's ancestors.
+ variants:
+ - *product-1-var-1
+ - *product-1-var-2
+ - *product-1-var-3
+ - &product-2
+ id: 2
+ title: Arbor Element
+ handle: arbor-element
+ type: Snowboards
+ vendor: Arbor
+ price: 29900
+ price_max: 29900
+ price_min: 29900
+ price_varies: false
+ available: true
+ tags:
+ - season2005
+ - pro
+ - wooden
+ - freestyle
+ options:
+ - Length
+ compare_at_price: 52900
+ compare_at_price_max: 52900
+ compare_at_price_min: 52900
+ compare_at_price_varies: false
+ url: /products/arbor-element
+ featured_image: products/element58.jpg
+ images:
+ - products/element58.jpg
+ description:
+ The Element is a technically advanced all-mountain board for riders who readily transition from one terrain, snow condition, or riding style to another. Its balanced design provides the versatility needed for the true ride-it-all experience. The Element is exceedingly lively, freely initiates, and holds a tight edge at speed. Its structural real-wood topsheet is made with book-matched Koa.
+ variants:
+ - *product-2-var-1
+
+ - &product-3
+ id: 3
+ title: Comic ~ Pastel
+ handle: comic-pastel
+ type: Snowboards
+ vendor: Technine
+ price: 19900
+ price_max: 22900
+ price_min: 19900
+ tags:
+ - season2006
+ - beginner
+ - intermediate
+ - freestyle
+ - purple
+ options:
+ - Length
+ price_varies: true
+ available: true
+ compare_at_price:
+ compare_at_price_max: 0
+ compare_at_price_min: 0
+ compare_at_price_varies: false
+ url: /products/comic-pastel
+ featured_image: products/technine1.jpg
+ images:
+ - products/technine1.jpg
+ - products/technine2.jpg
+ - products/technine_detail.jpg
+ description:
+ 2005 Technine Comic Series Description The Comic series was developed to be the ultimate progressive freestyle board in the Technine line. Dependable edge control and a perfect flex pattern for jumping in the park or out of bounds. Landins and progression will come easy with this board and it will help your riding progress to the next level. Street rails, park jibs, backcountry booters and park jumps, this board will do it all.
+ variants:
+ - *product-3-var-1
+ - *product-3-var-2
+ - *product-3-var-3
+
+ - &product-4
+ id: 4
+ title: Comic ~ Orange
+ handle: comic-orange
+ type: Snowboards
+ vendor: Technine
+ price: 19900
+ price_max: 19900
+ price_min: 19900
+ price_varies: false
+ available: true
+ tags:
+ - season2006
+ - beginner
+ - intermediate
+ - freestyle
+ - orange
+ options:
+ - Length
+ compare_at_price: 32900
+ compare_at_price_max: 32900
+ compare_at_price_min: 32900
+ compare_at_price_varies: false
+ url: /products/comic-orange
+ featured_image: products/technine3.jpg
+ images:
+ - products/technine3.jpg
+ - products/technine4.jpg
+ description:
+ 2005 Technine Comic Series Description The Comic series was developed to be the ultimate progressive freestyle board in the Technine line. Dependable edge control and a perfect flex pattern for jumping in the park or out of bounds. Landins and progression will come easy with this board and it will help your riding progress to the next level. Street rails, park jibs, backcountry booters and park jumps, this board will do it all.
+ variants:
+ - *product-4-var-1
+
+ - &product-5
+ id: 5
+ title: Burton Boots
+ handle: burton-boots
+ type: Boots
+ vendor: Burton
+ price: 11900
+ price_max: 11900
+ price_min: 11900
+ price_varies: false
+ available: true
+ tags:
+ - season2006
+ - beginner
+ - intermediate
+ - boots
+ options:
+ - Color
+ - Shoe Size
+ compare_at_price: 22900
+ compare_at_price_max: 22900
+ compare_at_price_min: 22900
+ compare_at_price_varies: false
+ url: /products/burton-boots
+ featured_image: products/burton.jpg
+ images:
+ - products/burton.jpg
+ description:
+ The Burton boots are particularly well on snowboards. The very best thing about them is that the according picture is cubic. This makes testing in a Vision testing environment very easy.
+ variants:
+ - *product-5-var-1
+ - *product-5-var-2
+ - *product-5-var-3
+ - *product-5-var-4
+ - *product-5-var-5
+ - *product-5-var-6
+
+ - &product-6
+ id: 6
+ title: Superbike 1198 S
+ handle: superbike
+ type: Superbike
+ vendor: Ducati
+ price: 2179500
+ price_max: 2179500
+ price_min: 2179500
+ price_varies: false
+ available: true
+ tags:
+ - ducati
+ - superbike
+ - bike
+ - street
+ - racing
+ - performance
+ options:
+ - Color
+ compare_at_price:
+ compare_at_price_max: 0
+ compare_at_price_min: 0
+ compare_at_price_varies: false
+ url: /products/superbike
+ featured_image: products/ducati.jpg
+ images:
+ - products/ducati.jpg
+ description:
+
‘S’ PERFORMANCE
+
Producing 170hp (125kW) and with a dry weight of just 169kg (372.6lb), the new 1198 S now incorporates more World Superbike technology than ever before by taking the 1198 motor and adding top-of-the-range suspension, lightweight chassis components and a true racing-style traction control system designed for road use.
+
The high performance, fully adjustable 43mm Öhlins forks, which sport low friction titanium nitride-treated fork sliders, respond effortlessly to every imperfection in the tarmac. Beyond their advanced engineering solutions, one of the most important characteristics of Öhlins forks is their ability to communicate the condition and quality of the tyre-to-road contact patch, a feature that puts every rider in superior control. The suspension set-up at the rear is complemented with a fully adjustable Öhlins rear shock equipped with a ride enhancing top-out spring and mounted to a single-sided swingarm for outstanding drive and traction. The front-to-rear Öhlins package is completed with a control-enhancing adjustable steering damper.
High Quality Shopify Shirt. Wear your e-commerce solution with pride and attract attention anywhere you go.
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Extra comfortable zip up sweater. Durable quality, ideal for any outdoor activities.
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Flagship pro D-SLR with a 12.1-MP FX-format CMOS sensor, blazing 9 fps shooting at full FX resolution and low-noise performance up to 6400 ISO.
+
Nikon's original 12.1-megapixel FX-format (23.9 x 36mm) CMOS sensor: Couple Nikon's exclusive digital image processing system with the 12.1-megapixel FX-format and you'll get breathtakingly rich images while also reducing noise to unprecedented levels with even higher ISOs.
+
Continuous shooting at up to 9 frames per second: At full FX resolution and up to 11fps in the DX crop mode, the D3 offers uncompromised shooting speeds for fast-action and sports photography.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ created_at: 2005-04-04 12:00
+
+blogs:
+ - id: 1
+ handle: news
+ title: News
+ url: /blogs/news
+ articles:
+ - id: 3
+ title: 'Welcome to the new Foo Shop'
+ author: Daniel
+ content:
Welcome to your Shopify store! The jaded Pixel crew is really glad you decided to take Shopify for a spin.
To help you get you started with Shopify, here are a couple of tips regarding what you see on this page.
The text you see here is an article. To edit this article, create new articles or create new pages you can go to the Blogs & Pages tab of the administration menu.
The Shopify t-shirt above is a product and selling products is what Shopify is all about. To edit this product, or create new products you can go to the Products Tab in of the administration menu.
While you're looking around be sure to check out the Collections and Navigations tabs and soon you will be well on your way to populating your site.
And of course don't forget to browse the theme gallery to pick a new look for your shop!
Shopify is in beta If you would like to make comments or suggestions please visit us in the Shopify Forums or drop us an email.
+ created_at: 2005-04-04 16:00
+ - id: 4
+ title: 'Breaking News: Restock on all sales products'
+ author: Tobi
+ content: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ created_at: 2005-04-04 12:00
+ articles_count: 2
+
+ - id: 2
+ handle: bigcheese-blog
+ title: Bigcheese blog
+ url: /blogs/bigcheese-blog
+ articles:
+ - id: 1
+ title: 'One thing you probably did not know yet...'
+ author: Justin
+ content: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ created_at: 2005-04-04 16:00
+ comments:
+ -
+ id: 1
+ author: John Smith
+ email: john@smith.com
+ content: Wow...great article man.
+ status: published
+ created_at: 2009-01-01 12:00
+ updated_at: 2009-02-01 12:00
+ url: ""
+ -
+ id: 2
+ author: John Jones
+ email: john@jones.com
+ content: I really enjoyed this article. And I love your shop! It's awesome. Shopify rocks!
+ status: published
+ created_at: 2009-03-01 12:00
+ updated_at: 2009-02-01 12:00
+ url: "http://somesite.com/"
+ - id: 2
+ title: Fascinating
+ author: Tobi
+ content: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ created_at: 2005-04-06 12:00
+ comments:
+ articles_count: 2
+ comments_enabled?: true
+ comment_post_url: ""
+ comments_count: 2
+ moderated?: true
+
+ - id: 3
+ handle: paginated-blog
+ title: Paginated blog
+ url: /blogs/paginated-blog
+ articles:
+ - id: 6
+ title: 'One thing you probably did not know yet...'
+ author: Justin
+ content: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ created_at: 2005-04-04 16:00
+
+ - id: 7
+ title: Fascinating
+ author: Tobi
+ content: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ created_at: 2005-04-06 12:00
+ articles_count: 200
diff --git a/lib/liquid/compile.rb b/lib/liquid/compile.rb
index e712e5c5..816488e0 100644
--- a/lib/liquid/compile.rb
+++ b/lib/liquid/compile.rb
@@ -1,12 +1,14 @@
# frozen_string_literal: true
require 'pry-byebug'
+require 'set'
module Liquid
class Compiler
def initialize
@ruby = +""
@nodes = {}
+ @declared = Set.new(['__l_product'])
end
def <<(line)
@@ -17,33 +19,51 @@ module Liquid
"__l_#{name}"
end
+ def declare(name)
+ @declared << name
+ end
+
+ def declared?(name)
+ @declared.member?(name)
+ end
+
def to_proc
- puts @ruby if ENV['SHOW_RUBY'] == '1'
- RubyVM::InstructionSequence.compile(<<~RUBY).eval.call(@nodes)
+ show_ruby = ENV["SHOW_RUBY"] && ENV["SHOW_RUBY"].to_i || 0
+ STDERR.puts @ruby if show_ruby >= 1
+ res = RubyVM::InstructionSequence.compile(<<~RUBY).eval.call(@nodes)
->(__nodes) {
- ->(__context, __output) {
+ ->(__context, __output, __l_product) {
+ __scope = __context.environments.first
#{@ruby}
__output
}
}
RUBY
+
+ STDERR.puts RubyVM::InstructionSequence.disasm(res) if show_ruby >= 2
+ res
end
- # Compiles any thing that can be returned by Expression/QuotedFragment
def compile_expr(node)
- case node
- when Liquid::VariableLookup
- @nodes[node.object_id] = node
+ if node.respond_to?(:compile_expr)
node.compile_expr(self)
- when Liquid::RangeLookup
- @nodes[node.object_id] = node
- node.compile_expr(self)
- when Range # returned by RangeLookup when range contains only literals
- node.inspect
- when Integer, Float, nil, true, false, ''
- node.inspect
else
- raise ArgumentError, "cannot compile node #{node.inspect}"
+ case node
+ when Range # returned by RangeLookup when range contains only literals
+ node.inspect
+ when Integer, Float, nil, true, false, String
+ node.inspect
+ else
+ raise ArgumentError, "cannot compile node #{node.inspect}"
+ end
+ end
+ end
+
+ def output(node)
+ self << if node.is_a?(String)
+ "__output << #{node.inspect}\n"
+ else
+ "__output << #{compile_expr(node)}.to_s\n"
end
end
@@ -67,38 +87,6 @@ module Liquid
RUBY
end
- def slice_collection_expr(collection_name, from_name, to_name)
- <<~RUBY.strip
- (begin
- if (#{from_name} != 0 || !#{to_name}.nil?) && #{collection_name}.respond_to?(:load_slice)
- #{collection_name}.load_slice(#{from_name}, #{to_name})
- else
- segments = []
- index = 0
- if #{collection_name}.is_a?(String)
- #{collection_name}.empty? ? [] : [collection]
- elsif !#{collection_name}.respond_to?(:each)
- []
- else
- #{collection_name}.each do |item|
- if #{to_name} && #{to_name} <= index
- break
- end
-
- if #{from_name} && #{from_name} <= index
- segments << item
- end
-
- index += 1
- end
-
- segments
- end
- end
- end)
- RUBY
- end
-
def compile(node)
if node.instance_of?(String)
self << "__output << #{node.inspect}\n"
@@ -113,7 +101,7 @@ module Liquid
nil
end
catch_errors(line_number, show_message: !node.blank?) do
- self << "__nodes[#{node.object_id}].render_to_output_buffer(__context, __output)\n"
+ self << "__nodes[#{node.object_id}].render_to_output_buffer(__context, __output) # #{node.inspect} \n"
end
end
end
@@ -135,13 +123,12 @@ module Liquid
self << "__output << __error_message\n" if show_message
self << "end\nend\n"
end
-
end
class BlockBody
def render_to_output_buffer(context, output)
raise "Tried to render uncompiled block" unless @compiled
- @compiled.call(context, output)
+ @compiled.call(context, output, context.environments[0][:product])
end
def compile_top_level
@@ -169,16 +156,88 @@ module Liquid
class VariableLookup
def compile_expr(compiler)
- compiler.var_name(@name)
+ # HACK
+ if @name == "forloop" && @lookups == ["first"]
+ return "forloop_first"
+ end
+
+ var_name = compiler.var_name(@name)
+ root = if compiler.declared?(var_name)
+ var_name
+ else
+ "__scope[#{@name.inspect}]"
+ end
+
+ @lookups.reduce(root) do |prev, lookup|
+ "#{prev}[:#{lookup}]"
+ end
end
end
class Variable
+ FILTERS = {
+ "modulo" => ->(compiler, expr, args, kwargs) {
+ "(#{expr} % #{args[0]})"
+ },
+ "product_img_url" => ->(compiler, expr, args, kwargs) {
+ style = args.fetch(0, 'small')
+
+ rest = case style
+ when 'original'
+ "\"/files/shops/random_number/\#{url}\""
+ when 'grande', 'large', 'medium', 'compact', 'small', 'thumb', 'icon'
+ "\"/files/shops/random_number/products/\#{$1}_#{style}.\#{$2}\""
+ else
+ "raise ArgumentError, 'valid parameters for filter \"size\" are: original, grande, large, medium, compact, small, thumb and icon '"
+ end
+
+ <<~RUBY.strip
+ (begin
+ if #{expr} =~ %r{\\Aproducts/([\\w\\-\\_]+)\\.(\\w{2,4})}
+ #{rest}
+ else
+ raise ArgumentError, 'filter \"size\" can only be called on product images'
+ end
+ end)
+ RUBY
+ },
+ "escape" => ->(compiler, expr, args, kwargs) {
+ "(_t = #{expr}; CGI.escape(_t) unless _t)"
+ },
+ "money" => ->(compiler, expr, args, kwargs) {
+ "(_m = #{expr}; _m.nil? ? '' : \"\#{(_m / 100.0).round(2)}\")"
+ },
+ }
+
def compile(compiler)
- compiler.catch_errors(@line_number, show_message: true) do
- compiler << "__output << #{@name.compile_expr(compiler)}.to_s\n"
+ if const?
+ compiler.output(name)
+ else
+ compiler.catch_errors(@line_number, show_message: true) do
+ compiler.output(self)
+ end
end
end
+
+ def const?
+ @filters.empty? && !name.respond_to?(:compile_expr)
+ end
+
+ def compile_expr(compiler)
+ @filters.reduce(compiler.compile_expr(name)) do |expr, (name, args, kwargs)|
+ if FILTERS.key?(name)
+ FILTERS[name].call(compiler, expr, args, kwargs)
+ else
+ expr
+ end
+ end
+ end
+ end
+
+ class Echo
+ def compile(compiler)
+ compiler.compile(variable)
+ end
end
class For
@@ -206,11 +265,64 @@ module Liquid
RUBY
end
+ item_var = compiler.var_name(variable_name)
compiler << <<~RUBY
- collection.each do |#{compiler.var_name(variable_name)}|
+ forloop_first = true
+ for #{item_var} in collection
RUBY
+ compiler.declare(item_var)
compiler.compile(@for_block)
+ compiler << <<~RUBY
+ forloop_first = false
+ end
+ RUBY
+
+ end
+ end
+
+ class If
+ def compile(compiler)
+ compiler << "if #{compiler.compile_expr(blocks[0])}\n"
+ compiler.compile(blocks[0].attachment)
+ blocks.drop(1).each do |block|
+ if block.else?
+ compiler << "else\n"
+ else
+ compiler << "elsif #{block.compile_expr(compiler)}\n"
+ end
+ compiler.compile(block.attachment)
+ end
compiler << "end\n"
end
end
+
+ class Comment
+ def compile(_compiler); end
+ end
+
+ class Condition
+ def compile_expr(compiler)
+ condition = if operator
+ left_expr = compiler.compile_expr(left)
+ right_expr = compiler.compile_expr(right)
+ expr = "((#{left_expr} #{operator} #{right_expr}) #{child_relation}"
+ else
+ left_expr = compiler.compile_expr(left)
+ right_expr = compiler.compile_expr(right)
+ expr = "#{left_expr}"
+ end
+ if child_condition
+ child_expr = compiler.compile_expr(child_condition)
+ condition << " #{child_expr}"
+ end
+ condition
+ end
+ end
+
+ class Assign
+ def compile(compiler)
+ compliler.declare(@to)
+ compiler << "#{compiler.var_name(@to)} = #{compiler.compile_expr(@from)}\n"
+ end
+ end
end
diff --git a/performance/benchmark b/performance/benchmark
index 9519db22..70f48771 100755
--- a/performance/benchmark
+++ b/performance/benchmark
@@ -1,8 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
-
-
unless ENV.key?("BUNDLE_BIN_PATH")
exec("bundle", "exec", "ruby", __FILE__, *ARGV)
end
@@ -156,6 +154,7 @@ def print_columns(cols)
end
end
+ITERS = 1
Benchmarks = Class.new do
def define(_name, benchmark)
@benchmark = benchmark
@@ -167,27 +166,32 @@ Benchmarks = Class.new do
parsed = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
# warmup
- 1000.times { @benchmark.render}
+ ITERS.times { @benchmark.render}
warm = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
res = nil
- 1000.times { res = @benchmark.render }
+ ITERS.times { res = @benchmark.render }
ran = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond)
- puts res if res.is_a?(String)
+ if res.is_a?(String)
+ puts res
+ puts "Output digest: #{Digest::SHA2.hexdigest(res)}"
+ end
if ENV['SHOW_RUBY'] == '1'
STDERR.puts "note: SHOW_RUBY prevents gathering parse metrics"
- STDERR.puts "render: #{(ran - warm) / 1000}µs"
+ STDERR.puts "render: #{(ran - warm) / ITERS}µs"
else
STDERR.puts "parse: #{parsed - start}µs"
- STDERR.puts "render: #{(ran - warm) / 1000}µs"
- STDERR.puts "total: #{(ran - warm) / 1000 + (parsed - start)}µs"
+ STDERR.puts "render: #{(ran - warm) / ITERS}µs"
+ STDERR.puts "total: #{(ran - warm) / ITERS + (parsed - start)}µs"
end
end
end.new
def execute
+ require 'digest'
+
if ARGV.count != 2
STDERR.puts "Usage: benchmark.rb record [output_path]"
exit(1)
diff --git a/performance/benchmarks/fizzbuzz_10000.rb b/performance/benchmarks/fizzbuzz_10000.rb
index 14558a1c..08c302f2 100644
--- a/performance/benchmarks/fizzbuzz_10000.rb
+++ b/performance/benchmarks/fizzbuzz_10000.rb
@@ -1,7 +1,22 @@
# frozen_string_literal: true
-Benchmarks.define('simple_loop', Class.new do
- TEMPLATE = "{% for i in (1..1000) %}{{ i }}{% endfor %}"
+Benchmarks.define('fizzbuzz_10000', Class.new do
+ TEMPLATE = <<~LIQUID
+ {% for i in (1..#{ENV['COUNT'].to_i}) %}
+ {% liquid
+ assign rem_3 = i | modulo: 3
+ assign rem_5 = i | modulo: 5
+ if rem_3 == 0 and rem_5 == 0
+ echo "Fizzbuzz"
+ elsif rem_3 == 0
+ echo "Fizz"
+ elsif rem_5 == 0
+ echo "Buzz"
+ else
+ echo i
+ endif
+ %}{% endfor %}
+ LIQUID
def compile
@parsed = Liquid::Template.parse(TEMPLATE)