nanoc-filesystem-i18n 0.1.0.pre1 → 0.1.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -1,15 +1,24 @@
|
|
1
1
|
= nanoc-filesystem-i18n
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
filesystem_i18n is a localized data source for a nanoc site. It stores
|
4
|
+
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
|
+
|
8
|
+
Nanoc is a Ruby web publishing system for building small to medium-sized
|
9
|
+
websites. It is a tool that runs on your local computer and compiles documents
|
10
|
+
written in formats such as Markdown, Textile, Haml, Erb, ... into a static
|
11
|
+
web site consisting of simple HTML files, ready for uploading to any web
|
12
|
+
server. For more information, please see Nanoc site.
|
6
13
|
|
7
14
|
== Resources
|
8
15
|
|
9
16
|
- FilesystemI18n (http://github.com/yannlugrin/nanoc-filesystem-i18n)
|
10
17
|
- Nanoc (http://nanoc.stoneship.org)
|
11
18
|
- Nanoc on Github (http://github.com/ddfreyne/nanoc)
|
12
|
-
-
|
19
|
+
- Nanoc discussion group (http://groups.google.com/group/nanoc)
|
20
|
+
- Nanoc irc channel (irc://chat.freenode.net/#nanoc)
|
21
|
+
- Ruby I18n on Github (http://github.com/svenfuchs/i18n)
|
13
22
|
|
14
23
|
== Documentation
|
15
24
|
|
@@ -19,7 +28,7 @@ with {Nanoc3::DataSources::FilesystemUnified} and {Nanoc3::DataSources::Filesyst
|
|
19
28
|
|
20
29
|
Add following require in your `lib/default.rb` file:
|
21
30
|
|
22
|
-
|
31
|
+
require 'nanoc3/data_sources/filesystem_i18n'
|
23
32
|
|
24
33
|
Edit `config.yaml` file of your nanoc site and change data_sources type
|
25
34
|
from `filesystem_unified` or `filesystem_verbose` to `filesystem_i18n`:
|
@@ -28,21 +37,21 @@ from `filesystem_unified` or `filesystem_verbose` to `filesystem_i18n`:
|
|
28
37
|
-
|
29
38
|
type: filesystem_i18n
|
30
39
|
|
31
|
-
In the data source section of `config.yaml` file, add following
|
40
|
+
In the data source section of `config.yaml` file, add following informations:
|
32
41
|
|
33
42
|
config:
|
34
43
|
locale:
|
35
44
|
# list of availables locale, ser default to true to select default
|
36
45
|
# locale.
|
37
46
|
availables:
|
38
|
-
fr:
|
39
|
-
name: Francais
|
40
47
|
en:
|
41
|
-
name: English
|
48
|
+
name: "English"
|
42
49
|
default: true
|
50
|
+
fr:
|
51
|
+
name: "Francais"
|
43
52
|
# objects should be not localized
|
44
53
|
exclude:
|
45
|
-
item: ['/css*', '/js*']
|
54
|
+
item: ['/css*', '/js*', '/images*']
|
46
55
|
layout: ['*']
|
47
56
|
|
48
57
|
See following configuration section for more information.
|
@@ -57,7 +66,7 @@ directory.
|
|
57
66
|
|
58
67
|
Every object (item or layout) is represented by a meta file and one or
|
59
68
|
more content files with a minimum of one file. The content file contains
|
60
|
-
|
69
|
+
the actual item content or layout, while the meta file contains the item’s
|
61
70
|
or the layout’s metadata, formatted as YAML.
|
62
71
|
|
63
72
|
Both meta files and content files are named after its parent directory
|
@@ -79,20 +88,79 @@ e.g. a `foo.fr.markdown` for locale `fr`. If default locale for site is
|
|
79
88
|
`fr` and the `foo.fr.markdown` file is present but `foo.markdow` file not,
|
80
89
|
the `fr` content file is used by default.
|
81
90
|
|
82
|
-
The identifier is calculated by stripping the extension (part after last
|
83
|
-
and locale code.
|
91
|
+
The identifier is calculated by stripping the extension (part after last
|
92
|
+
dot) and locale code.
|
84
93
|
|
85
94
|
=== Configuration
|
86
95
|
|
87
|
-
|
96
|
+
You need to configure available locales in config data source section of
|
97
|
+
`config.yaml` file. The I18n configuration is a hash with `locale` key,
|
98
|
+
and have a `availables` section containing each locale information. If
|
99
|
+
`availables` is set to nil, empty hash or false, the site is not localized
|
100
|
+
and data source work normaly. A locale have it code has key and contain a
|
101
|
+
`name` key and optional `default` key. Set only one locale has default.
|
102
|
+
|
103
|
+
config:
|
104
|
+
locale:
|
105
|
+
availables:
|
106
|
+
en:
|
107
|
+
name: "English"
|
108
|
+
default: true
|
109
|
+
fr:
|
110
|
+
name: "Francais"
|
111
|
+
|
112
|
+
Items and layout can be excluded from localize process by set `exclude`
|
113
|
+
list. It is recommanded to exclude all layouts, css, javascript and
|
114
|
+
design images.
|
115
|
+
|
116
|
+
config:
|
117
|
+
locale:
|
118
|
+
...
|
119
|
+
exclude:
|
120
|
+
item: ['/css*', '/js*', '/images*']
|
121
|
+
layout: ['*']
|
88
122
|
|
89
123
|
=== Manage locale meta and content
|
90
124
|
|
91
125
|
soon...
|
92
126
|
|
93
|
-
===
|
127
|
+
=== Locale selection according to navigator accept language
|
94
128
|
|
95
|
-
|
129
|
+
If you deploy your site with Apache server, you can use mod_rewrite to select
|
130
|
+
default locale according to navigator accept language configuration. Create an
|
131
|
+
item named `htaccess.erb` in `content` directory with following content:
|
132
|
+
|
133
|
+
---
|
134
|
+
locale: false
|
135
|
+
---
|
136
|
+
|
137
|
+
RewriteEngine On
|
138
|
+
RewriteBase /
|
139
|
+
|
140
|
+
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 %>]
|
143
|
+
|
144
|
+
RewriteCond %{REQUEST_FILENAME} !-d
|
145
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
146
|
+
RewriteCond %{REQUEST_FILENAME} !-l
|
147
|
+
RewriteRule ^(.*)$ %{ENV:locale}/$1 [R=303,L]
|
148
|
+
|
149
|
+
Add in `Rules` file following compile and route information:
|
150
|
+
|
151
|
+
compile '/htaccess*' do
|
152
|
+
filter :erb
|
153
|
+
# don’t layout
|
154
|
+
end
|
155
|
+
|
156
|
+
route '/htaccess*' do
|
157
|
+
'/.htaccess'
|
158
|
+
end
|
159
|
+
|
160
|
+
With this method, visitor on root of your site is redirected to is/her prefered
|
161
|
+
language or default language.
|
162
|
+
|
163
|
+
Another methods comming soon.
|
96
164
|
|
97
165
|
== Note on Patches/Pull Requests
|
98
166
|
|
@@ -29,11 +29,12 @@ module Nanoc3::DataSources
|
|
29
29
|
|
30
30
|
# See {Nanoc3::DataSource#up}.
|
31
31
|
def up
|
32
|
-
|
32
|
+
load_config(@config)
|
33
33
|
end
|
34
34
|
|
35
35
|
# See {Nanoc3::DataSource#down}.
|
36
36
|
def down
|
37
|
+
@config_loaded = false
|
37
38
|
end
|
38
39
|
|
39
40
|
# See {Nanoc3::DataSource#setup}.
|
@@ -67,6 +68,28 @@ module Nanoc3::DataSources
|
|
67
68
|
|
68
69
|
private
|
69
70
|
|
71
|
+
# Load data source configuration and configure I18n
|
72
|
+
def load_config(config)
|
73
|
+
unless @config_loaded
|
74
|
+
config = config.symbolize_keys if config
|
75
|
+
@exclude_objects = {}
|
76
|
+
|
77
|
+
if config && config[:locale]
|
78
|
+
I18n.available_locales = config[:locale][:availables] ? config[:locale][:availables].map {|code, data| code.to_sym } : []
|
79
|
+
if I18n.localized_site?
|
80
|
+
I18n.default_locale = I18n.available_locales.find{|code, data| data[:default] }[0] rescue I18n.available_locales.first
|
81
|
+
@exclude_objects = config[:locale][:exclude] if config[:locale][:exclude]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# By default, exclude object Hash return empty array, or if site
|
86
|
+
# is not localized (no available locale), all objects is excluded.
|
87
|
+
@exclude_objects.default = I18n.localized_site? ? [] : ['*']
|
88
|
+
end
|
89
|
+
|
90
|
+
@config_loaded = true
|
91
|
+
end
|
92
|
+
|
70
93
|
# Creates a new object (item or layout) on disk in dir_name according to
|
71
94
|
# the given identifier. The file will have its attributes taken from the
|
72
95
|
# attributes hash argument and its content from the content argument.
|
@@ -339,7 +362,7 @@ module Nanoc3::DataSources
|
|
339
362
|
# layout: ['*']
|
340
363
|
#
|
341
364
|
def locale_exclude_regex(kind)
|
342
|
-
Regexp.union(
|
365
|
+
Regexp.union(@exclude_objects[kind.to_sym].map do |identifier|
|
343
366
|
if identifier.is_a? String
|
344
367
|
# Add leading/trailing slashes if necessary
|
345
368
|
new_identifier = identifier.dup
|
data/lib/nanoc3/extra/i18n.rb
CHANGED
@@ -6,43 +6,14 @@ require 'i18n'
|
|
6
6
|
module I18n
|
7
7
|
class Config
|
8
8
|
|
9
|
+
# A site is note localized if available locale is empty
|
9
10
|
def localized_site?
|
10
11
|
!available_locales.empty?
|
11
12
|
end
|
12
13
|
|
13
|
-
def exclude_list(kind)
|
14
|
-
@exclude ||= {}
|
15
|
-
@exclude[kind] ||= localized_site? ? [] : ['*']
|
16
|
-
end
|
17
|
-
|
18
|
-
def exclude_list=(exclude)
|
19
|
-
@exclude = exclude
|
20
|
-
end
|
21
|
-
|
22
14
|
end
|
23
15
|
|
24
16
|
class << self
|
25
|
-
def load_config(dir_or_config_hash)
|
26
|
-
if dir_or_config_hash.is_a? String
|
27
|
-
# Read config from config.yaml in given dir
|
28
|
-
config_path = File.join(dir_or_config_hash, 'config.yaml')
|
29
|
-
config_data = YAML.load_file(config_path).symbolize_keys[:locale] rescue {}
|
30
|
-
else
|
31
|
-
# Use passed config hash
|
32
|
-
config_data = dir_or_config_hash || {}
|
33
|
-
end
|
34
|
-
|
35
|
-
config.available_locales = config_data[:availables] ? config_data[:availables].map {|code, data| code.to_sym } : []
|
36
|
-
if I18n.localized_site?
|
37
|
-
config.default_locale = begin config_data[:availables].find{|code, data| data[:default] }[0] rescue config_data[:availables].first[0] end
|
38
|
-
config.exclude_list = config_data[:exclude]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def exclude_list(kind)
|
43
|
-
config.exclude_list(kind)
|
44
|
-
end
|
45
|
-
|
46
17
|
def localized_site?
|
47
18
|
config.localized_site?
|
48
19
|
end
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.1.0.
|
9
|
+
- pre2
|
10
|
+
version: 0.1.0.pre2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yann Lugrin
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-04-
|
18
|
+
date: 2010-04-09 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|