octopress-multilingual 0.0.2 → 0.0.3

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: c9c4b68e16a7376bd630c41a53223971b9cb8b31
4
- data.tar.gz: 914ea8e09eb53c783f427614ef4f596ebe58ac94
3
+ metadata.gz: 53be2ced0c8a63eb3b700693e9c7970d3f8d9fee
4
+ data.tar.gz: 63c5a43ee90647ca20155753f6cfbe540a4c48aa
5
5
  SHA512:
6
- metadata.gz: e55ab6dd6dcc3c5fd251d47671c432541297ca7bbd6052100a0eeaa56d53195d13e079e6d6400b1ab3a04ec92ad712b003657e7097458cde9c9b94381e97fc67
7
- data.tar.gz: 182bcf88b786ab2ca309ce7725c7cab7231bd4908fa74677fa391bfab3d989398e5cf76d0de93bc683cabce4003964c3769a9868c2ff8d06507b2b3a376b8df8
6
+ metadata.gz: 5559796598c95835c13af44f6ecc402926572629f3ba6499f5511fed54e2063eb6d932dbfe125715647c6ef96057c23e90a1801879ac82a4ce0097e16d659a2f
7
+ data.tar.gz: fdd40263d7ab8776f082297d817e2a7936be4e7137a3af86f82f5557c708d3972cf7f8b5fbc28f802a2e7198bf051fbc6780aade8585fb02efd5ae34df7049d1
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ### 0.0.2 (2015-01-18)
4
4
 
5
+ - Renamed tag to `{% set_lang %}`.
6
+
7
+ ### 0.0.2 (2015-01-18)
8
+
5
9
  - New: `{% post_lang %}` block tag.
6
10
 
7
11
  ### 0.0.1 (2015-01-18)
data/README.md CHANGED
@@ -113,49 +113,81 @@ ordinal => /:lang/:categories/:year/:y_day/:title.html
113
113
 
114
114
  If you don't want language to appear in your URLs, you must configure your own permalinks without `:lang`.
115
115
 
116
- ## Post Indexes and RSS Feeds
116
+ ## Changing language scope
117
117
 
118
118
  This plugin modifies your site's post list. The `site.posts` array **will not contain every post**, but only posts defined with your site's main language or with no language defined.
119
119
 
120
- Using the `post_lang` liquid block, set the language for posts in your post loop. Here's how to use it:
120
+ Using the `set_lang` liquid block, you can temporarily switch languages while rendering a portion of your site. For example:
121
121
 
122
122
  ```
123
- # Standard post loop (loops through main language)
124
- {% for post in site.posts %}...{% endfor %}
123
+ {{ site.lang }} # => 'en'
124
+ {{ site.posts }} # => English posts
125
+
126
+ {% set_lang de %}
127
+ {{ site.lang }} # => 'de'
128
+ {{ site.posts }} # => German posts
129
+ {% endset_lang %}
130
+
131
+ {{ site.lang }} # => 'en'
132
+ {{ site.posts }} # => English posts
133
+ ```
134
+
135
+ ## Post Indexes and RSS Feeds
125
136
 
126
- # Loop through german posts (and crossposts)
127
- {% post_lang de %}
137
+ To add multilingual post indexes you can use the `set_lang` tag like this:
138
+
139
+ ```
140
+ {% set_lang de %}
128
141
  {% for post in site.posts %}...{% endfor %}
129
- {% endpost_lang %}
142
+ {% endset_lang %}
130
143
  ```
131
144
 
132
145
  If your default post index is at `/index.html` you should create additional indexes for each secondary language. If you're also writing in German, create a posts index at `/de/index.html`.
133
146
 
134
- DRY up your templates by putting post loops in an include.
147
+ DRY up your templates by putting post loops in an include, for
148
+ example, `_includes/post-index.html`. It might look this:
135
149
 
136
- <!-- title:"From /index.html" -->
150
+ <!-- title:"From _includes/post-index.html" -->
137
151
  ```
138
- # Render main language post index
139
- {% include post-index.html %}
152
+ {% set_lang page.lang %}
153
+ {% for post in site.posts %}...{% endfor %}
154
+ {% endpost_lang %}
140
155
  ```
141
156
 
157
+ Set the page language to German and include the same partial.
158
+
142
159
  <!-- title:"From /de/index.html" -->
143
160
  ```
144
- # Render German post index
161
+ ---
162
+ lang: de
163
+ ---
164
+ {% include post-index.html %}
165
+ ```
166
+
167
+ The `set_lang` tag will read the `page.lang` setting and
168
+ convert the post loop to use German. If `page.lang` were
169
+ `nil` the default language will be used.
170
+
171
+ If you don't want to set the `lang` for a page, but want to
172
+ use `{% set_lang %}`, that's fine too. It will also work like
173
+ this:
174
+
175
+ ```
145
176
  {% include post-index.html lang='de' %}
177
+
178
+ # Then in the included partial
179
+ {% set_lang include.lang %}
180
+ ...
146
181
  ```
147
182
 
148
- The post loop in your `_includes/post-index.html` file would look
149
- like this:
183
+ Or even just use a normal post loop on your included file and
184
+ set the language when including the partial.
150
185
 
