Class: Oembed::ImageProvider
- Inherits:
-
Object
- Object
- Oembed::ImageProvider
- Defined in:
- app/services/oembed/image_provider.rb
Overview
Custom oEmbed provider for WarmlyYours Images
Returns rendered image HTML using image_asset_tag for embedding in Redactor editor
This supports all ImageKit transformations and renders the same HTML structure
used across the site (figure + figcaption, srcset, lazy loading, etc.)
Usage:
provider = Oembed::ImageProvider.new
result = provider.get(
image_id: 123,
caption: 'My image caption',
width: 800,
crop_x: 100, crop_y: 50, crop_w: 400, crop_h: 300
)
result[:html] # => Rendered image HTML
Defined Under Namespace
Classes: ImageNotFoundError
Constant Summary collapse
- VALID_IMAGE_OPTIONS =
All valid options that can be passed to image_url
See Models::Imageable::VALID_IMAGE_URL_OPTIONS %i[ encode_format size borderx bordery size_modifier percentage width height crop_x crop_y crop_w crop_h crop_mode crop_last rotate relative hostname cache webp download optimize thumbnail background progressive_jpeg blur quality focus zoom radius border border_color ].freeze
- VALID_DISPLAY_OPTIONS =
Display options for the rendered tag
%i[ caption lazyload include_srcset sizes class alt link link_target wrapper_tag ].freeze
- DEFAULT_MAX_WIDTH =
Default max width to prevent enormous images from being inserted
The srcset will still provide smaller sizes for appropriate viewports 2000
Instance Method Summary collapse
-
#get(options = {}) ⇒ Hash
Get rendered image HTML.
Instance Method Details
#get(options = {}) ⇒ Hash
Get rendered image HTML
60 61 62 63 64 65 66 67 68 |
# File 'app/services/oembed/image_provider.rb', line 60 def get( = {}) image_id = [:image_id] raise ImageNotFoundError, 'No image ID provided' if image_id.blank? image = Image.find_by(id: image_id) raise ImageNotFoundError, "Image not found: #{image_id}" unless image build_response(image, ) end |