octopress-multilingual 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 988ada1b8e7e3a6cd445a4c440476df940673fe0
4
- data.tar.gz: 3c515dec3ace3c5aa14c8ee44bfd9315821ebf06
3
+ metadata.gz: c9c4b68e16a7376bd630c41a53223971b9cb8b31
4
+ data.tar.gz: 914ea8e09eb53c783f427614ef4f596ebe58ac94
5
5
  SHA512:
6
- metadata.gz: a3e26bcc97084f9ad7c91ef0fe11f449adc7d6ffb224a70db8be66d141eba73e1874fddb753d0178a6832f8630f25beafa8dc2a85bf8082ba22ec1dba0c28dd2
7
- data.tar.gz: 67599396585ab3d2b09b088274c07bb29027d23bc475a870d2275ede43ab73c8d0629bb2638ce95c20dfaaff4ad55be1dfbd1ac221282935c0056264cce56a43
6
+ metadata.gz: e55ab6dd6dcc3c5fd251d47671c432541297ca7bbd6052100a0eeaa56d53195d13e079e6d6400b1ab3a04ec92ad712b003657e7097458cde9c9b94381e97fc67
7
+ data.tar.gz: 182bcf88b786ab2ca309ce7725c7cab7231bd4908fa74677fa391bfab3d989398e5cf76d0de93bc683cabce4003964c3769a9868c2ff8d06507b2b3a376b8df8
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ### 0.0.2 (2015-01-18)
4
+
5
+ - New: `{% post_lang %}` block tag.
6
+
7
+ ### 0.0.1 (2015-01-18)
8
+
9
+ - initial release
data/README.md CHANGED
@@ -116,23 +116,62 @@ If you don't want language to appear in your URLs, you must configure your own p
116
116
  ## Post Indexes and RSS Feeds
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
- You may access secondary languages with `site.posts_by_language`.
120
119
 
121
- For example, to loop through the posts written in your main language (or without a defined language) you would do this:
120
+ Using the `post_lang` liquid block, set the language for posts in your post loop. Here's how to use it:
122
121
 
123
122
  ```
124
- {% for post in site.posts.reverse %}
123
+ # Standard post loop (loops through main language)
124
+ {% for post in site.posts %}...{% endfor %}
125
+
126
+ # Loop through german posts (and crossposts)
127
+ {% post_lang de %}
128
+ {% for post in site.posts %}...{% endfor %}
129
+ {% endpost_lang %}
130
+ ```
131
+
132
+ 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
+
134
+ DRY up your templates by putting post loops in an include.
135
+
136
+ <!-- title:"From /index.html" -->
137
+ ```
138
+ # Render main language post index
139
+ {% include post-index.html %}
140
+ ```
141
+
142
+ <!-- title:"From /de/index.html" -->
143
+ ```
144
+ # Render German post index
145
+ {% include post-index.html lang='de' %}
125
146
  ```
126
147
 
127
- This is probably the way your posts index and RSS feeds are generated. If you want to loop through the posts from a secondary language — in this case, German — you would want to do this:
148
+ The post loop in your `_includes/post-index.html` file would look
149
+ like this:
128
150
 
151
+ <!-- title:"From _includes/post-index.html" -->
129
152
  ```
130
- {% for post in site.posts_by_language.de.reverse %}
153
+ {% post_lang include.lang %}
154
+ {% for post in site.posts %}...{% endfor %}
155
+ {% endpost_lang %}
131
156
  ```
132
157
 
133
- 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, you'd copy your posts index to `/de/index.html`.
158
+ This approach should work for RSS feeds and anything that works with the post loop.
134
159
 
135
- This practice should work for RSS feeds and anything that works with the post loop.
160
+ ## Reference posts by language
161
+
162
+ You may also access secondary languages directly with `site.posts_by_language`.
163
+
164
+ For example, to loop through the posts written in your main language (or those with no defined language) you would do this:
165
+
166
+ ```
167
+ {% for post in site.posts %}
168
+ ```
169
+
170
+ If you want to loop through the posts from a secondary language — in this case, German — you would want to do this:
171
+
172
+ ```
173
+ {% for post in site.posts_by_language.de %}
174
+ ```
136
175
 
137
176
  ## Contributing
138
177
 
@@ -1,4 +1,5 @@
1
1
  require "octopress-multilingual/version"
2
+ require "octopress-multilingual/posts_by-tag"
2
3
  require 'octopress-hooks'
3
4
 
4
5
  module Octopress
@@ -0,0 +1,45 @@
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
+
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Multilingual
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: octopress
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: clash
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -101,9 +115,11 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
118
+ - CHANGELOG.md
104
119
  - LICENSE.txt
105
120
  - README.md
106
121
  - lib/octopress-multilingual.rb
122
+ - lib/octopress-multilingual/posts_by-tag.rb
107
123
  - lib/octopress-multilingual/version.rb
108
124
  homepage: https://github.com/octopress/multilingual
109
125
  licenses: