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
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/jekyll-multiple-languages-plugin.rb', line 389 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 |