jekyll-localization 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,5 +1,9 @@
1
1
  = Revision history for jekyll-localization
2
2
 
3
+ == 0.0.3 [2010-09-16]
4
+
5
+ * Use alternate page contenten if a page is empty in one language
6
+
3
7
  == 0.0.2 [2010-07-01]
4
8
 
5
9
  * Refactoring and documentation.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to jekyll-localization version 0.0.2
5
+ This documentation refers to jekyll-localization version 0.0.3
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/Rakefile CHANGED
@@ -10,11 +10,19 @@ begin
10
10
  :summary => %q{Jekyll plugin that adds localization features to the rendering engine.},
11
11
  :files => FileList['lib/**/*.rb'].to_a,
12
12
  :extra_files => FileList['[A-Z]*'].to_a,
13
- :dependencies => %w[jekyll-rendering]
13
+ :dependencies => %w[jekyll-rendering],
14
+ :authors => ["Jens Wille"],
15
+ :email => %q{jens.wille@uni-koeln.de}
14
16
  }
15
17
  }}
16
18
  rescue LoadError
17
- abort "Please install the 'hen' gem first."
19
+ warn "Please install the `hen' gem."
18
20
  end
19
21
 
20
22
  ### Place your custom Rake tasks here.
23
+
24
+ begin
25
+ require 'jekyll/testtasks/rake'
26
+ rescue LoadError
27
+ warn "Please install the `jekyll-testtasks' gem."
28
+ end
@@ -40,20 +40,85 @@ module Jekyll
40
40
  # What is considered a language extension
41
41
  LANG_EXT_RE = %r{\.([a-z]{2})}
42
42
 
43
- end
43
+ # Extract relevant parts from a file name
44
+ LANG_PARTS_RE = %r{\A(.*?)#{LANG_EXT_RE}\.(\w+)\z}
44
45
 
45
- class Page
46
+ module LocalizedConvertible
47
+
48
+ def self.included(base)
49
+ base.class_eval {
50
+ alias_method :initialize_without_localization, :initialize
51
+ alias_method :initialize, :initialize_with_localization
52
+ }
53
+ end
46
54
 
47
- alias_method :_localization_original_initialize, :initialize
55
+ private
48
56
 
49
- # Overwrites the original method to extract the language extension.
50
- def initialize(site, base, dir, name)
51
- _localization_original_initialize(site, base, dir, name)
57
+ # Enhances the original method to extract the language extension.
58
+ def initialize_with_localization(*args)
59
+ initialize_without_localization(*args)
52
60
 
53
- @lang = data['lang'] = @name[/#{Localization::LANG_EXT_RE}\.\w+\z/, 1]
54
- @lang_ext = ".#{@lang}" if @lang
61
+ if @lang = extract_lang(@name)
62
+ data['lang'] = @lang
63
+ @lang_ext = ".#{@lang}"
64
+ end
65
+ end
66
+
67
+ # call-seq:
68
+ #
69
+ #
70
+ # Extracts language extension from +name+, or all relevant parts
71
+ # if +all+ is true.
72
+ def extract_lang(name, all = false)
73
+ if md = name.match(LANG_PARTS_RE)
74
+ all ? md.captures : md[2]
75
+ else
76
+ all ? [] : nil
77
+ end
78
+ end
79
+
80
+ def read_alternate_language_content(base, name)
81
+ basename, lang, ext = extract_lang(name, true)
82
+ return unless lang
83
+
84
+ data = self.data # keep original YAML data!
85
+
86
+ (LANGUAGES - [lang]).each { |alternate_lang|
87
+ alternate_name = [basename, alternate_lang, ext].join('.')
88
+
89
+ if File.exists?(File.join(base, alternate_name))
90
+ read_yaml(base, alternate_name, false)
91
+ break unless content.empty?
92
+ end
93
+ }
94
+
95
+ self.data = data
96
+ end
97
+
98
+ end
99
+
100
+ [Page, Post, Layout].each { |klass|
101
+ klass.send(:include, LocalizedConvertible)
102
+ }
103
+
104
+ end
105
+
106
+ module Convertible
107
+
108
+ alias_method :_localization_original_read_yaml, :read_yaml
109
+
110
+ # Overwrites the original method to optionally set the content of a
111
+ # file with no content in it to the content of a file with another
112
+ # language which does have content in it.
113
+ def read_yaml(base, name, alt = true)
114
+ _localization_original_read_yaml(base, name)
115
+ read_alternate_language_content(base, name) if alt && content.empty?
55
116
  end
56
117
 
118
+ end
119
+
120
+ class Page
121
+
57
122
  alias_method :_localization_original_url, :url
58
123
 
59
124
  # Overwrites the original method to include the language extension.
@@ -6,7 +6,7 @@ module Jekyll
6
6
 
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- TINY = 2
9
+ TINY = 3
10
10
 
11
11
  class << self
12
12
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-localization
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 2
10
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jens Wille
@@ -15,18 +14,16 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-07-01 00:00:00 +02:00
17
+ date: 2010-09-16 00:00:00 +02:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: jekyll-rendering
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ">="
28
26
  - !ruby/object:Gem::Version
29
- hash: 3
30
27
  segments:
31
28
  - 0
32
29
  version: "0"
@@ -43,12 +40,12 @@ extra_rdoc_files:
43
40
  - ChangeLog
44
41
  - README
45
42
  files:
46
- - lib/jekyll/localization.rb
47
43
  - lib/jekyll/localization/version.rb
48
- - README
49
- - ChangeLog
44
+ - lib/jekyll/localization.rb
50
45
  - Rakefile
51
46
  - COPYING
47
+ - ChangeLog
48
+ - README
52
49
  has_rdoc: true
53
50
  homepage:
54
51
  licenses: []
@@ -67,27 +64,23 @@ rdoc_options:
67
64
  require_paths:
68
65
  - lib
69
66
  required_ruby_version: !ruby/object:Gem::Requirement
70
- none: false
71
67
  requirements:
72
68
  - - ">="
73
69
  - !ruby/object:Gem::Version
74
- hash: 3
75
70
  segments:
76
71
  - 0
77
72
  version: "0"
78
73
  required_rubygems_version: !ruby/object:Gem::Requirement
79
- none: false
80
74
  requirements:
81
75
  - - ">="
82
76
  - !ruby/object:Gem::Version
83
- hash: 3
84
77
  segments:
85
78
  - 0
86
79
  version: "0"
87
80
  requirements: []
88
81
 
89
82
  rubyforge_project:
90
- rubygems_version: 1.3.7
83
+ rubygems_version: 1.3.6
91
84
  signing_key:
92
85
  specification_version: 3
93
86
  summary: Jekyll plugin that adds localization features to the rendering engine.