Class: Jekyll::LocalizeLink
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::LocalizeLink
- Defined in:
- lib/jekyll-multiple-languages-plugin.rb
Overview
class LocalizeLink
Creates links or permalinks for translated pages. User must use the “tl” or “translate_link” liquid tags.
Instance Method Summary collapse
-
#initialize(tag_name, key, tokens) ⇒ LocalizeLink
constructor
initialize ======================================.
-
#render(context) ⇒ Object
render ======================================.
Constructor Details
#initialize(tag_name, key, tokens) ⇒ LocalizeLink
initialize
365 366 367 368 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 365 def initialize(tag_name, key, tokens) super @key = key end |
Instance Method Details
#render(context) ⇒ Object
render
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 375 def render(context) if "#{context[@key]}" != "" # Check for page variable key = "#{context[@key]}" else key = @key end key = Liquid::Template.parse(key).render(context) # Parses and renders some Liquid syntax on arguments (allows expansions) site = context.registers[:site] # Jekyll site object key = key.split namespace = key[0] lang = key[1] || site.config[ 'lang'] default_lang = site.config['default_lang'] baseurl = site.baseurl pages = site.pages url = ""; if default_lang != lang baseurl = baseurl + "/" + lang end for p in pages unless p['namespace'].nil? page_namespace = p['namespace'] if namespace == page_namespace permalink = p['permalink_'+lang] || p['permalink'] url = baseurl + permalink end end end url end |