class Bridgetown::Cloudinary::Builder
Constants
- CONFIG_DEFAULTS
Public Instance Methods
add_image_urls_to_resources()
click to toggle source
Populate front matter
# File lib/bridgetown-cloudinary/builder.rb, line 40 def add_image_urls_to_resources Bridgetown::Cloudinary::Utils.add_image_urls_to_resources( site, config[:cloudinary] ) end
build()
click to toggle source
Set up the Cloudinary
configuration
# File lib/bridgetown-cloudinary/builder.rb, line 26 def build ::Cloudinary.config({ "cloud_name" => config[:cloudinary][:cloud_name], "secure" => true, }) generator :add_image_urls_to_resources liquid_tag "cloudinary_img", :img_tag liquid_filter "cloudinary_url", :url_filter helper "cloudinary_img", :img_helper helper "cloudinary_url", :url_filter end
img_helper(alt, id, transformation = nil)
click to toggle source
Define the “cloudinary_img” Ruby helper
# File lib/bridgetown-cloudinary/builder.rb, line 57 def img_helper(alt, id, transformation = nil) "<img alt=\"#{alt}\" src=\"#{url_filter(id, transformation)}\" />" end
img_tag(attributes, tag)
click to toggle source
Define the “cloudinary_img” Liquid tag
# File lib/bridgetown-cloudinary/builder.rb, line 47 def img_tag(attributes, tag) alt, id, transformation = attributes.split(",").map(&:strip) alt = variable_in_context(alt, tag.context) id = variable_in_context(id, tag.context) transformation&.delete! '"' "<img alt=\"#{alt}\" src=\"#{url_filter(id, transformation)}\" />" end
url_filter(id, transformation = nil)
click to toggle source
Define the “cloudinary_url” Liquid filter / Ruby helper
# File lib/bridgetown-cloudinary/builder.rb, line 62 def url_filter(id, transformation = nil) Bridgetown::Cloudinary::Utils.url( config: config[:cloudinary], id: id, transformation: transformation ) end
Protected Instance Methods
variable_in_context(variable, tag_context)
click to toggle source
# File lib/bridgetown-cloudinary/builder.rb, line 70 def variable_in_context(variable, tag_context) if variable.include? '"' variable.delete! '"' elsif variable.include? "." obj, var = variable.split(".") variable = tag_context[obj][var] else variable = tag_context[variable] end xml_escape(variable) end