jekyll-kw-shorten 0.0.6 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,42 +1,50 @@
|
|
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
|
8
|
+
# jekyll-kw-shorten jekyll (tag and filter) class
|
7
9
|
module Shorten
|
8
10
|
class Error < StandardError; end
|
9
11
|
class Exception < Gem::Exception; end
|
10
12
|
|
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
|
+
{}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
# shorten tag {% shorten input %} for Jekyll
|
12
22
|
class ShortenTag < Liquid::Tag
|
13
23
|
def initialize(tag_name, input, tokens)
|
14
24
|
super
|
15
|
-
@input = input
|
25
|
+
@input = input.to_s.strip
|
16
26
|
end
|
17
27
|
|
18
28
|
def render(context)
|
19
|
-
|
29
|
+
parser = Jekyll::KargWare::Shorten::Parser.new(
|
30
|
+
Jekyll::KargWare::Shorten.get_plugin_config(context)
|
31
|
+
)
|
32
|
+
parser.parse(@input)
|
20
33
|
end
|
21
34
|
end
|
22
35
|
|
23
36
|
# shorten filter {{ number | shorten }} for Jekyll
|
24
37
|
module ShortenFilter
|
25
38
|
def shorten(number)
|
26
|
-
parser = Jekyll::KargWare::Shorten::Parser.new(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def get_site_config
|
33
|
-
@context.registers[:site].config['jekyll-kw-shorten'] || {}
|
39
|
+
parser = Jekyll::KargWare::Shorten::Parser.new(
|
40
|
+
Jekyll::KargWare::Shorten.get_plugin_config(@context)
|
41
|
+
)
|
42
|
+
parser.parse(number)
|
34
43
|
end
|
35
44
|
end
|
36
|
-
|
37
45
|
end
|
38
46
|
end
|
39
47
|
end
|
40
48
|
|
41
49
|
Liquid::Template.register_tag('shorten', Jekyll::KargWare::Shorten::ShortenTag)
|
42
|
-
Liquid::Template.register_filter(Jekyll::KargWare::Shorten::ShortenFilter)
|
50
|
+
Liquid::Template.register_filter(Jekyll::KargWare::Shorten::ShortenFilter)
|
@@ -13,25 +13,39 @@ module Jekyll
|
|
13
13
|
@configuration = Jekyll::KargWare::Shorten::Configuration.new(options)
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
num = text.
|
21
|
-
if num >= 1000000000000
|
22
|
-
|
23
|
-
elsif num >= 1000000000
|
24
|
-
|
25
|
-
elsif num >= 1000000
|
26
|
-
|
27
|
-
elsif num >= 1000
|
28
|
-
|
16
|
+
def parse(text)
|
17
|
+
return text unless Parser.number?(text)
|
18
|
+
|
19
|
+
begin
|
20
|
+
num = text.to_f
|
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
|
29
29
|
else
|
30
|
-
|
30
|
+
num.round(0).truncate(0).to_s.rjust(5)
|
31
31
|
end
|
32
|
+
rescue StandardError => e
|
33
|
+
puts e.message
|
34
|
+
text
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
38
|
+
# private
|
39
|
+
|
40
|
+
def format(num)
|
41
|
+
num.round(1).truncate(1).to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.number?(string)
|
45
|
+
true if Float(string)
|
46
|
+
rescue StandardError
|
47
|
+
false
|
48
|
+
end
|
35
49
|
end
|
36
50
|
end
|
37
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
|