Skip to content

Commit

Permalink
Merge pull request #100 from mojavelinux/find-bg-image
Browse files Browse the repository at this point in the history
find the background image block in a portable and reliable way
  • Loading branch information
obilodeau authored Sep 27, 2016
2 parents 61159fc + 60b9d91 commit 056c95f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions templates/slim/section.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 056c95f

Please sign in to comment.