Class: ImgProperties

Inherits:
Object
  • Object
show all
Defined in:
lib/img_props.rb

Overview

Properties from user All methods are idempotent. attr_ methods can be called after compute_dependant_properties All methods except compute_dependant_properties can be called in any order

Constant Summary collapse

SIZES =
%w[eighthsize fullsize halfsize initial quartersize].freeze
UNITS =
%w[Q ch cm em dvh dvw ex in lh lvh lvw mm pc px pt rem rlh svh svw vb vh vi vmax vmin vw %].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alignObject

Returns the value of attribute align.



8
9
10
# File 'lib/img_props.rb', line 8

def align
  @align
end

#altObject

Returns the value of attribute alt.



8
9
10
# File 'lib/img_props.rb', line 8

def alt
  @alt
end

#attr_wrapper_align_classObject

Returns the value of attribute attr_wrapper_align_class.



8
9
10
# File 'lib/img_props.rb', line 8

def attr_wrapper_align_class
  @attr_wrapper_align_class
end

#attributeObject

Returns the value of attribute attribute.



8
9
10
# File 'lib/img_props.rb', line 8

def attribute
  @attribute
end

#attributionObject

Returns the value of attribute attribution.



8
9
10
# File 'lib/img_props.rb', line 8

def attribution
  @attribution
end

#captionObject

Returns the value of attribute caption.



8
9
10
# File 'lib/img_props.rb', line 8

def caption
  @caption
end

#classesObject

Returns the value of attribute classes.



8
9
10
# File 'lib/img_props.rb', line 8

def classes
  @classes
end

#die_on_img_errorObject

Returns the value of attribute die_on_img_error.



8
9
10
# File 'lib/img_props.rb', line 8

def die_on_img_error
  @die_on_img_error
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/img_props.rb', line 8

def id
  @id
end

#img_displayObject

Returns the value of attribute img_display.



8
9
10
# File 'lib/img_props.rb', line 8

def img_display
  @img_display
end

#local_srcObject

Returns the value of attribute local_src.



8
9
10
# File 'lib/img_props.rb', line 8

def local_src
  @local_src
end

#nofollowObject

Returns the value of attribute nofollow.



8
9
10
# File 'lib/img_props.rb', line 8

def nofollow
  @nofollow
end

#sizeObject

Returns the value of attribute size.



8
9
10
# File 'lib/img_props.rb', line 8

def size
  @size
end

#srcObject

Returns the value of attribute src.



8
9
10
# File 'lib/img_props.rb', line 8

def src
  @src
end

#styleObject

Returns the value of attribute style.



8
9
10
# File 'lib/img_props.rb', line 8

def style
  @style
end

#targetObject

Returns the value of attribute target.



8
9
10
# File 'lib/img_props.rb', line 8

def target
  @target
end

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/img_props.rb', line 8

def title
  @title
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/img_props.rb', line 8

def url
  @url
end

#wrapper_classObject

Returns the value of attribute wrapper_class.



8
9
10
# File 'lib/img_props.rb', line 8

def wrapper_class
  @wrapper_class
end

#wrapper_styleObject

Returns the value of attribute wrapper_style.



8
9
10
# File 'lib/img_props.rb', line 8

def wrapper_style
  @wrapper_style
end

Class Method Details

.local_path?(src) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/img_props.rb', line 76

def self.local_path?(src)
  first_char = src[0]
  first_char.match?(%r{[./]})
end

Instance Method Details

#attr_altObject



15
16
17
# File 'lib/img_props.rb', line 15

def attr_alt
  "alt='#{@alt}'" if @alt
end

#attr_idObject



19
20
21
# File 'lib/img_props.rb', line 19

def attr_id
  " id='#{@id}'" if @id
end

#attr_img_classesObject

<img> tag assets, except alignment classes (inline, left, center, right)



24
25
26
# File 'lib/img_props.rb', line 24

def attr_img_classes
  @classes || 'rounded shadow'
end

#attr_nofollowObject



28
29
30
# File 'lib/img_props.rb', line 28

def attr_nofollow
  " rel='nofollow'" if @nofollow
end

#attr_size_classObject



32
33
34
35
36
37
38
39
40
# File 'lib/img_props.rb', line 32

def attr_size_class
  return nil if @size == false || @size.nil? || size_unit_specified?

  unless SIZES.include?(@size)
    msg = "'#{@size}' is not a recognized size; must be one of #{SIZES.join(', ')}, or an explicit unit."
    raise Jekyll::ImgError, msg
  end
  @size
end

#attr_style_imgObject



42
43
44
# File 'lib/img_props.rb', line 42

def attr_style_img
  "style='width: 100%; #{@style}'".squish
end

#attr_targetObject



46
47
48
49
50
51
# File 'lib/img_props.rb', line 46

def attr_target
  return nil if @target == 'none'

  target = @target || '_blank'
  " target='#{target}'"
end

#attr_titleObject



53
54
55
# File 'lib/img_props.rb', line 53

def attr_title
  "title='#{@title}'" if @title && !@title.empty?
end

#attr_width_styleObject



57
58
59
# File 'lib/img_props.rb', line 57

def attr_width_style
  "width: #{@size};" if size_unit_specified?
end

#compute_dependant_propertiesObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/img_props.rb', line 61

def compute_dependant_properties
  setup_src

  @target ||= '_blank'

  @img_display = @caption && @size ? 'imgBlock' : 'imgFlex'

  @alt   ||= @caption || @title
  @title ||= @caption || @alt
end

#src_any(filetype) ⇒ Object



72
73
74
# File 'lib/img_props.rb', line 72

def src_any(filetype)
  @src.gsub(/\..*?$/, ".#{filetype}")
end