From 4b69f6ae83b3ab0f7b680f4bfd6cae37cdd0c365 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Wed, 19 Mar 2014 17:55:29 -0400 Subject: [PATCH] Use render! in benchmarks to avoid making it faster by breaking things. --- performance/shopify/shop_filter.rb | 16 ++++++++++++++-- performance/theme_runner.rb | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/performance/shopify/shop_filter.rb b/performance/shopify/shop_filter.rb index be2dbb2..27b6b57 100644 --- a/performance/shopify/shop_filter.rb +++ b/performance/shopify/shop_filter.rb @@ -45,11 +45,11 @@ module ShopFilter end def url_for_vendor(vendor_title) - "/collections/#{vendor_title.to_handle}" + "/collections/#{to_handle(vendor_title)}" end def url_for_type(type_title) - "/collections/#{type_title.to_handle}" + "/collections/#{to_handle(type_title)}" end def product_img_url(url, style = 'small') @@ -95,4 +95,16 @@ module ShopFilter 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/performance/theme_runner.rb b/performance/theme_runner.rb index f1caf9a..ab8274e 100644 --- a/performance/theme_runner.rb +++ b/performance/theme_runner.rb @@ -8,6 +8,7 @@ require 'rubygems' require 'active_support' +require 'active_support/json' require 'yaml' require 'digest/md5' require File.dirname(__FILE__) + '/shopify/liquid' @@ -70,11 +71,11 @@ class ThemeRunner tmpl.assigns['template'] = page_template tmpl.registers[:file_system] = ThemeRunner::FileSystem.new(File.dirname(template_file)) - content_for_layout = tmpl.parse(template).render(assigns) + content_for_layout = tmpl.parse(template).render!(assigns) if layout assigns['content_for_layout'] = content_for_layout - tmpl.parse(layout).render(assigns) + tmpl.parse(layout).render!(assigns) else content_for_layout end