Class: Liquid::Image
- Inherits:
-
DmCore::LiquidTag
- Object
- DmCore::LiquidTag
- Liquid::Image
- Includes:
- ActionView::Helpers::AssetTagHelper, ActionView::Helpers::TagHelper, DmCore::AccountHelper, DmCore::ParamsHelper, DmCore::UrlHelper
- Defined in:
- lib/dm_cms/liquid/tags/image.rb
Class Method Summary collapse
-
.details ⇒ Object
——————————————————————————.
Instance Method Summary collapse
-
#render(context) ⇒ Object
——————————————————————————.
Class Method Details
.details ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dm_cms/liquid/tags/image.rb', line 30 def self.details { name: self.tag_name, summary: 'Displays an image', category: 'media', description: "Displays an image. Will pull image (with optional version) from the site's media directory unless a full path is given.\nAny normal HTML img attributes can be passed, such `alt`, `title`, `width`, etc\n\nParameters:\n\nsrc\n: name of the image. Can either reference a file in the 'media' directory (`2014/car.jpg`), a full path (`http://example.com/image/car.jpg`)\nor reference an S3 file (`s3://bucket/car.jpg`)\n\nversion\n: (optional) Use a specific image version (`thumb`, `lg`, etc)\n\nprotected\n: (optional) File is in protected directory. `version` will have no effect with this option\n\nhtml img attributes\n: you can specify any valid HTML img attributes, such as `width` or `title`\n\n**Examples**\n\n~~~\n{% image src: '2014/placeholder_190x105.jpg', class: 'right', title: \"Some title\" %}\n~~~\nImage in the media directory, with a specified class and title\n\n~~~\n{% image src: '2014/placeholder_190x105.jpg', class: right, protected: true %}\n~~~\nImage is in the protected asset folder\n\n~~~\n{% image src: '2014/placeholder_190x105.jpg', version: 'thumb', alt: \"Some title\" %}\n~~~\nUse the `thumb` version of the image\n\n" } end |
Instance Method Details
#render(context) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dm_cms/liquid/tags/image.rb', line 15 def render(context) if @attributes['version'] #--- pull from MediaFile object src = MediaFile.url_by_name(@attributes['src'], version: @attributes['version']) @attributes.delete('version') else #--- handle like regular url src = file_url(@attributes['src'], account_site_assets: context_account_site_assets(context), default_folder: 'media', protected: @attributes['protected'].as_boolean) end @attributes.delete('src') image_tag(src, @attributes) end |