nanoc-filesystem-i18n 0.1.0 → 0.2.0

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.
@@ -1,9 +1,11 @@
1
1
  = nanoc-filesystem-i18n
2
2
 
3
+ {<img src="https://secure.travis-ci.org/yannlugrin/nanoc-filesystem-i18n.png" />}[http://travis-ci.org/yannlugrin/nanoc-filesystem-i18n]
4
+
3
5
  filesystem_i18n is a localized data source for a nanoc site. It stores
4
6
  all data as files on the hard disk and is fully compatible with default
5
- nanoc data sources {Nanoc3::DataSources::FilesystemUnified} and
6
- {Nanoc3::DataSources::FilesystemVerbose}.
7
+ nanoc data sources {Nanoc::DataSources::FilesystemUnified} and
8
+ {Nanoc::DataSources::FilesystemVerbose}.
7
9
 
8
10
  Nanoc is a Ruby web publishing system for building small to medium-sized
9
11
  websites. It is a tool that runs on your local computer and compiles documents
@@ -24,11 +26,15 @@ server. For more information, please see Nanoc site.
24
26
 
25
27
  === Installation
26
28
 
27
- gem install nanoc-filesystem-i18n --pre
29
+ gem install nanoc-filesystem-i18n
30
+
31
+ And add following require in your `lib/default.rb` file:
32
+
33
+ require 'nanoc/data_sources/filesystem_i18n'
28
34
 
29
- Add following require in your `lib/default.rb` file:
35
+ Or add following line in your `Gemfile` file:
30
36
 
31
- require 'nanoc3/data_sources/filesystem_i18n'
37
+ gem 'nanoc-filesystem-i18n', :require => 'nanoc/data_sources/filesystem_i18n'
32
38
 
33
39
  Edit `config.yaml` file of your nanoc site and change data_sources type
34
40
  from `filesystem_unified` or `filesystem_verbose` to `filesystem_i18n`:
@@ -89,7 +95,16 @@ e.g. a `foo.fr.markdown` for locale `fr`. If default locale for site is
89
95
  the `fr` content file is used by default.
90
96
 
91
97
  The identifier is calculated by stripping the extension (part after last
92
- dot) and locale code.
98
+ dot) and locale code. The locale code also be added at start of identifier
99
+ (`foo.fr.html` => `/fr/foo/`), remember this when you configure `Rules` file.
100
+
101
+ Top level key in meta file is default for all locales, but you can override a
102
+ metadata for specific locale with following method:
103
+
104
+ title: Default Item Title
105
+ locale:
106
+ fr:
107
+ title: Titre en Français
93
108
 
94
109
  === Configuration
95
110
 
@@ -122,7 +137,35 @@ design images.
122
137
 
123
138
  === Manage locale meta and content
124
139
 
125
- soon...
140
+ All items have an attribute `locale` now, with the item locale code. Get
141
+ current locale code in your templates and helpers with `item[:locale]`.
142
+
143
+ === Rules file
144
+
145
+ In your `Rules` file, you must remember that identifier have locale code at
146
+ the beginning.
147
+
148
+ compile '/*/foo/' do
149
+ filter :erb
150
+ layout 'default'
151
+ end
152
+
153
+ compile '*' do
154
+ filter :erb
155
+ layout 'default'
156
+ end
157
+
158
+ route '/*/foo/' do
159
+ item.identifier.gsub(/\/$/, '') + '.' + item[:extension]
160
+ end
161
+
162
+ route '*' do
163
+ if item.children.size > 0 || item.identifier == '/' || item.identifier == "/#{item[:locale]}/"
164
+ item.identifier + 'index.html'
165
+ else
166
+ item.identifier.gsub(/\/$/, '') + '.' + item[:extension]
167
+ end
168
+ end
126
169
 
127
170
  === Locale selection according to navigator accept language
128
171
 
@@ -130,21 +173,33 @@ If you deploy your site with Apache server, you can use mod_rewrite to select
130
173
  default locale according to navigator accept language configuration. Create an
131
174
  item named `htaccess.erb` in `content` directory with following content:
132
175
 
133
- ---
134
- locale: false
135
- ---
176
+ ---
177
+ locale: false
178
+ ---
179
+
180
+ # For language content negociation, used by css images
181
+ Options +MultiViews
136
182
 
137
183
  RewriteEngine On
138
184
  RewriteBase /
139
185
 
186
+ # Set prefered language from browser preference if available or to default locale
140
187
  RewriteCond %{HTTP:Accept-Language} ^.*?(<%= I18n.available_locales.map{|l| l.to_s }.join('|') %>).*$ [NC]
141
- RewriteRule ^(.*)$ - [env=locale:%1,S=1]
142
- RewriteRule ^(.*)$ - [env=locale:<%= I18n.default_locale.to_s %>]
188
+ RewriteRule ^(.*)$ - [env=prefer-language:%1,S=1]
189
+ RewriteRule ^(.*)$ - [env=prefer-language:<%= I18n.default_locale.to_s %>]
190
+
191
+ # Force prefered language if present in URI
192
+ SetEnvIf REQUEST_URI ^/(<%= I18n.available_locales.map{|l| l.to_s }.join('|') %>)(/.+)? prefer-language=$1
143
193
 
194
+ # Rewrite root access to prefered language root
195
+ RewriteRule ^(/)?$ %{ENV:prefer-language}/ [R=303,L]
196
+
197
+ # Rewrite other uri to language scope
144
198
  RewriteCond %{REQUEST_FILENAME} !-d
145
199
  RewriteCond %{REQUEST_FILENAME} !-f
146
200
  RewriteCond %{REQUEST_FILENAME} !-l
147
- RewriteRule ^(.*)$ %{ENV:locale}/$1 [R=303,L]
201
+ RewriteCond %{REQUEST_URI} !^/(<%= I18n.available_locales.map{|l| l.to_s }.join('|') %>)
202
+ RewriteRule ^(.*)$ %{ENV:prefer-language}/$1 [R=303,L]
148
203
 
149
204
  Add in `Rules` file following compile and route information:
150
205
 
@@ -160,8 +215,6 @@ Add in `Rules` file following compile and route information:
160
215
  With this method, visitor on root of your site is redirected to is/her prefered
161
216
  language or default language.
162
217
 
163
- Another methods comming soon.
164
-
165
218
  == Note on Patches/Pull Requests
166
219
 
167
220
  * Fork the project.
@@ -1,43 +1,48 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'nanoc3'
4
- require 'nanoc3/extra/i18n'
3
+ begin
4
+ require 'nanoc'
5
+ rescue LoadError # fallback to nanoc3 namespace
6
+ require 'nanoc3'
7
+ Nanoc = Nanoc3
8
+ end
9
+ require 'nanoc/extra/i18n'
5
10
 
6
- module Nanoc3::DataSources
11
+ module Nanoc::DataSources
7
12
 
8
13
  # The filesystem_i18n data source is a localized data source for a nanoc
9
14
  # site. It stores all data as files on the hard disk and is fully compatible
10
- # with {Nanoc3::DataSources::FilesystemUnified} and {Nanoc3::DataSources::FilesystemVerbose}.
15
+ # with {Nanoc::DataSources::FilesystemUnified} and {Nanoc::DataSources::FilesystemVerbose}.
11
16
  #
12
17
  # None of the public api methods are documented in this file. See
13
- # {Nanoc3::DataSource} for documentation on the overridden methods instead.
18
+ # {Nanoc::DataSource} for documentation on the overridden methods instead.
14
19
  #
15
20
  # For more information about this data source specifications and configuration,
16
21
  # please read the Readme file.
17
- class FilesystemI18n < Nanoc3::DataSource
22
+ class FilesystemI18n < Nanoc::DataSource
18
23
  identifier :filesystem_i18n
19
24
 
20
25
  # The VCS that will be called when adding, deleting and moving files. If
21
26
  # no VCS has been set, or if the VCS has been set to `nil`, a dummy VCS
22
27
  # will be returned.
23
28
  #
24
- # @return [Nanoc3::Extra::VCS, nil] The VCS that will be used.
29
+ # @return [Nanoc::Extra::VCS, nil] The VCS that will be used.
25
30
  def vcs
26
- @vcs ||= Nanoc3::Extra::VCSes::Dummy.new
31
+ @vcs ||= Nanoc::Extra::VCSes::Dummy.new
27
32
  end
