Class: EmbeddableContent::Images::ImgTagAttributes

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
app/services/embeddable_content/images/img_tag_attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_processor) ⇒ ImgTagAttributes

Returns a new instance of ImgTagAttributes.



13
14
15
# File 'app/services/embeddable_content/images/img_tag_attributes.rb', line 13

def initialize(node_processor)
  @node_processor = node_processor
end

Instance Attribute Details

#node_processorObject (readonly)

Returns the value of attribute node_processor.



5
6
7
# File 'app/services/embeddable_content/images/img_tag_attributes.rb', line 5

def node_processor
  @node_processor
end

Instance Method Details

#heightObject

TODO: should this be abstracted?



43
44
45
46
47
48
# File 'app/services/embeddable_content/images/img_tag_attributes.rb', line 43

def height
  case target
  when :editable then height_for_editable_target
  when :cc, :kiddom, :qti, :schoology then image_height
  end
end

#srcObject



25
26
27
28
29
30
31
32
33
# File 'app/services/embeddable_content/images/img_tag_attributes.rb', line 25

def src
  case target
  when :schoology, :cc, :kiddom then s3_url with_extension: false
  when :cms                     then cms_url
  when :editable                then downloaded_file_url
  when :exported, :qti          then s3_url with_extension: false
  when :print, :web             then record.cdn_url
  end
end

#to_hObject



17
18
19
20
21
22
23
# File 'app/services/embeddable_content/images/img_tag_attributes.rb', line 17

def to_h
  { alt:    strip_tags(alt_text),
    src:    src,
    height: height,
    class:  css_classes,
    width:  width }.merge(aria_attrs).compact
end

#widthObject



35
36
37
38
39
40
# File 'app/services/embeddable_content/images/img_tag_attributes.rb', line 35

def width
  case target
  when :editable then width_for_editable_target
  when :cc, :kiddom, :qti, :schoology then image_width
  end
end