jekyll-kw-shorten 0.0.10 → 0.0.11
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e593496e1b6a803fc2ccad35c0e477fefe1fb7fa1f9d5ae4431a84a9c99395f
|
4
|
+
data.tar.gz: 27ad67e6058c04547fc482d58e9b12bf9f06685ce01ff966b5e7fd7302348801
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf3e5f9f35fad937a511661d3a6ab694046dc8fe178e84a234c195e46766d3291d2438c0990cba4b534d129d87d951865d4cb8903fe9009b9263cf664a217bf0
|
7
|
+
data.tar.gz: ece39f6384277d0f5f32fc6c32a79c3903099343cf4d0cea6682fae432814240dffdfe3817852e0339dc4d17db2019a8f400306e2582c415d8de4b63691bc933
|
data/lib/jekyll-kw-shorten.rb
CHANGED
@@ -5,67 +5,46 @@ require 'jekyll/KargWare/Shorten/version'
|
|
5
5
|
|
6
6
|
module Jekyll
|
7
7
|
module KargWare
|
8
|
+
# jekyll-kw-shorten jekyll (tag and filter) class
|
8
9
|
module Shorten
|
9
10
|
class Error < StandardError; end
|
10
11
|
class Exception < Gem::Exception; end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
name.split("::").last.downcase
|
18
|
-
end
|
13
|
+
module_function def get_plugin_config(context)
|
14
|
+
if defined? context.registers[:site].config
|
15
|
+
context.registers[:site].config[Jekyll::KargWare::Shorten::RUBYGEM_NAME] || {}
|
16
|
+
else
|
17
|
+
{}
|
19
18
|
end
|
19
|
+
end
|
20
20
|
|
21
|
+
# shorten tag {% shorten input %} for Jekyll
|
22
|
+
class ShortenTag < Liquid::Tag
|
21
23
|
def initialize(tag_name, input, tokens)
|
22
24
|
super
|
23
25
|
@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
|
29
26
|
end
|
30
27
|
|
31
28
|
def render(context)
|
32
|
-
parser = Jekyll::KargWare::Shorten::Parser.new(
|
33
|
-
|
29
|
+
parser = Jekyll::KargWare::Shorten::Parser.new(
|
30
|
+
Jekyll::KargWare::Shorten.get_plugin_config(context)
|
31
|
+
)
|
34
32
|
parser.parse(@input)
|
35
33
|
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
|
45
|
-
end
|
46
34
|
end
|
47
35
|
|
48
36
|
# shorten filter {{ number | shorten }} for Jekyll
|
49
37
|
module ShortenFilter
|
50
38
|
def shorten(number)
|
51
|
-
parser = Jekyll::KargWare::Shorten::Parser.new(
|
39
|
+
parser = Jekyll::KargWare::Shorten::Parser.new(
|
40
|
+
Jekyll::KargWare::Shorten.get_plugin_config(@context)
|
41
|
+
)
|
52
42
|
parser.parse(number)
|
53
43
|
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
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
|
63
|
-
end
|
64
44
|
end
|
65
|
-
|
66
45
|
end
|
67
46
|
end
|
68
47
|
end
|
69
48
|
|
70
49
|
Liquid::Template.register_tag('shorten', Jekyll::KargWare::Shorten::ShortenTag)
|
71
|
-
Liquid::Template.register_filter(Jekyll::KargWare::Shorten::ShortenFilter)
|
50
|
+
Liquid::Template.register_filter(Jekyll::KargWare::Shorten::ShortenFilter)
|
@@ -14,21 +14,24 @@ module Jekyll
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def parse(text)
|
17
|
-
|
17
|
+
return text unless Parser.number?(text)
|
18
|
+
|
19
|
+
begin
|
18
20
|
num = text.to_f
|
19
|
-
if num >= 1000000000000
|
20
|
-
|
21
|
-
elsif num >= 1000000000
|
22
|
-
|
23
|
-
elsif num >= 1000000
|
24
|
-
|
25
|
-
elsif num >= 1000
|
26
|
-
|
21
|
+
if num >= 1000000000000
|
22
|
+
'∞ 🚀'
|
23
|
+
elsif num >= 1000000000
|
24
|
+
format(num / 1000000000.0) + @configuration.shorten_gt9_digit
|
25
|
+
elsif num >= 1000000
|
26
|
+
format(num / 1000000.0) + @configuration.shorten_gt6_digit
|
27
|
+
elsif num >= 1000
|
28
|
+
format(num / 1000.0) + @configuration.shorten_gt3_digit
|
27
29
|
else
|
28
|
-
|
30
|
+
num.round(0).truncate(0).to_s.rjust(5)
|
29
31
|
end
|
30
|
-
|
31
|
-
|
32
|
+
rescue StandardError => e
|
33
|
+
puts e.message
|
34
|
+
text
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
@@ -38,10 +41,11 @@ module Jekyll
|
|
38
41
|
num.round(1).truncate(1).to_s
|
39
42
|
end
|
40
43
|
|
41
|
-
def self.
|
42
|
-
true if Float(string)
|
44
|
+
def self.number?(string)
|
45
|
+
true if Float(string)
|
46
|
+
rescue StandardError
|
47
|
+
false
|
43
48
|
end
|
44
|
-
|
45
49
|
end
|
46
50
|
end
|
47
51
|
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.11
|
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:
|
12
|
+
date: 2021-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|