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

#align ⇒ Object

Returns the value of attribute align.



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

def align
  @align
end

#alt ⇒ Object

Returns the value of attribute alt.



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

def alt
  @alt
end

#attr_wrapper_align_class ⇒ Object

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

#attribute ⇒ Object

Returns the value of attribute attribute.



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

def attribute
  @attribute
end

#attribution ⇒ Object

Returns the value of attribute attribution.



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

def attribution
  @attribution
end

#caption ⇒ Object

Returns the value of attribute caption.



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

def caption
  @caption
end

#classes ⇒ Object

Returns the value of attribute classes.



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

def classes
  @classes
end

#die_on_img_error ⇒ Object

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

#id ⇒ Object

Returns the value of attribute id.



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

def id
  @id
end

#img_display ⇒ Object

Returns the value of attribute img_display.



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

def img_display
  @img_display
end

#lazy ⇒ Object

Returns the value of attribute lazy.



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

def lazy
  @lazy
end

#local_src ⇒ Object

Returns the value of attribute local_src.



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

def local_src
  @local_src
end

#max_width ⇒ Object

Returns the value of attribute max_width.



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

def max_width
  @max_width
end

#nofollow ⇒ Object

Returns the value of attribute nofollow.



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

def nofollow
  @nofollow
end

#priority ⇒ Object

Returns the value of attribute priority.



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

def priority
  @priority
end

#size ⇒ Object

Returns the value of attribute size.



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

def size
  @size
end

#src ⇒ Object

Returns the value of attribute src.



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

def src
  @src
end

#style ⇒ Object

Returns the value of attribute style.



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

def style
  @style
end

#target ⇒ Object

Returns the value of attribute target.



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

def target
  @target
end

#title ⇒ Object

Returns the value of attribute title.



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

def title
  @title
end

#url ⇒ Object

Returns the value of attribute url.



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

def url
  @url
end

#wrapper_class ⇒ Object

Returns the value of attribute wrapper_class.



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

def wrapper_class
  @wrapper_class
end

#wrapper_style ⇒ Object

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)


93
94
95
96
# File 'lib/img_props.rb', line 93

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

Instance Method Details

#attr_alt ⇒ Object



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

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

#attr_id ⇒ Object



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

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

#attr_img_classes ⇒ Object

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_max_width_class ⇒ Object

FIXME: this method does not work when max-width is specified as a % or a unit such as 15em

Returns:

  • class name: max_fullsize, max_halfsize, max_quartersize



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

def attr_max_width_class
  return nil if @max_width == false || @max_width.nil? || max_width_unit_specified?

  unless SIZES.include?(@max_width) || @max_width.end_with?('%')
    msg = "'#{@max_width}' is not a recognized size; must be one of #{SIZES.join(', ')}, or an explicit unit."
    raise Jekyll::ImgError, msg
  end
  "max_#{@max_width}" # FIXME: this only works with fullsize, halfsize, quartersize and not % or units
end

#attr_max_width_style ⇒ Object



70
71
72
# File 'lib/img_props.rb', line 70

def attr_max_width_style
  "max-width: #{@max_width};" if max_width_unit_specified?
end

#attr_nofollow ⇒ Object



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

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

#attr_size_class ⇒ Object

FIXME: this method does not work when width is specified as a unit such as 15em



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

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_img ⇒ Object



55
56
57
# File 'lib/img_props.rb', line 55

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

#attr_target ⇒ Object



59
60
61
62
63
64
# File 'lib/img_props.rb', line 59

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

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

#attr_title ⇒ Object



66
67
68
# File 'lib/img_props.rb', line 66

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

#attr_width_style ⇒ Object



74
75
76
# File 'lib/img_props.rb', line 74

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

#compute_dependant_properties ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/img_props.rb', line 78

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



89
90
91
# File 'lib/img_props.rb', line 89

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