Module: RailsAmp::ViewHelpers::ImageTagHelper
- Defined in:
- lib/rails_amp/view_helpers/image_tag_helper.rb
Constant Summary collapse
- AMP_IMG_PERMITTED_ATTRIBUTES =
%w[ src srcset alt attribution height width fallback heights layout media noloading on placeholder sizes class ].freeze
Instance Method Summary collapse
- #amp_image_tag(source, options = {}) ⇒ Object
-
#image_tag(source, options = {}) ⇒ Object
override image_tag helper in ActionView::Helpers::AssetTagHelper.
Instance Method Details
#amp_image_tag(source, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rails_amp/view_helpers/image_tag_helper.rb', line 14 def amp_image_tag(source, ={}) = .symbolize_keys check_for_image_tag_errors() if defined?(check_for_image_tag_errors) src = [:src] = path_to_image(source, skip_pipeline: .delete(:skip_pipeline)) unless src.start_with?("cid:") || src.start_with?("data:") || src.blank? [:alt] = .fetch(:alt){ image_alt(src) } end [:width], [:height] = extract_dimensions(.delete(:size)) if [:size] if [:width].blank? || [:height].blank? [:width], [:height] = compute_image_size(source) end [:layout] ||= 'fixed' .select! { |key, _| key.to_s.in?(AMP_IMG_PERMITTED_ATTRIBUTES) } tag('amp-img', ) + '</amp-img>'.html_safe end |
#image_tag(source, options = {}) ⇒ Object
override image_tag helper in ActionView::Helpers::AssetTagHelper
36 37 38 39 40 41 42 |
# File 'lib/rails_amp/view_helpers/image_tag_helper.rb', line 36 def image_tag(source, ={}) if controller && RailsAmp.amp_renderable?(controller.controller_path, controller.action_name) amp_image_tag(source, ) else super end end |