class LightboxBlockMacro
Public Instance Methods
process(parent, target, attrs)
click to toggle source
# File lib/starter_web/_plugins/asciidoctor-extensions/lightbox-block.rb, line 41 def process parent, target, attrs html_block = Builder::XmlMarkup.new(:indent => 2) imagesdir = parent.attr 'imagesdir' images_hash = Hash[*attrs['image_data'].split(',')] title_html = (attrs.has_key? 'title') ? %(<div class="title">#{attrs['title']}</div>\n) : nil role = (attrs.has_key? 'role') ? role : 'mb-3' grouped = (attrs.has_key? 'group') ? true : false if grouped html_block.div(:class=>"content") { images_hash.each do |i,d| image = i.strip descr = d.strip html_block.a(:class=>"notoc",:href=>"#{imagesdir}/#{image}", :"data-lightbox"=>"lb-#{target}", :"data-title"=>"#{descr}"){ html_block.img(:class=>"img-fluid", :src=>"#{imagesdir}/#{image}", :alt=>"#{attrs['title']}", :width=>"#{attrs['size']}") } end } else html_block.div(:class=>"content") { images_hash.each do |i,d| image = i.strip descr = d.strip html_block.a(:class=>"notoc", :href=>"#{imagesdir}/#{image}", :"data-lightbox"=>"#{image}", :"data-title"=>"#{descr}"){ html_block.img(:class=>"img-fluid", :src=>"#{imagesdir}/#{image}", :alt=>"#{attrs['title']}", :width=>"#{attrs['size']}") } end } end content = html_block.target! # See: https://stackoverflow.com/questions/4961609/extra-to-s-when-using-builder-to-generate-xml html = %( <div id="lb-#{target}" class="imageblock #{role}"> #{title_html} #{content} </div> ) create_pass_block parent, html, attrs, subs: nil end