jekyll-kw-shorten 0.0.10 → 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: 68f63c1abffd9e7cadb9ce48e2b926f612b4e6ec7a40d964a9a7660631cff5fb
4
- data.tar.gz: 319d0ba44d6f0ae50589ad2df7db45ca9798bab80db52a225bc29ba32318d967
3
+ metadata.gz: 3e593496e1b6a803fc2ccad35c0e477fefe1fb7fa1f9d5ae4431a84a9c99395f
4
+ data.tar.gz: 27ad67e6058c04547fc482d58e9b12bf9f06685ce01ff966b5e7fd7302348801
5
5
  SHA512:
6
- metadata.gz: a5bd7d988b75d828a50c5733e2e843e662c58c18a3dd009c61955926c53f62fe5216fbdded3642b12d2f9648dea238392665b773e5b32e6e1002b0e86d6ee91e
7
- data.tar.gz: 38b05260c97dda5f6e1c531cf87e815c8890d880b1a83f3edfc36d9842121a981add98eb36ac7f57863b427a1b0f975dfba4bdca9db49cbccc0fbbc7334af69f
6
+ metadata.gz: cf3e5f9f35fad937a511661d3a6ab694046dc8fe178e84a234c195e46766d3291d2438c0990cba4b534d129d87d951865d4cb8903fe9009b9263cf664a217bf0
7
+ data.tar.gz: ece39f6384277d0f5f32fc6c32a79c3903099343cf4d0cea6682fae432814240dffdfe3817852e0339dc4d17db2019a8f400306e2582c415d8de4b63691bc933
@@ -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
- # shorten tag {% shorten input %} for Jekyll
13
- class ShortenTag < Liquid::Tag
14
-
15
- class << self
16
- def tag_name
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(get_plugin_config(context))
33
- # parser = Jekyll::KargWare::Shorten::Parser.new({})
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(get_plugin_config)
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)
@@ -21,9 +21,7 @@ module Jekyll
21
21
  @shorten_gt9_digit = options['shorten_gt9_digit']
22
22
  end
23
23
 
24
- private
25
-
26
- def generate_option_hash(options)
24
+ private def generate_option_hash(options)
27
25
  DEFAULT_CONFIG.merge(options)
28
26
  rescue TypeError
29
27
  DEFAULT_CONFIG
@@ -14,21 +14,24 @@ module Jekyll
14
14
  end
15
15
 
16
16
  def parse(text)
17
- if Parser.is_number?(text) then
17
+ return text unless Parser.number?(text)
18
+
19
+ begin
18
20
  num = text.to_f
19
- if num >= 1000000000000 then
20
- return "∞ 🚀"
21
- elsif num >= 1000000000 then
22
- return format(num / 1000000000.0) + @configuration.shorten_gt9_digit
23
- elsif num >= 1000000 then
24
- return format(num / 1000000.0) + @configuration.shorten_gt6_digit
25
- elsif num >= 1000 then
26
- return format(num / 1000.0) + @configuration.shorten_gt3_digit
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
- return num.round(0).truncate(0).to_s.rjust(5)
30
+ num.round(0).truncate(0).to_s.rjust(5)
29
31
  end
30
- else
31
- return text
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.is_number? string
42
- true if Float(string) rescue false
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
@@ -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.10'
7
+ VERSION = '0.0.11'
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.10
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: 2020-12-28 00:00:00.000000000 Z
12
+ date: 2021-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll