Class: JekyllIS::Images::Kramdown::Image
- Defined in:
- lib/jekyll-is/images/kramdown/image.rb
Instance Attribute Summary collapse
-
#alt ⇒ Object
readonly
Returns the value of attribute alt.
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#caption_position ⇒ Object
readonly
Returns the value of attribute caption_position.
-
#crop ⇒ Object
readonly
Returns the value of attribute crop.
-
#figure ⇒ Object
readonly
Returns the value of attribute figure.
-
#fit ⇒ Object
readonly
Returns the value of attribute fit.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#lazy ⇒ Object
readonly
Returns the value of attribute lazy.
-
#salt ⇒ Object
readonly
Returns the value of attribute salt.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#shift ⇒ Object
readonly
Returns the value of attribute shift.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#up ⇒ Object
readonly
Returns the value of attribute up.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Attributes inherited from Value
#attrs, #classes, #context, #flags, #id, #styles
Instance Method Summary collapse
- #apply(element) ⇒ Object
- #category ⇒ Object
-
#initialize(context, figure: nil) ⇒ Image
constructor
A new instance of Image.
- #to_html(overlay: {}) ⇒ Object
- #type ⇒ Object
Methods inherited from Value
Constructor Details
#initialize(context, figure: nil) ⇒ Image
Returns a new instance of Image.
13 14 15 16 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 13 def initialize context, figure: nil super(context) @figure = figure end |
Instance Attribute Details
#alt ⇒ Object (readonly)
Returns the value of attribute alt.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def alt @alt end |
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def caption @caption end |
#caption_position ⇒ Object (readonly)
Returns the value of attribute caption_position.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def caption_position @caption_position end |
#crop ⇒ Object (readonly)
Returns the value of attribute crop.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def crop @crop end |
#figure ⇒ Object (readonly)
Returns the value of attribute figure.
11 12 13 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 11 def figure @figure end |
#fit ⇒ Object (readonly)
Returns the value of attribute fit.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def fit @fit end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def format @format end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def height @height end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def href @href end |
#lazy ⇒ Object (readonly)
Returns the value of attribute lazy.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def lazy @lazy end |
#salt ⇒ Object (readonly)
Returns the value of attribute salt.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def salt @salt end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def scale @scale end |
#shift ⇒ Object (readonly)
Returns the value of attribute shift.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def shift @shift end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def src @src end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def title @title end |
#up ⇒ Object (readonly)
Returns the value of attribute up.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def up @up end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
18 19 20 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 18 def width @width end |
Instance Method Details
#apply(element) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 20 def apply element super(element) super(element.children.first) if element.type == :a @alt = @attrs.delete('alt') @src = @attrs.delete('src') @format = @attrs.delete('format') || @context.detect_format(@src) @href = @attrs.delete('href') || @context.config('default_link') @href = @context.config("default_link") if @href == '' @href = false if [ '0', 'false', 'no', 'none' ].include?(@href) @href = 'view' if [ '1', 'true', 'yes', 'auto' ].include?(@href) @title = @attrs.delete('title') @width = @attrs.delete('width')&.to_i @height = @attrs.delete('height')&.to_i @scale = @attrs.delete('scale')&.to_f @crop = @attrs.delete('crop') @fit = @attrs.delete('fit') @shift = @attrs.delete('shift')&.to_i @up = @attrs.delete('up')&.to_i @caption = @attrs.delete('caption') @alt ||= @title || @caption || '' @title ||= @alt unless @alt.nil? || @alt.empty? @title ||= @caption @title = nil if @title == '' @caption = nil if @caption == '' @caption ||= @alt if @flags.delete?('caption') @lazy = @flags.delete?('lazy') @salt = @attrs.delete('salt') @caption_position = @attrs.delete('caption-position') end |
#category ⇒ Object
9 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 9 def category = :span |
#to_html(overlay: {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 50 def to_html(overlay: {}) @context.page.data['__is_images_has_images'] = true transform = transform_parameters image = JekyllIS::Images::Image::transform @context, @src, transform ['__url'] = image.url img_styles = @styles.dup if transform[:width] img_styles['--is-images-width'] = "#{ transform[:width] }px" elsif transform[:height] && image.aspect_ratio img_styles['--is-images-width'] = "#{ transform[:height] * image.aspect_ratio }px" end img_styles['--is-images-aspect-ratio'] = image.aspect_ratio.to_s if image.aspect_ratio img_styles['--is-images-scale'] = transform[:scale] if transform[:scale] img_styles['--is-images-fit'] = transform[:fit] if transform[:fit] img_styles['--is-images-shift'] = "#{ @shift }px" if @shift img_styles['--is-images-up'] = "#{ @up }px" if @up img_classes = @classes.dup img_classes << '__is_images_image' img_classes << "__is_images_#{ ['mode'] }" if ['mode'] @flags.each do |flag| img_classes << "__is_images__#{ flag }" end img_attrs = {} img_attrs['id'] = @id if @id img_attrs['src'] = image.url img_attrs['alt'] = @alt if @alt img_attrs['class'] = img_classes.join(' ') img_attrs['style'] = img_styles.map { |k, v| "#{ k }:#{ v };" }.join('') img_attrs['loading'] = 'lazy' if @lazy || ['lazy'] img_attrs['data-scale'] = transform[:scale] || 1 img_attrs['data-caption'] = process_caption(@caption) if @caption data = @attrs.select { |k, _| k.start_with?("data-") } img_attrs.merge! data img = "<img #{ img_attrs.map { |k, v| "#{ k }=\"#{ v }\"" }.join(' ') }>" wrp_tag = 'a' wrp_attrs = {} if @href == 'view' if @src.start_with?('http://') || @src.start_with?('https://') wrp_attrs['href'] = @src else view_transform = view_transform_parameters image = JekyllIS::Images::Image::transform @context, @src, view_transform wrp_attrs['href'] = image.url end elsif @href wrp_attrs['href'] = @href else wrp_tag = 'span' end wrp_attrs['title'] = @title if @title wrp_attrs['class'] = '__is_images_wrapper' "<#{ wrp_tag } #{ wrp_attrs.map { |k, v| "#{ k }=\"#{ v }\"" }.join(' ') }>#{ img }</#{ wrp_tag }>" end |
#type ⇒ Object
8 |
# File 'lib/jekyll-is/images/kramdown/image.rb', line 8 def type = :is_image |