Sha256: 3f1ff85ef819fc7515aa41708317658c4e82fd0b1ed5b58e009a0d60dcb162e2

Contents?: true

Size: 886 Bytes

Versions: 16

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true

module DocTemplate
  module Tags
    class ImageTag < TableTag
      TAG_NAME = 'image'
      TEMPLATES = { default: 'image.html.erb',
                    gdoc: 'gdoc/image.html.erb' }.freeze

      def parse_table(table)
        params = {
          caption: table.at_xpath('.//tr[2]/td').text,
          image_src: image_src,
          subject: @opts[:metadata].try(:[], 'subject')
        }
        @content = parse_template(params, template_name(@opts))
        replace_tag table
      end

      private

      def image_src
        filename = "#{@opts[:value]}.jpg"
        grade = @opts[:metadata]['grade']
        unit = @opts[:metadata]['unit']
        "https://unbounded-uploads-development.s3.amazonaws.com/ela-images/G#{grade}/#{unit}/#{filename}"
      end
    end
  end

  Template.register_tag(Tags::ImageTag::TAG_NAME, Tags::ImageTag)
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 lib/doc_template/tags/image_tag.rb
lcms-engine-0.5.4 lib/doc_template/tags/image_tag.rb
lcms-engine-0.5.3 lib/doc_template/tags/image_tag.rb
lcms-engine-0.5.2 lib/doc_template/tags/image_tag.rb
lcms-engine-0.5.1 lib/doc_template/tags/image_tag.rb
lcms-engine-0.5.0 lib/doc_template/tags/image_tag.rb
lcms-engine-0.4.2 lib/doc_template/tags/image_tag.rb
lcms-engine-0.4.1 lib/doc_template/tags/image_tag.rb
lcms-engine-0.4.0 lib/doc_template/tags/image_tag.rb
lcms-engine-0.3.1 lib/doc_template/tags/image_tag.rb
lcms-engine-0.1.4 lib/doc_template/tags/image_tag.rb
lcms-engine-0.3.0 lib/doc_template/tags/image_tag.rb
lcms-engine-0.1.3 lib/doc_template/tags/image_tag.rb
lcms-engine-0.2.0 lib/doc_template/tags/image_tag.rb
lcms-engine-0.1.2 lib/doc_template/tags/image_tag.rb
lcms-engine-0.1.0 lib/doc_template/tags/image_tag.rb