Class: Jekyll::Tags::LocalizeInclude
- Inherits:
-
IncludeTag
- Object
- IncludeTag
- Jekyll::Tags::LocalizeInclude
- Defined in:
- lib/jekyll-multiple-languages-plugin.rb
Instance Method Summary collapse
-
#render(context) ⇒ Object
render ======================================.
Instance Method Details
#render(context) ⇒ Object
render
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 426 def render(context) if "#{context[@file]}" != "" # Check for page variable file = "#{context[@file]}" else file = @file end file = Liquid::Template.parse(file).render(context) # Parses and renders some Liquid syntax on arguments (allows expansions) site = context.registers[:site] # Jekyll site object default_lang = site.config['default_lang'] validate_file_name(file) includes_dir = File.join(site.source, '_i18n/' + site.config['lang']) # If directory doesn't exist, go to default lang if !Dir.exist?(includes_dir) includes_dir = File.join(site.source, '_i18n/' + default_lang) elsif # If file doesn't exist, go to default lang Dir.chdir(includes_dir) do choices = Dir['**/*'].reject { |x| File.symlink?(x) } if !choices.include?( file) includes_dir = File.join(site.source, '_i18n/' + default_lang) end end end Dir.chdir(includes_dir) do choices = Dir['**/*'].reject { |x| File.symlink?(x) } if choices.include?( file) source = File.read(file) partial = Liquid::Template.parse(source) context.stack do context['include'] = parse_params( context) if @params contents = partial.render(context) ext = File.extname(file) converter = site.converters.find { |c| c.matches(ext) } contents = converter.convert(contents) unless converter.nil? contents end else raise IOError.new "Included file '#{file}' not found in #{includes_dir} directory" end end end |