Class: Bridgetown::Cloudinary::Builder
- Inherits:
-
Builder
- Object
- Builder
- Bridgetown::Cloudinary::Builder
- Includes:
- Filters
- Defined in:
- lib/bridgetown-cloudinary/builder.rb
Constant Summary collapse
- CONFIG_DEFAULTS =
{ cloudinary: { cloud_name: nil, default_transformation: "open_graph", default_image_format: "jpg", transformations: { open_graph: "c_fill,g_face:center,w_1600,h_900,q_50", tiny: "w_300,c_limit,q_90", small: "w_600,c_limit,q_85", medium: "w_1200,c_limit,q_80", large: "w_1800,c_limit,q_80", xlarge: "w_2048,c_limit,q_75", }, add_transformed_urls_to_image_front_matter: false, }, }.freeze
Instance Method Summary collapse
-
#add_image_urls_to_resources ⇒ Object
Populate front matter.
-
#build ⇒ Object
Set up the Cloudinary configuration.
-
#img_helper(alt, id, transformation = nil) ⇒ Object
Define the “cloudinary_img” Ruby helper.
-
#img_tag(attributes, tag) ⇒ Object
Define the “cloudinary_img” Liquid tag.
-
#url_filter(id, transformation = nil) ⇒ Object
Define the “cloudinary_url” Liquid filter / Ruby helper.
Instance Method Details
#add_image_urls_to_resources ⇒ Object
Populate front matter
40 41 42 43 44 |
# 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 ⇒ Object
Set up the Cloudinary configuration
26 27 28 29 30 31 32 33 34 35 36 37 |
# 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) ⇒ Object
Define the “cloudinary_img” Ruby helper
57 58 59 |
# 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) ⇒ Object
Define the “cloudinary_img” Liquid tag
47 48 49 50 51 52 53 54 |
# 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) ⇒ Object
Define the “cloudinary_url” Liquid filter / Ruby helper
62 63 64 65 66 |
# 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 |