jekyll-language-plugin 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c4a3dc1639cfb176ca59888045e1019021aa0f3f
4
+ data.tar.gz: b514c635ef7f5aaf570505b664e7caeeb6daed36
5
+ SHA512:
6
+ metadata.gz: d8da51a1a09a018483e9221544fb6756cec1fc30cb4ed797135d1c7a60537c43e32e3e3cfbc6a37736da0446d9c16aa86c0c4842e0c9fdabcd9213913303bbd1
7
+ data.tar.gz: dc4ce2e7042c712c533713ecc37896cb5679e14628b67ad90dd408f0d0b236d3b8d40b414b2bf7b3aa473b5a6163437ba6208171c933c903172e921a5cd5cb2e
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 GitHub, inc.
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # jekyll-language-plugin
2
+ Jekyll 3.0-compatible multi-language plugin for posts, pages and includes
@@ -0,0 +1,7 @@
1
+ # require all files in jekyll subdirectory
2
+ require 'jekyll-language-plugin/language_page.rb'
3
+ require 'jekyll-language-plugin/language_document.rb'
4
+ require 'jekyll-language-plugin/readers/page_reader.rb'
5
+ require 'jekyll-language-plugin/readers/post_reader.rb'
6
+ require 'jekyll-language-plugin/tags/language.rb'
7
+ require 'jekyll-language-plugin/tags/language_include.rb'
@@ -0,0 +1,29 @@
1
+ module Jekyll
2
+ class LanguageDocument < Document
3
+ alias_method :url_template_orig, :url_template
4
+ alias_method :url_placeholders_orig, :url_placeholders
5
+
6
+ def language
7
+ return nil if data.nil? || data['language'].nil?
8
+ data['language']
9
+ end
10
+
11
+ def languages
12
+ return nil if data.nil? || data['languages'].nil?
13
+ data['languages']
14
+ end
15
+
16
+ def url_template
17
+ if language
18
+ return "/:language" + url_template_orig
19
+ end
20
+ url_template_orig
21
+ end
22
+
23
+ def url_placeholders
24
+ p = url_placeholders_orig
25
+ p['language'] = language
26
+ p
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Jekyll
2
+ class LanguagePage < Page
3
+ alias_method :template_orig, :template
4
+ alias_method :url_placeholders_orig, :url_placeholders
5
+
6
+ def language
7
+ return nil if data.nil? || data['language'].nil?
8
+ data['language']
9
+ end
10
+
11
+ def languages
12
+ return nil if data.nil? || data['languages'].nil?
13
+ data['languages']
14
+ end
15
+
16
+ def template
17
+ if language
18
+ return "/:language" + template_orig
19
+ end
20
+ template_orig
21
+ end
22
+
23
+ def url_placeholders
24
+ p = url_placeholders_orig
25
+ p['language'] = language
26
+ p
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ module Jekyll
2
+ class PageReader
3
+ def read(files)
4
+ for file in files do
5
+ page = LanguagePage.new(@site, @site.source, @dir, file)
6
+ if page.languages
7
+ for language in page.languages do
8
+ if page.language == language
9
+ @unfiltered_content << page
10
+ elsif page.language.nil?
11
+ page.data['language'] = language
12
+ @unfiltered_content << page
13
+ else
14
+ page2 = LanguagePage.new(@site, @site.source, @dir, file)
15
+ page2.data['language'] = language
16
+ @unfiltered_content << page2
17
+ end
18
+ end
19
+ else
20
+ @unfiltered_content << page
21
+ end
22
+ end
23
+ @unfiltered_content.select{ |page| site.publisher.publish?(page) }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ module Jekyll
2
+ class PostReader
3
+ def read_content(dir, magic_dir, matcher)
4
+ entries = @site.reader.get_entries(dir, magic_dir)
5
+ documents = []
6
+ for entry in entries
7
+ next unless entry =~ matcher
8
+ path = @site.in_source_dir(File.join(dir, magic_dir, entry))
9
+ documents.concat(multilinguify(path))
10
+ end
11
+ documents
12
+ end
13
+
14
+ def multilinguify(path)
15
+ document = create_document_from_path(path)
16
+ document.read
17
+ if not document.language and not document.languages
18
+ # create a new document that can be freshly read
19
+ return [create_document_from_path(path)]
20
+ end
21
+
22
+ languages = document.languages || []
23
+ if document.language and not languages.include?(document.language)
24
+ languages.push(document.language)
25
+ end
26
+
27
+ languages.map do |language|
28
+ document2 = create_document_from_path(path)
29
+ document2.data['language'] = language
30
+ document2
31
+ end
32
+ end
33
+
34
+ def create_document_from_path(path)
35
+ LanguageDocument.new(path, {
36
+ site: @site,
37
+ collection: @site.posts
38
+ })
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ module Jekyll
2
+ module Tags
3
+ class LanguageTag < Liquid::Tag
4
+ def initialize(tag_name, markup, tokens)
5
+ super
6
+ @params = markup.gsub(/\s+/m, ' ').strip.split(" ")
7
+ @lkey = @params.shift
8
+ end
9
+
10
+ def get_language_data(context, language)
11
+ language_data = context['site']['language_data'].strip
12
+ traverse = language_data.gsub("%%", language).split('.')
13
+
14
+ data = context['site']
15
+ traverse.each { |t| data = data[t] }
16
+ data
17
+ end
18
+
19
+ def get_language_string(context, key)
20
+ page_language = context['page']['language']
21
+
22
+ if not page_language
23
+ return ""
24
+ end
25
+
26
+ page_alias = context['page']['alias']
27
+
28
+ data = get_language_data(context, page_language)
29
+ if page_alias and data.include?(page_alias) and data[page_alias].include?(key)
30
+ "#{data[page_alias][key]}"
31
+ elsif data.include?(key)
32
+ "#{data[key]}"
33
+ else
34
+ ""
35
+ end
36
+ end
37
+
38
+ def render(context)
39
+ str = get_language_string(context, @lkey)
40
+ @params.each { |p| str.sub!("%%", p) }
41
+ str
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ Liquid::Template.register_tag('t', Jekyll::Tags::LanguageTag)
@@ -0,0 +1,19 @@
1
+ module Jekyll
2
+ module Tags
3
+ class LanguageIncludeTag < IncludeTag
4
+ def tag_includes_dir(context)
5
+ context.registers[:site].config['language_includes_dir'].freeze
6
+ end
7
+
8
+ def page_language(context)
9
+ context.registers[:page].nil? ? "en" : context.registers[:page]["language"]
10
+ end
11
+
12
+ def resolved_includes_dir(context)
13
+ File.join(context.registers[:site].in_source_dir(@includes_dir), page_language(context))
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ Liquid::Template.register_tag('tinclude', Jekyll::Tags::LanguageIncludeTag)
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-language-plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vincent Wochnik
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-13 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.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ description: Jekyll 3.0-compatible multi-language plugin for posts, pages and includes
70
+ email:
71
+ - v.wochnik@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/jekyll-language-plugin.rb
77
+ - lib/jekyll-language-plugin/language_document.rb
78
+ - lib/jekyll-language-plugin/language_page.rb
79
+ - lib/jekyll-language-plugin/readers/page_reader.rb
80
+ - lib/jekyll-language-plugin/readers/post_reader.rb
81
+ - lib/jekyll-language-plugin/tags/language.rb
82
+ - lib/jekyll-language-plugin/tags/language_include.rb
83
+ - README.md
84
+ - LICENSE.md
85
+ homepage: https://github.com/vwochnik/jekyll-language-plugin
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.0.14
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: This plugin enables Jekyll to run multilingual websites where pages and posts
109
+ can automatically be translated into different languages.
110
+ test_files: []