jekyll-aspect-ratio 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-aspect-ratio.rb +21 -8
  3. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '058a9c7412bba98f8aeea49537c2df702f44d8420d10c6a49953ba4557a6dc6f'
4
- data.tar.gz: b573af089a4a2e3fd23fbb08d44dcf5b5cd7f56369e7e349af2bef5542f32b58
3
+ metadata.gz: fd37b32b0b923b0c43e4fdc08a9496743d449898162d6c763c24268f3e720e01
4
+ data.tar.gz: 42fae0e5c906dfe525a6710a926fee8b9f751df7cd8e86a8636902aa23c42174
5
5
  SHA512:
6
- metadata.gz: cba3c22da811c376dbfc6b8648889c2f3cd56f85fe12108f53a219455d3d13e97e8982fb383f75f16d2cb4d1b26854404b1ba26ac73fafa824b231ef89b36c97
7
- data.tar.gz: 64c586c4d3e58ac7e98da9ef1bd06ac5f2a854eedc78f5e84f421a996184f211d04aea67812483f7e487c6b03415659a01260909f6bd5010d1b5366eb2f57ff4
6
+ metadata.gz: 03d2c8c683e19481c6a2238eae8c92ffbde451477b1f2ecc670c47f25d3820d2e324dca6bd35f23c7f42eb6e05641661b8435e5d35adb66f7e554d247858c8b2
7
+ data.tar.gz: ad954441f040a353146e6b6e6d1d578c1e8d34992f3b09b813b1ecfe52b1d01de91f0f16393aae9786a0d66d298a15a5312744dcc3c4423d5642642edc22dcfe
@@ -3,34 +3,47 @@ require 'mini_exiftool'
3
3
 
4
4
  class AspectRatio < Liquid::Tag
5
5
 
6
- def initialize(tagName, input, tokens)
6
+ def initialize(tagName, content, tokens)
7
7
  super
8
- @input = input
8
+ @input = content
9
9
  end
10
10
 
11
11
  def render(context)
12
- filepath = context[@input]
13
- # Strip off the first '/', as that confuses things with relative filepaths
12
+ # If this is a parameter name (from {% assign x = "path" %})
13
+ # then we need to pass that in as a key to context to get its value
14
+ if context.key?(@input)
15
+ filepath = context[@input]
16
+ else
17
+ filepath = @input
18
+ end
19
+
20
+ # Strip leading spaces and quotes
21
+ filepath = filepath.strip.tr('"', '').tr('\'', '')
22
+
23
+ # Strip off the first '/', if there is one
24
+ # as that confuses things with relative filepaths
14
25
  if filepath[0] == "/"
15
26
  filepath = filepath[1..-1]
16
27
  end
28
+
29
+ # MiniExfitool doesn't like relative paths
17
30
  abspath = File.expand_path(filepath)
18
- output = 0
19
31
 
20
32
  if (File.file?(abspath))
21
33
  mediaObj = MiniExiftool.new abspath
22
34
  height = mediaObj.image_height
23
35
  width = mediaObj.image_width
24
36
 
25
- # TODO is it always giving me the longer side as width? if so I could pass in a flag for if it's a horizontal or vertical video?
26
- if mediaObj.rotation == 90 or mediaObj.rotation == 180
37
+ # If the video is rotated, we need to swap width and height
38
+ if mediaObj.rotation == 90 or mediaObj.rotation == 270
27
39
  temp = height
28
40
  height = width
29
41
  width = temp
30
42
  end
31
43
 
44
+ # Avoid division by zero errors
32
45
  if height != 0
33
- output = width.to_f/height.to_f
46
+ output = (width.to_f/height.to_f).truncate(2)
34
47
  end
35
48
  end
36
49
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-aspect-ratio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Crane
@@ -10,12 +10,13 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-05-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: "Jekyll-Aspect-Ratio enables the use of a custom Liquid tag {% aspectratio
14
- filepath %}, to find the aspect ratio of an image or video file. \n\nExample use
15
- cases:\n- Specify the flex-grow value of an item so that a series of items of different
16
- aspect ratios can fill up one row, all being the same height\n- Sort or separate
17
- items by aspect ratio, to display horizontal vs vertical videos together (aspect
18
- ratio < 1 is a portrait item, >1 is landscape)\n"
13
+ description: 'This plugin enables the use of a custom Liquid tag {% aspectratio filepath
14
+ %}, to find the aspect ratio of an image or video file. This can be used for e.g.
15
+ specifying the flex-grow value of an item to display items of different aspect ratios
16
+ on one line at the same height, or to separate out horizontal or vertical videos
17
+ (aspect ratio > or < than 1).
18
+
19
+ '
19
20
  email: hello@bethcrane.com
20
21
  executables: []
21
22
  extensions: []