28
33
  attr_writer :vcs
29
34
 
30
- # See {Nanoc3::DataSource#up}.
35
+ # See {Nanoc::DataSource#up}.
31
36
  def up
32
37
  load_config(@config)
33
38
  end
34
39
 
35
- # See {Nanoc3::DataSource#down}.
40
+ # See {Nanoc::DataSource#down}.
36
41
  def down
37
42
  @config_loaded = false
38
43
  end
39
44
 
40
- # See {Nanoc3::DataSource#setup}.
45
+ # See {Nanoc::DataSource#setup}.
41
46
  def setup
42
47
  # Create directories
43
48
  %w( content layouts lib ).each do |dir|
@@ -46,22 +51,22 @@ module Nanoc3::DataSources
46
51
  end
47
52
  end
48
53
 
49
- # See {Nanoc3::DataSource#items}.
54
+ # See {Nanoc::DataSource#items}.
50
55
  def items
51
- load_objects('content', 'item', Nanoc3::Item)
56
+ load_objects('content', 'item', Nanoc::Item)
52
57
  end
53
58
 
54
- # See {Nanoc3::DataSource#layouts}.
59
+ # See {Nanoc::DataSource#layouts}.
55
60
  def layouts
56
- load_objects('layouts', 'layout', Nanoc3::Layout)
61
+ load_objects('layouts', 'layout', Nanoc::Layout)
57
62
  end
58
63
 
59
- # See {Nanoc3::DataSource#create_item}.
64
+ # See {Nanoc::DataSource#create_item}.
60
65
  def create_item(content, attributes, identifier, params={})
61
66
  create_object('content', content, attributes, identifier, params)
62
67
  end
63
68
 
64
- # See {Nanoc3::DataSource#create_layout}.
69
+ # See {Nanoc::DataSource#create_layout}.
65
70
  def create_layout(content, attributes, identifier, params={})
66
71
  create_object('layouts', content, attributes, identifier, params)
67
72
  end
@@ -107,8 +112,8 @@ module Nanoc3::DataSources
107
112
  parent_path = File.dirname(meta_filename)
108
113
 
109
114
  # Notify
110
- Nanoc3::NotificationCenter.post(:file_created, meta_filename)
111
- Nanoc3::NotificationCenter.post(:file_created, content_filename)
115
+ Nanoc::NotificationCenter.post(:file_created, meta_filename)
116
+ Nanoc::NotificationCenter.post(:file_created, content_filename)
112
117
 
113
118
  # Create files
114
119
  FileUtils.mkdir_p(parent_path)
@@ -143,7 +148,7 @@ module Nanoc3::DataSources
143
148
  is_binary = !!(content_filename && !@site.config[:text_extensions].include?(File.extname(content_filename)[1..-1]))
144
149
 
145
150
  # Read content and metadata
146
- meta, content_or_filename = parse(content_filename, meta_filename, kind, (is_binary && klass == Nanoc3::Item))
151
+ meta, content_or_filename = parse(content_filename, meta_filename, kind, (is_binary && klass == Nanoc::Item))
147
152
 
148
153
  # Is locale content?
149
154
  # - excluded content with locale meta IS a locale content
@@ -165,7 +170,7 @@ module Nanoc3::DataSources
165
170
  content_filename = filename_for(base_filename, content_ext)
166
171
 
167
172
  # Read content and metadata for localized content
168
- meta, content_or_filename = parse(content_filename, meta_filename, kind, (is_binary && klass == Nanoc3::Item))
173
+ meta, content_or_filename = parse(content_filename, meta_filename, kind, (is_binary && klass == Nanoc::Item))
169
174
 
170
175
  # merge meta for current locale, default locale meta used by
171
176
  # default is meta don't have key
@@ -184,7 +189,7 @@ module Nanoc3::DataSources
184
189
  # WARNING :file is deprecated; please create a File object manually
185
190
  # using the :content_filename or :meta_filename attributes.
186
191
  # TODO [in nanoc 4.0] remove me
187
- :file => content_filename ? Nanoc3::Extra::FileProxy.new(content_filename) : nil
192
+ :file => content_filename ? Nanoc::Extra::FileProxy.new(content_filename) : nil
188
193
  }.merge(meta)
189
194
 
