lib/jekyll-flickr/flickr_tag.rb
def render(context)

        match = /(?<photo_id>\d+)(\s(\"(?<caption>[^"]+)\"))?(?<attr>.*)/.match @text

        photo_id = match.named_captures['photo_id']
        photo_caption = match.named_captures['caption']
        photo_attr = match.named_captures['attr']

        photo_data = cache.getset photo_id do
          {
            info:  flickr.photos.getInfo(photo_id: photo_id),
            sizes: flickr.photos.getSizes(photo_id: photo_id)
          }
        end

        widths = config['widths'] + [config['width_legacy']]
        photo_sizes = photo_data[:sizes].select{ |photo| widths.include?(photo['width'].to_i) }
        photo_legacy = photo_data[:sizes].find{ |photo| photo['width'].to_i == config['width_legacy']} || photo_data[:sizes].find{ |photo| photo['label'] == 'Original'}

        srcset = photo_sizes.map{|photo| "#{photo['source']} #{photo['width']}w"}.join(", ")

        sizes = unless photo_attr.include?('sizes=') then
          context.registers[:site].config['flickr']['width_viewport']
        else
          ""
        end

        if photo_caption and not photo_attr.include?('alt=') then
          photo_attr += " alt=\"#{photo_caption}\""
        end

        img_tag = "<img class=\"flickr\" src=\"#{photo_legacy.source}\" srcset=\"#{srcset}\" sizes=\"#{sizes}\" #{photo_attr}>"

        return img_tag if not config['figcaption']

        photo_license = if config['license'] then
          license = LICENSES[photo_data[:info].license.to_i]

          owner_link = "&copy; Flickr/<a href=\"#{photo_data[:info]['urls'].first['_content']}\">#{photo_data[:info]['owner']['username']}</a>"

          license_link = if license[:url]
            "<a href=\"#{license[:url]}\">#{license[:name]}</a>"
          else
            license[:name]
          end
          "<div class=\"license\">#{owner_link} #{license_link}</div>"
        else
          ""
        end

        photo_caption = if config['caption'] and photo_caption then
          "<div class=\"caption\">#{photo_caption}</div>"
        else
          ""
        end

        return img_tag if photo_license.empty? and photo_caption.empty?

        return <<-HTML
<figure class="flickr">
  #{img_tag}
  <figcaption>#{photo_caption}#{photo_license}</figcaption>
</figure>
        HTML
      end
# selection of sizes from those offered by Flickr API
selection of sizes from those offered by Flickr API
selection of sizes from those offered by Flickr API
def render(context)
        match = /(?<photo_id>\d+)(\s(\"(?<caption>[^"]+)\"))?(?<attr>.*)/.match @text
        photo_id = match.named_captures['photo_id']
        photo_caption = match.named_captures['caption']
        photo_attr = match.named_captures['attr']
        photo_data = cache.getset photo_id do
          {
            info:  flickr.photos.getInfo(photo_id: photo_id),
            sizes: flickr.photos.getSizes(photo_id: photo_id)
          }
        end
        widths = config['widths'] + [config['width_legacy']]
        photo_sizes = photo_data[:sizes].select{ |photo| widths.include?(photo['width'].to_i) }
        photo_legacy = photo_data[:sizes].find{ |photo| photo['width'].to_i == config['width_legacy']} || photo_data[:sizes].find{ |photo| photo['label'] == 'Original'}
        srcset = photo_sizes.map{|photo| "#{photo['source']} #{photo['width']}w"}.join(", ")
        sizes = unless photo_attr.include?('sizes=') then
          context.registers[:site].config['flickr']['width_viewport']
        else
          ""
        end
        if photo_caption and not photo_attr.include?('alt=') then
          photo_attr += " alt=\"#{photo_caption}\""
        end
        img_tag = "<img class=\"flickr\" src=\"#{photo_legacy.source}\" srcset=\"#{srcset}\" sizes=\"#{sizes}\" #{photo_attr}>"
        return img_tag if not config['figcaption']
        photo_license = if config['license'] then
          license = LICENSES[photo_data[:info].license.to_i]
          owner_link = "&copy; Flickr/<a href=\"#{photo_data[:info]['urls'].first['_content']}\">#{photo_data[:info]['owner']['username']}</a>"
          license_link = if license[:url]
            "<a href=\"#{license[:url]}\">#{license[:name]}</a>"
          else
            license[:name]
          end
          "<div class=\"license\">#{owner_link} #{license_link}</div>"
        else
          ""
        end
        photo_caption = if config['caption'] and photo_caption then
          "<div class=\"caption\">#{photo_caption}</div>"
        else
          ""
        end
        return img_tag if photo_license.empty? and photo_caption.empty?
        return <<-HTML
<figure class="flickr">
  #{img_tag}
  <figcaption>#{photo_caption}#{photo_license}</figcaption>
</figure>
        HTML
      end
def render ( context ) match = / (?<photo_id> \d +)( \s ( \" (?<caption>[^"]+) \" ))?(?<attr>.*) / . match @text photo_id = match . named_captures [ 'photo_id' ] photo_caption = match . named_captures [ 'caption' ] photo_attr = match . named_captures [ 'attr' ] photo_data = cache . getset photo_id do { info : flickr . photos . getInfo ( photo_id : photo_id ) , sizes : flickr . photos . getSizes ( photo_id : photo_id ) } end widths = config [ 'widths' ] + [ config [ 'width_legacy' ] ] photo_sizes = photo_data [ :sizes ] . select { | photo | widths . include? ( photo [ 'width' ] . to_i ) } photo_legacy = photo_data [ :sizes ] . find { | photo | photo [ 'width' ] . to_i == config [ 'width_legacy' ] } || photo_data [ :sizes ] . find { | photo | photo [ 'label' ] == 'Original' } srcset = photo_sizes . map { | photo | "#{photo['source']} #{photo['width']}w" } . join ( ", " ) sizes = unless photo_attr . include? ( 'sizes=' ) then context . registers [ :site ] . config [ 'flickr' ] [ 'width_viewport' ] else "" end if photo_caption and not photo_attr . include? ( 'alt=' ) then photo_attr += " alt=\"#{photo_caption}\"" end img_tag = "<img class=\"flickr\" src=\"#{photo_legacy.source}\" srcset=\"#{srcset}\" sizes=\"#{sizes}\" #{photo_attr}>" return img_tag if not config [ 'figcaption' ] photo_license = if config [ 'license' ] then license = LICENSES [ photo_data [ :info ] . license . to_i ] owner_link = "&copy; Flickr/<a href=\"#{photo_data[:info]['urls'].first['_content']}\">#{photo_data[:info]['owner']['username']}</a>" license_link = if license [ :url ] "<a href=\"#{license[:url]}\">#{license[:name]}</a>" else license [ :name ] end "<div class=\"license\">#{owner_link} #{license_link}</div>" else "" end photo_caption = if config [ 'caption' ] and photo_caption then "<div class=\"caption\">#{photo_caption}</div>" else "" end return img_tag if photo_license . empty? and photo_caption . empty? return <<-HTML 
<figure class="flickr">
   #{ img_tag } 
  <figcaption> #{ photo_caption } #{ photo_license } </figcaption>
</figure>
         HTML end
selection of sizes from those offered by Flickr API
selection of sizes from those offered by Flickr API
context