class Jekyll::Tags::LocalizeInclude
Public Instance Methods
render(context)
click to toggle source
¶ ↑
render
¶ ↑
# 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