190
195
  # Get identifier
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc
4
+ module DataSources
5
+ FilesystemI18nVersion = '0.2.0'
6
+ end
7
+ end
8
+
@@ -1,6 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'nanoc3'
3
+ begin
4
+ require 'nanoc'
5
+ rescue LoadError # fallback to nanoc3 namespace
6
+ require 'nanoc3'
7
+ Nanoc = Nanoc3
8
+ end
4
9
  require 'i18n'
5
10
 
6
11
  module I18n
metadata CHANGED
@@ -1,141 +1,99 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: nanoc-filesystem-i18n
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Yann Lugrin
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-10-18 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: nanoc
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70305163704760 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 1
33
- - 2
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 3.1.2
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: i18n
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70305163704760
25
+ - !ruby/object:Gem::Dependency
26
+ name: i18n
27
+ requirement: &70305163704080 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.4.1
49
33
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: minitest
53
34
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70305163704080
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70305163703240 !ruby/object:Gem::Requirement
55
39
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 1.7.2
63
44
  type: :development
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: yard
67
45
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70305163703240
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: &70305163702220 !ruby/object:Gem::Requirement
69
50
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.8
77
55
  type: :development
78
- version_requirements: *id004
79
- description: I18n filesystem based data source for nanoc. Compatible with nanoc 3 and default filesystem based data source.
80
- email: yann.lugrin@sans-savoir.net
56
+ prerelease: false
57
+ version_requirements: *70305163702220
58
+ description: I18n filesystem based data source for nanoc. Compatible with nanoc 3
59
+ and default filesystem based data source.
60
+ email:
61
+ - yann.lugrin@sans-savoir.net
81
62
  executables: []
82
-
83
63
  extensions: []
84
-
85
- extra_rdoc_files:
86
- - LICENSE
87
- - README.rdoc
88
- files:
64
+ extra_rdoc_files: []
65
+ files:
66
+ - lib/nanoc/data_sources/filesystem_i18n/version.rb
67
+ - lib/nanoc/data_sources/filesystem_i18n.rb
68
+ - lib/nanoc/extra/i18n.rb
89
69
  - LICENSE
90
70
  - README.rdoc
91
- - Rakefile
92
- - lib/nanoc3/data_sources/filesystem_i18n.rb
93
- - lib/nanoc3/data_sources/filesystem_i18n/version.rb
94
- - lib/nanoc3/extra/i18n.rb
95
- - test/helper.rb
96
- - test/test_filesystem.rb
97
- - test/test_filesystem_i18n.rb
98
- - test/test_filesystem_unified.rb
99
- - test/test_filesystem_verbose.rb
100
- has_rdoc: true
101
- homepage: http://github.com/yannlugrin/nanoc-filesystem-i18n
71
+ homepage: http://rubygems.org/gems/nanoc-filesystem-i18n
102
72
  licenses: []
103
-
104
73
  post_install_message:
105
- rdoc_options:
74
+ rdoc_options:
106
75
  - --charset=UTF-8
107
- require_paths:
76
+ - --main=README.rdoc
77
+ - --exclude='(lib|test|spec)|(Gem|Guard|Rake)file'
78
+ require_paths:
108
79
  - lib
109
- required_ruby_version: !ruby/object:Gem::Requirement
80
+ required_ruby_version: !ruby/object:Gem::Requirement
110
81
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
118
- required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
87
  none: false
120
- requirements:
121
- - - ">"
122
- - !ruby/object:Gem::Version
123
- hash: 25
124
- segments:
125
- - 1
126
- - 3
127
- - 1
128
- version: 1.3.1
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 1.3.6
129
92
  requirements: []
130
-
131
- rubyforge_project:
132
- rubygems_version: 1.3.7
93
+ rubyforge_project: nanoc-filesystem-i18n
94
+ rubygems_version: 1.8.10
133
95
  signing_key:
134
96
  specification_version: 3
135
97
  summary: I18n filesystem based data source for nanoc
136
- test_files:
137
- - test/helper.rb
138
- - test/test_filesystem_unified.rb
139
- - test/test_filesystem_i18n.rb
140
- - test/test_filesystem.rb
141
- - test/test_filesystem_verbose.rb
98
+ test_files: []
99
+ has_rdoc: