jekyll-language-plugin 1.0.1 → 1.0.2

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
  SHA1:
3
- metadata.gz: 1f7f81d9c518d3a746e3d3e2df8f113bbf32ecb0
4
- data.tar.gz: babaab48e38c83dd620960f2756234e55c372e59
3
+ metadata.gz: 18a4c1437ec41d016a655990c7dd40086db5eed3
4
+ data.tar.gz: 080a094139c5372c70dd659bd6e5bbae6ae5e9ed
5
5
  SHA512:
6
- metadata.gz: a315f32074df59365490a7a529b22a31c4cf129d1f5c3366d520459def13ef5c4e8be35ca3d74ca47a7683383913a1e3aa1122f859156a521c26d71b564ecb81
7
- data.tar.gz: 6a68495e25db78915703815362da6aae5981868d6b91255cae165c2a25ccfc23f509e1b3342c9660ab056457e8c8485be08cb49e840d8beff0dacbec71a1c544
6
+ metadata.gz: 01a89b8faf0b802df025daa1712b44f788eecad67029394e3cf76be8c91f3ae91df9f0c945d61a4141145eecb60d7739799fc5dce9ced3de50a27d65a47bd4bb
7
+ data.tar.gz: 6619b1f2f0fe8029b4c742a02ebedd1ebe4004a237746b9b75a562af2e077006a3ba9c7db61a2c62ed64e2cc30f4292e508e51642b8441a7f1c6d2a0706d1864
@@ -1,7 +1,13 @@
1
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'
2
+ require 'jekyll/language_reader.rb'
3
+ require 'jekyll/language_page.rb'
4
+ require 'jekyll/language_document.rb'
5
+ require 'jekyll/readers/language_page_reader.rb'
6
+ require 'jekyll/readers/language_post_reader.rb'
7
+ require 'jekyll/tags/language.rb'
8
+ require 'jekyll/tags/language_include.rb'
9
+
10
+ # replace Jekyll::Reader upon page reset with Jekyll::LanguageReader extension
11
+ Jekyll::Hooks.register :site, :after_reset do |site|
12
+ site.reader = Jekyll::LanguageReader.new(site)
13
+ end
@@ -0,0 +1,12 @@
1
+ module Jekyll
2
+ class LanguageReader < Reader
3
+ def retrieve_posts(dir)
4
+ site.posts.docs.concat(LanguagePostReader.new(site).read_posts(dir))
5
+ site.posts.docs.concat(LanguagePostReader.new(site).read_drafts(dir)) if site.show_drafts
6
+ end
7
+
8
+ def retrieve_pages(dir, dot_pages)
9
+ site.pages.concat(LanguagePageReader.new(site, dir).read(dot_pages))
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ module Jekyll
2
+ class LanguagePageReader < PageReader
3
+ alias_method :read_orig, :read
4
+
5
+ def read(files)
6
+ read_orig(files).flat_map do |page|
7
+ lpages = []
8
+ lpage = LanguagePage.new(@site, @site.source, page.dir, page.name)
9
+ if lpage.languages
10
+ for language in lpage.languages do
11
+ if lpage.language == language
12
+ lpages << lpage
13
+ elsif lpage.language.nil?
14
+ lpage.data['language'] = language
15
+ lpages << lpage
16
+ else
17
+ lpage2 = LanguagePage.new(@site, @site.source, page.dir, page.name)
18
+ lpage2.data['language'] = language
19
+ lpages << lpage2
20
+ end
21
+ end
22
+ elsif lpage.language
23
+ lpages << lpage
24
+ else
25
+ # no languages -> do not add extended Page
26
+ lpages << page
27
+ end
28
+ lpages
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ module Jekyll
2
+ class LanguagePostReader < PostReader
3
+ alias_method :read_content_orig, :read_content
4
+
5
+ def read_content(dir, magic_dir, matcher)
6
+ read_content_orig(dir, magic_dir, matcher).flat_map do |document|
7
+ ldocument = LanguageDocument.new(document.path, { site: @site, collection: @site.posts })
8
+ ldocument.read
9
+
10
+ languages = ldocument.languages.is_a?(Enumerable) ? ldocument.languages : []
11
+ if ldocument.language and not languages.include?(ldocument.language)
12
+ languages.push(ldocument.language)
13
+ end
14
+
15
+ if languages.size == 0
16
+ return [document]
17
+ end
18
+
19
+ languages.map do |language|
20
+ ldocument2 = LanguageDocument.new(document.path, { site: @site, collection: @site.posts })
21
+ ldocument2.data['language'] = language
22
+ ldocument2
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-language-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Wochnik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-13 00:00:00.000000000 Z
11
+ date: 2015-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -74,12 +74,13 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
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
77
+ - lib/jekyll/language_document.rb
78
+ - lib/jekyll/language_page.rb
79
+ - lib/jekyll/language_reader.rb
80
+ - lib/jekyll/readers/language_page_reader.rb
81
+ - lib/jekyll/readers/language_post_reader.rb
82
+ - lib/jekyll/tags/language.rb
83
+ - lib/jekyll/tags/language_include.rb
83
84
  - README.md
84
85
  - LICENSE.md
85
86
  homepage: https://github.com/vwochnik/jekyll-language-plugin
@@ -1,26 +0,0 @@
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
@@ -1,41 +0,0 @@
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