151
- <!-- title:"From _includes/post-index.html" -->
152
186
  ```
153
- {% post_lang include.lang %}
154
- {% for post in site.posts %}...{% endfor %}
155
- {% endpost_lang %}
187
+ {% set_lang de %}{% include post-index.html %}{% endset_lang %}
156
188
  ```
157
189
 
158
- This approach should work for RSS feeds and anything that works with the post loop.
190
+ There are lots of ways to use this, but this approach should work for RSS feeds or any template system which works with the post loop.
159
191
 
160
192
  ## Reference posts by language
161
193
 
@@ -0,0 +1,58 @@
1
+ require 'liquid'
2
+
3
+ module Octopress
4
+ module Multilingual
5
+ class PostsByTag < Liquid::Block
6
+ def initialize(tag_name, markup, tokens)
7
+ super
8
+ @lang = markup.strip
9
+ end
10
+
11
+ def render(context)
12
+ @context = context
13
+ @languages = @context['site.languages']
14
+ @lang_posts = @context['site.posts_by_language']
15
+ main_lang = @context['site.main_language']
16
+
17
+ # Render with new posts context
18
+ if lang
19
+
20
+ # Set to specified language
21
+ set_post_lang lang
22
+ set_current_lang(lang)
23
+
24
+ # Render
25
+ content = super(context)
26
+
27
+ # Reset to main language
28
+ set_post_lang main_lang
29
+ set_current_lang(main_lang)
30
+
31
+ content
32
+ else
33
+ # Tell scope it's in the main
34
+ super(context)
35
+ end
36
+ end
37
+
38
+ def set_post_lang(lang)
39
+ @context.environments.first['site']['posts'] = @lang_posts[lang]
40
+ end
41
+
42
+ def set_current_lang(lang)
43
+ @context.environments.first['site']['lang'] = lang
44
+ end
45
+
46
+ def lang
47
+ # If lang is a local variable, read it from the context
48
+ lang = [@lang, @context[@lang]].select{|l| @languages.include?(l)}.first
49
+ if !lang.nil?
50
+ lang.downcase
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ Liquid::Template.register_tag('set_lang', Octopress::Multilingual::PostsByTag)
58
+
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Multilingual
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  require "octopress-multilingual/version"
2
- require "octopress-multilingual/posts_by-tag"
2
+ require "octopress-multilingual/set_lang-tag"
3
3
  require 'octopress-hooks'
4
4
 
5
5
  module Octopress
@@ -65,7 +65,8 @@ module Octopress
65
65
  {
66
66
  'posts' => main_language_posts,
67
67
  'posts_by_language' => posts_by_language,
68
- 'languages' => languages
68
+ 'languages' => languages,
69
+ 'lang' => main_language
69
70
  }
70
71
  end
71
72
  end
@@ -83,7 +84,9 @@ module Octopress
83
84
  # appear in each language's feed
84
85
  #
85
86
 
86
- { 'site' => Octopress::Multilingual.site_payload(site) }
87
+ {
88
+ 'site' => Octopress::Multilingual.site_payload(site),
89
+ }
87
90
  end
88
91
  end
89
92
  end
@@ -128,3 +131,14 @@ module Jekyll
128
131
  end
129
132
  end
130
133
  end
134
+
135
+ if defined? Octopress::Docs
136
+ Octopress::Docs.add({
137
+ name: "Octopress Multilingual",
138
+ gem: "octopress-multilingual",
139
+ version: Octopress::Multilingual::VERSION,
140
+ description: "",
141
+ path: File.expand_path(File.join(File.dirname(__FILE__), "..")),
142
+ source_url: "https://github.com/octopress/multilingual"
143
+ })
144
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-multilingual
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
@@ -119,7 +119,7 @@ files:
119
119
  - LICENSE.txt
120
120
  - README.md
121
121
  - lib/octopress-multilingual.rb
122
- - lib/octopress-multilingual/posts_by-tag.rb
122
+ - lib/octopress-multilingual/set_lang-tag.rb
123
123
  - lib/octopress-multilingual/version.rb
124
124
  homepage: https://github.com/octopress/multilingual
125
125
  licenses:
@@ -1,45 +0,0 @@
1
- require 'liquid'
2
-
3
- module Octopress
4
- module Multilingual
5
- class PostsByTag < Liquid::Block
6
- def initialize(tag_name, markup, tokens)
7
- super
8
- @lang = markup.strip
9
- end
10
-
11
- def render(context)
12
- @context = context
13
- @languages = context['site.languages']
14
- lang_posts = context['site.posts_by_language']
15
-
16
- # Was a language passed in?
17
- if lang
18
- # Set posts loop, to language
19
- context.environments.first['site']['posts'] = lang_posts[lang]
20
-
21
- # Render with new posts context
22
- rendered = super(context)
23
-
24
- # Restore posts to context
25
- context.environments.first['site']['posts'] = lang_posts[context['site.main_language']]
26
-
27
- rendered
28
- else
29
- super(context)
30
- end
31
- end
32
-
33
- def lang
34
- # If lang is a local variable, read it from the context
35
- lang = [@lang, @context[@lang]].select{|l| @languages.include?(l)}.first
36
- if !lang.nil?
37
- lang.downcase
38
- end
39
- end
40
- end
41
- end
42
- end
43
-
44
- Liquid::Template.register_tag('post_lang', Octopress::Multilingual::PostsByTag)
45
-