jekyll-kw-shorten 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3874189518634abb2c6a33ffe63226ab96438007b688e9853163ffc1c2c8d4fc
4
+ data.tar.gz: 61d26e48aa0fc93b65745a52581c35d13629caa71e62dbc67abd4b0dc589cb43
5
+ SHA512:
6
+ metadata.gz: 3d6d12b048d8a49e6b8e3fce09a11433f18a158ad3568dfd2c0aa1c419d18da314ea52f482ae8d2194024371a4ecbe281fde0c6695adaf4d4247626d119d013e
7
+ data.tar.gz: ae5cd4ec1964c8d6268751ffde40cdda8bf33433dc10e1683ada9ed4db3e77f678c7833d9297d5022902f307c7fa18105eeaf1f014b246a29c313138a52b0d72
@@ -0,0 +1,27 @@
1
+
2
+ The project `jekyll-kw-shorten` is a **[filter](https://jekyllrb.com/docs/plugins/filters/)** plug-in for a [jekyll](https://jekyllrb.com/) static page blog.
3
+
4
+ It is published on [rubygems.org](https://rubygems.org/gems/jekyll-kw-shorten), the source code is hosted on [GitHub](https://github.com/n13org/jekyll-kw-shorten).
5
+
6
+ ## Usage
7
+
8
+ * {{ "txt" | shorten }}
9
+ * {{ "text with spaces" | shorten }}
10
+ * {{ 500 | shorten }}
11
+ * {{ 777 | shorten }}
12
+ * {{ 1000 | shorten }}
13
+ * {{ 1200 | shorten }}
14
+ * {{ 1450 | shorten }}
15
+ * {{ 1777 | shorten }}
16
+ * {{ 12345 | shorten }}
17
+ * {{ 1000000 | shorten }}
18
+ * {{ 1110000 | shorten }}
19
+ * {{ 1000000000 | shorten }}
20
+
21
+ ## Installation
22
+
23
+ ## Configuration
24
+
25
+ ## Contribution
26
+
27
+ ## Test locally
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module KargWare
5
+ module Shorten
6
+ # Shorten configuration class
7
+ class Configuration
8
+ attr_accessor :shorten_gt3_digit, :shorten_gt6_digit, :shorten_gt9_digit
9
+
10
+ DEFAULT_CONFIG = {
11
+ 'shorten_gt3_digit' => ' K',
12
+ 'shorten_gt6_digit' => ' M',
13
+ 'shorten_gt9_digit' => ' B'
14
+ }.freeze
15
+
16
+ def initialize(options)
17
+ options = generate_option_hash(options)
18
+
19
+ @shorten_gt3_digit = options['shorten_gt3_digit']
20
+ @shorten_gt6_digit = options['shorten_gt6_digit']
21
+ @shorten_gt9_digit = options['shorten_gt9_digit']
22
+ end
23
+
24
+ private
25
+
26
+ def generate_option_hash(options)
27
+ DEFAULT_CONFIG.merge(options)
28
+ rescue TypeError
29
+ DEFAULT_CONFIG
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module KargWare
5
+ module Shorten
6
+ # jekyll-kw-shorten parser class
7
+ class Parser
8
+ attr_reader :configuration
9
+
10
+ def initialize(options = {})
11
+ @configuration = Configuration.new(options)
12
+ end
13
+
14
+ def shorten(text)
15
+ if text.is_a? String then
16
+ return text
17
+ else
18
+ num = text.to_i
19
+ if num >= 1000000000000 then
20
+ return "∞ 🚀"
21
+ elsif num >= 1000000000 then
22
+ return (num / 1000000000.0).truncate(1).to_s + @configuration.shorten_gt9_digit
23
+ elsif num >= 1000000 then
24
+ return (num / 1000000.0).truncate(1).to_s + @configuration.shorten_gt6_digit
25
+ elsif num >= 1000 then
26
+ return (num / 1000.0).truncate(1).to_s + @configuration.shorten_gt3_digit
27
+ else
28
+ return (num).truncate(1).to_s
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module KargWare
5
+ module Shorten
6
+ RUBYGEM_NAME = 'jekyll-kw-shorten'
7
+ VERSION = '0.0.1'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module KargWare
5
+ module Shorten
6
+ class Error < StandardError; end
7
+ class Exception < Gem::Exception; end
8
+
9
+ # shorten tag {% shorten input %} for Jekyll
10
+ class ShortenTag < Liquid::Tag
11
+ def initialize(tag_name, input, tokens)
12
+ super
13
+ @input = input
14
+ end
15
+
16
+ def render(context)
17
+ filter = ShortenFilter.new
18
+ filter.shorten(@input)
19
+ end
20
+ end
21
+
22
+ # shorten filter {{ number | shorten }} for Jekyll
23
+ module ShortenFilter
24
+ def shorten(number)
25
+ parser = Jekyll::KargWare::Shorten::Parser.new(get_site_config)
26
+ parser.shorten(number)
27
+ end
28
+
29
+ private
30
+
31
+ def get_site_config
32
+ @context.registers[:site].config['jekyll-kw-shorten'] || {}
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+
40
+ Liquid::Template.register_tag('shorten', Jekyll::KargWare::Shorten::ShortenTag)
41
+ Liquid::Template.register_filter(Jekyll::KargWare::Shorten::ShortenFilter)
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-kw-shorten
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Karg
8
+ - n13.org - Open-Source by KargWare
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-12-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jekyll
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '3.8'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '3.8'
28
+ description: " A template project for jekyll plugins with some additional content\n"
29
+ email:
30
+ - rubygems.org@n13.org
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - lib/jekyll/KargWare/Shorten/configuration.rb
37
+ - lib/jekyll/KargWare/Shorten/parser.rb
38
+ - lib/jekyll/KargWare/Shorten/version.rb
39
+ - lib/jekyll/KargWare/shorten.rb
40
+ homepage: https://notes.n13.org/rubygems
41
+ licenses: []
42
+ metadata:
43
+ homepage_uri: https://notes.n13.org/rubygems
44
+ bug_tracker_uri: https://github.com/n13org/jekyll-plugin-template/issues
45
+ source_code_uri: https://github.com/n13org/jekyll-plugin-template
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.1.2
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A template project for jekyll plugins.
65
+ test_files: []