jekyll-locale 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +3 -0
- data/lib/jekyll/locale/drop.rb +10 -0
- data/lib/jekyll/locale/handler.rb +42 -0
- data/lib/jekyll/locale/version.rb +7 -0
- data/lib/jekyll/patches/site.rb +15 -0
- data/lib/jekyll/patches/utils.rb +76 -0
- data/lib/jekyll-locale.rb +15 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 73cdeebfabff92747661cda740330d4fadb99139
|
4
|
+
data.tar.gz: 6bb5b58bdb7420b41ea12c5b2d3f5f6267e93623
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1182409d6e2c03b9aec4a8af42fbe9ccffbc72b956df482931e47ee3d6ba534b5e9055025cb8201a3709f00cd849aa2886b22122789aff6f2b2af97a8d1fc35
|
7
|
+
data.tar.gz: ba66142dc23a732e769a10085cdcf0135a4d33d485fe61d5f90788a5ab541cb2dab8491443865ab9e66a9179e1b19a3e0a55ebe65d335eb24a008a7073fdbff9
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Ashwin Maroli
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Locale::Handler
|
5
|
+
def initialize(site)
|
6
|
+
@site = site
|
7
|
+
@config = site.config
|
8
|
+
end
|
9
|
+
|
10
|
+
def reset
|
11
|
+
@data = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def data
|
15
|
+
@data ||= begin
|
16
|
+
fallback = site.site_data.dig(locales_dir, locale)
|
17
|
+
return {} unless fallback.is_a?(Hash)
|
18
|
+
|
19
|
+
# transform hash to one with "latinized lowercased string keys"
|
20
|
+
Jekyll::Utils.snake_case_keys(fallback)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :site, :config
|
27
|
+
|
28
|
+
def locales_dir
|
29
|
+
@locales_dir ||= begin
|
30
|
+
value = config["locales_dir"]
|
31
|
+
value.to_s.empty? ? "locales" : value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def locale
|
36
|
+
@locale ||= begin
|
37
|
+
value = config["locale"]
|
38
|
+
value.to_s.empty? ? "en" : value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Drops::UnifiedPayloadDrop
|
5
|
+
def locale
|
6
|
+
@locale ||= Jekyll::Locale::Drop.new(@obj.locale_handler)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Site
|
11
|
+
def locale_handler
|
12
|
+
@locale_handler ||= Jekyll::Locale::Handler.new(self)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Utils
|
5
|
+
extend self
|
6
|
+
|
7
|
+
# Convert all keys to snake_case by substituting non-alphanumeric characters
|
8
|
+
# with an underscore.
|
9
|
+
# The keys are first converted to lowercase strings and then any letters with accents
|
10
|
+
# are replaced with their plaintext counterpart
|
11
|
+
#
|
12
|
+
# hash - the hash to which to apply this transformation
|
13
|
+
#
|
14
|
+
# Returns a new hash with snake_cased keys or a hash with stringified keys.
|
15
|
+
def snake_case_keys(hash)
|
16
|
+
transform_keys(hash) do |key|
|
17
|
+
begin
|
18
|
+
Utils.slugify(key.to_s, :mode => "latin", :replacement => "_")
|
19
|
+
rescue StandardError
|
20
|
+
key.to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def slugify(string, mode: nil, cased: false, replacement: "-")
|
26
|
+
mode ||= "default"
|
27
|
+
return nil if string.nil?
|
28
|
+
|
29
|
+
unless SLUGIFY_MODES.include?(mode)
|
30
|
+
return cased ? string : string.downcase
|
31
|
+
end
|
32
|
+
|
33
|
+
# Drop accent marks from latin characters. Everything else turns to ?
|
34
|
+
if mode == "latin"
|
35
|
+
I18n.config.available_locales = :en if I18n.config.available_locales.empty?
|
36
|
+
string = I18n.transliterate(string)
|
37
|
+
end
|
38
|
+
|
39
|
+
slug = replace_character_sequence(string, :mode => mode, :replacement => replacement)
|
40
|
+
|
41
|
+
# Remove leading/trailing hyphen
|
42
|
+
slug.gsub!(%r!^\-|\-$!i, "")
|
43
|
+
|
44
|
+
slug.downcase! unless cased
|
45
|
+
slug
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Replace each character sequence with a hyphen.
|
51
|
+
#
|
52
|
+
# See Utils#slugify for a description of the character sequence specified
|
53
|
+
# by each mode.
|
54
|
+
def replace_character_sequence(string, **opts)
|
55
|
+
replaceable_char =
|
56
|
+
case opts[:mode]
|
57
|
+
when "raw"
|
58
|
+
SLUGIFY_RAW_REGEXP
|
59
|
+
when "pretty"
|
60
|
+
# "._~!$&'()+,;=@" is human readable (not URI-escaped) in URL
|
61
|
+
# and is allowed in both extN and NTFS.
|
62
|
+
SLUGIFY_PRETTY_REGEXP
|
63
|
+
when "ascii"
|
64
|
+
# For web servers not being able to handle Unicode, the safe
|
65
|
+
# method is to ditch anything else but latin letters and numeric
|
66
|
+
# digits.
|
67
|
+
SLUGIFY_ASCII_REGEXP
|
68
|
+
else
|
69
|
+
SLUGIFY_DEFAULT_REGEXP
|
70
|
+
end
|
71
|
+
|
72
|
+
# Strip according to the mode
|
73
|
+
string.gsub(replaceable_char, opts[:replacement])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Locale
|
5
|
+
autoload :Drop, "jekyll/locale/drop"
|
6
|
+
autoload :Handler, "jekyll/locale/handler"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require_relative "jekyll/patches/site"
|
11
|
+
require_relative "jekyll/patches/utils"
|
12
|
+
|
13
|
+
Jekyll::Hooks.register :site, :after_reset do |site|
|
14
|
+
site.locale_handler.reset
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-locale
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ashwin Maroli
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.8'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- ashmaroli@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE.txt
|
35
|
+
- README.md
|
36
|
+
- lib/jekyll-locale.rb
|
37
|
+
- lib/jekyll/locale/drop.rb
|
38
|
+
- lib/jekyll/locale/handler.rb
|
39
|
+
- lib/jekyll/locale/version.rb
|
40
|
+
- lib/jekyll/patches/site.rb
|
41
|
+
- lib/jekyll/patches/utils.rb
|
42
|
+
homepage: https://github.com/ashmaroli/jekyll-locale
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata:
|
46
|
+
allowed_push_host: https://rubygems.org
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.3.0
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.6.14
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: A localization plugin for Jekyll
|
67
|
+
test_files: []
|