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 +4 -4
- data/lib/jekyll-kw-shorten.rb +35 -7
- data/lib/jekyll/KargWare/Shorten/parser.rb +19 -9
- data/lib/jekyll/KargWare/Shorten/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68f63c1abffd9e7cadb9ce48e2b926f612b4e6ec7a40d964a9a7660631cff5fb
|
4
|
+
data.tar.gz: 319d0ba44d6f0ae50589ad2df7db45ca9798bab80db52a225bc29ba32318d967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5bd7d988b75d828a50c5733e2e843e662c58c18a3dd009c61955926c53f62fe5216fbdded3642b12d2f9648dea238392665b773e5b32e6e1002b0e86d6ee91e
|
7
|
+
data.tar.gz: 38b05260c97dda5f6e1c531cf87e815c8890d880b1a83f3edfc36d9842121a981add98eb36ac7f57863b427a1b0f975dfba4bdca9db49cbccc0fbbc7334af69f
|
data/lib/jekyll-kw-shorten.rb
CHANGED
@@ -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
|
-
|
20
|
-
|
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(
|
28
|
-
parser.
|
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
|
34
|
-
@context.registers[:site].config
|
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
|
17
|
-
if
|
18
|
-
|
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)
|
22
|
+
return format(num / 1000000000.0) + @configuration.shorten_gt9_digit
|
25
23
|
elsif num >= 1000000 then
|
26
|
-
return (num / 1000000.0)
|
24
|
+
return format(num / 1000000.0) + @configuration.shorten_gt6_digit
|
27
25
|
elsif num >= 1000 then
|
28
|
-
return (num / 1000.0)
|
26
|
+
return format(num / 1000.0) + @configuration.shorten_gt3_digit
|
29
27
|
else
|
30
|
-
return (
|
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
|
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.
|
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-
|
12
|
+
date: 2020-12-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|