Class: Jekyll::Tags::LocalizeInclude

Inherits:
IncludeTag
  • Object
show all
Defined in:
lib/jekyll-multiple-languages-plugin.rb

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object

render



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/jekyll-multiple-languages-plugin.rb', line 311

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
  
  includes_dir = File.join(site.source, '_i18n/' + site.config['lang'])
  
  validate_file_name(file)
  
  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