Class: ImgProperties
- Inherits:
-
Object
- Object
- ImgProperties
- 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
-
#align ⇒ Object
Returns the value of attribute align.
-
#alt ⇒ Object
Returns the value of attribute alt.
-
#attr_wrapper_align_class ⇒ Object
Returns the value of attribute attr_wrapper_align_class.
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#attribution ⇒ Object
Returns the value of attribute attribution.
-
#caption ⇒ Object
Returns the value of attribute caption.
-
#classes ⇒ Object
Returns the value of attribute classes.
-
#die_on_img_error ⇒ Object
Returns the value of attribute die_on_img_error.
-
#id ⇒ Object
Returns the value of attribute id.
-
#img_display ⇒ Object
Returns the value of attribute img_display.
-
#local_src ⇒ Object
Returns the value of attribute local_src.
-
#nofollow ⇒ Object
Returns the value of attribute nofollow.
-
#size ⇒ Object
Returns the value of attribute size.
-
#src ⇒ Object
Returns the value of attribute src.
-
#style ⇒ Object
Returns the value of attribute style.
-
#target ⇒ Object
Returns the value of attribute target.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
-
#wrapper_class ⇒ Object
Returns the value of attribute wrapper_class.
-
#wrapper_style ⇒ Object
Returns the value of attribute wrapper_style.
Class Method Summary collapse
Instance Method Summary collapse
- #attr_alt ⇒ Object
- #attr_id ⇒ Object
-
#attr_img_classes ⇒ Object
<img> tag assets, except alignment classes (inline, left, center, right).
- #attr_nofollow ⇒ Object
- #attr_size_class ⇒ Object
- #attr_style_img ⇒ Object
- #attr_target ⇒ Object
- #attr_title ⇒ Object
- #attr_width_style ⇒ Object
- #compute_dependant_properties ⇒ Object
- #src_any(filetype) ⇒ Object
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 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 |
#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 |
#nofollow ⇒ Object
Returns the value of attribute nofollow.
8 9 10 |
# File 'lib/img_props.rb', line 8 def nofollow @nofollow 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
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_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
<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_nofollow ⇒ Object
28 29 30 |
# File 'lib/img_props.rb', line 28 def attr_nofollow " rel='nofollow'" if @nofollow end |
#attr_size_class ⇒ Object
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_img ⇒ Object
42 43 44 |
# File 'lib/img_props.rb', line 42 def attr_style_img "style='width: 100%; #{@style}'".squish end |
#attr_target ⇒ Object
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_title ⇒ Object
53 54 55 |
# File 'lib/img_props.rb', line 53 def attr_title "title='#{@title}'" if @title && !@title.empty? end |
#attr_width_style ⇒ Object
57 58 59 |
# File 'lib/img_props.rb', line 57 def attr_width_style "width: #{@size};" if size_unit_specified? end |
#compute_dependant_properties ⇒ Object
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 |