jekyll-kw-shorten 0.0.5 → 0.0.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b301717cf83ddd281a7cc992c4e6e0bfbf219422eb1af0c2c31f0b6637b7387e
4
- data.tar.gz: 9ca3cce9db681a39b39bd4bc6b661657920d9c09d20ed3f21a19575437d1ea13
3
+ metadata.gz: 68f63c1abffd9e7cadb9ce48e2b926f612b4e6ec7a40d964a9a7660631cff5fb
4
+ data.tar.gz: 319d0ba44d6f0ae50589ad2df7db45ca9798bab80db52a225bc29ba32318d967
5
5
  SHA512:
6
- metadata.gz: 30ed8a3a94fed605f15732e0dd447ea86dcadbc8c019d15ac9beeebdfd21d1febfc028623e70ea0648d87a9b336d3165e901eef3d6ff505ec7041bda8ffcc449
7
- data.tar.gz: 7bc9b7d533e0bcb706a9e19e979dfbb2a72248ebac4c3ab0e879cccf10348c5a53eb7f9105107262029f0884f4802957a71affc55fcb62631343e6c9e020fde9
6
+ metadata.gz: a5bd7d988b75d828a50c5733e2e843e662c58c18a3dd009c61955926c53f62fe5216fbdded3642b12d2f9648dea238392665b773e5b32e6e1002b0e86d6ee91e
7
+ data.tar.gz: 38b05260c97dda5f6e1c531cf87e815c8890d880b1a83f3edfc36d9842121a981add98eb36ac7f57863b427a1b0f975dfba4bdca9db49cbccc0fbbc7334af69f
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'jekyll/KargWare/Shorten/parser'
4
+ require 'jekyll/KargWare/Shorten/version'
4
5
 
5
6
  module Jekyll
6
7
  module KargWare
@@ -10,28 +11,55 @@ module Jekyll
10
11
 
11
12
  # shorten tag {% shorten input %} for Jekyll
12
13
  class ShortenTag < Liquid::Tag
14
+
15
+ class << self
16
+ def tag_name
17
+ name.split("::").last.downcase
18
+ end
19
+ end
20
+
13
21
  def initialize(tag_name, input, tokens)
14
22
  super
15
- @input = input
23
+ @input = input.to_s.strip
24
+
25
+ # raise ArgumentError, <<~MSG
26
+ # Could not use '#{input}' in tag '#{self.class.tag_name}'.
27
+ # Make sure it is a string or a number.
28
+ # MSG
16
29
  end
17
30
 
18
31
  def render(context)
19
- filter = Jekyll::KargWare::Shorten::ShortenFilter.new
20
- filter.shorten(@input)
32
+ parser = Jekyll::KargWare::Shorten::Parser.new(get_plugin_config(context))
33
+ # parser = Jekyll::KargWare::Shorten::Parser.new({})
34
+ parser.parse(@input)
35
+ end
36
+
37
+ private
38
+
39
+ def get_plugin_config(context)
40
+ if defined? context.registers[:site].config
41
+ context.registers[:site].config[Jekyll::KargWare::Shorten::RUBYGEM_NAME] || {}
42
+ else
43
+ {}
44
+ end
21
45
  end
22
46
  end
23
47
 
24
48
  # shorten filter {{ number | shorten }} for Jekyll
25
49
  module ShortenFilter
26
50
  def shorten(number)
27
- parser = Jekyll::KargWare::Shorten::Parser.new(get_site_config)
28
- parser.shorten(number)
51
+ parser = Jekyll::KargWare::Shorten::Parser.new(get_plugin_config)
52
+ parser.parse(number)
29
53
  end
30
54
 
31
55
  private
32
56
 
33
- def get_site_config
34
- @context.registers[:site].config['jekyll-kw-shorten'] || {}
57
+ def get_plugin_config
58
+ if defined? @context.registers[:site].config
59
+ @context.registers[:site].config[Jekyll::KargWare::Shorten::RUBYGEM_NAME] || {}
60
+ else
61
+ {}
62
+ end
35
63
  end
36
64
  end
37
65
 
@@ -13,25 +13,35 @@ module Jekyll
13
13
  @configuration = Jekyll::KargWare::Shorten::Configuration.new(options)
14
14
  end
15
15
 
16
- def shorten(text)
17
- if text.is_a? String then
18
- return text
19
- else
20
- num = text.to_i
16
+ def parse(text)
17
+ if Parser.is_number?(text) then
18
+ num = text.to_f
21
19
  if num >= 1000000000000 then
22
20
  return "∞ 🚀"
23
21
  elsif num >= 1000000000 then
24
- return (num / 1000000000.0).truncate(1).to_s + @configuration.shorten_gt9_digit
22
+ return format(num / 1000000000.0) + @configuration.shorten_gt9_digit
25
23
  elsif num >= 1000000 then
26
- return (num / 1000000.0).truncate(1).to_s + @configuration.shorten_gt6_digit
24
+ return format(num / 1000000.0) + @configuration.shorten_gt6_digit
27
25
  elsif num >= 1000 then
28
- return (num / 1000.0).truncate(1).to_s + @configuration.shorten_gt3_digit
26
+ return format(num / 1000.0) + @configuration.shorten_gt3_digit
29
27
  else
30
- return (num).truncate(1).to_s
28
+ return num.round(0).truncate(0).to_s.rjust(5)
31
29
  end
30
+ else
31
+ return text
32
32
  end
33
33
  end
34
34
 
35
+ # private
36
+
37
+ def format(num)
38
+ num.round(1).truncate(1).to_s
39
+ end
40
+
41
+ def self.is_number? string
42
+ true if Float(string) rescue false
43
+ end
44
+
35
45
  end
36
46
  end
37
47
  end
@@ -4,7 +4,7 @@ module Jekyll
4
4
  module KargWare
5
5
  module Shorten
6
6
  RUBYGEM_NAME = 'jekyll-kw-shorten'
7
- VERSION = '0.0.5'
7
+ VERSION = '0.0.10'
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-kw-shorten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Karg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-27 00:00:00.000000000 Z
12
+ date: 2020-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll