From 60b9d917f2d798cb3edf0d74a6bc90acc990dd2d Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Fri, 23 Sep 2016 15:47:02 -0600 Subject: [PATCH] find the background image block in a portable and reliable way --- templates/slim/section.html.slim | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/templates/slim/section.html.slim b/templates/slim/section.html.slim index 5d724fd3..8a0c88ff 100644 --- a/templates/slim/section.html.slim +++ b/templates/slim/section.html.slim @@ -13,19 +13,20 @@ - data_background_image, data_background_size, data_background_repeat, data_background_transition = nil -/ find all images under current node with attribute background or canvas -/ as long as they are of the same level as we are currently processing -- slide_images = find_by(:context => :image) { |image| -- (image.attr(1) == 'background' || image.attr(1) == 'canvas') && image.level == level -- } -- unless slide_images.nil? or slide_images.length == 0 - - slide_images.each do |image| - - data_background_image = image_uri(image.attr 'target') - / make sure no crash on nil and default values make sense - - data_background_size = image.attr 'size' - - data_background_repeat = image.attr 'repeat' - - data_background_transition = image.attr 'transition' - - break +/ process the first image block in the current section that acts as a background +- section_images = blocks.map do |block| + - if (ctx = block.context) == :image + - ['background', 'canvas'].include?(block.attr 1) ? block : [] + - elsif ctx == :section + - [] + - else + - block.find_by(context: :image) {|image| ['background', 'canvas'].include?(image.attr 1) } || [] +- if (bg_image = section_images.flatten.first) + - data_background_image = image_uri(bg_image.attr 'target') + / make sure no crash on nil and default values make sense + - data_background_size = bg_image.attr 'size' + - data_background_repeat = bg_image.attr 'repeat' + - data_background_transition = bg_image.attr 'transition' / background-image section attribute overrides the image one - if attr? 'background-image'