Module: Jekyll::Convertible

Defined in:
lib/polyglot.rb

Overview

Alteration to Jekyll Convertible module provides aliased methods to direct Convertible to skip files for write under certain conditions

Instance Method Summary collapse

Instance Method Details

#langObject



103
104
105
# File 'lib/polyglot.rb', line 103

def lang
  data['lang'] || site.config['default_lang']
end

#lang=(str) ⇒ Object



107
108
109
# File 'lib/polyglot.rb', line 107

def lang=(str)
  data['lang'] = str
end

#polypath(dest) ⇒ Object



122
123
124
125
126
127
128
129
# File 'lib/polyglot.rb', line 122

def polypath(dest)
  n = ''
  site.languages.each do |lang|
    n += "(\\\.#{lang}\\/)|"
  end
  n.chomp! '|'
  destination(dest).gsub(%r{#{n}}, '/')
end

#relative_url_regexObject



145
146
147
148
149
150
151
152
# File 'lib/polyglot.rb', line 145

def relative_url_regex
  n = ''
  site.exclude.each do |x|
    n += "(?!#{x}\/)"
  end
  # regex that looks for all relative urls except for excluded files
  %r{href=\"#{site.baseurl}\/((?:#{n}[^,'\"\s\/?\.#-]+\.?)*(?:\/[^\]\[\)\(\"\'\s]*)?)\"}
end

#relativize_urls(lang) ⇒ Object



140
141
142
143
# File 'lib/polyglot.rb', line 140

def relativize_urls(lang)
  return if lang == site.default_lang
  output.gsub!(relative_url_regex, "href=\"#{site.baseurl}/#{lang}/" + '\1"')
end

#skip?(path) ⇒ Boolean

Returns:

  • (Boolean)


131
132
133
134
135
136
137
138
# File 'lib/polyglot.rb', line 131

def skip?(path)
  return false if site.file_langs[path].nil?
  return false if lang == site.active_lang
  if lang == site.default_lang
    return site.file_langs[path] == site.active_lang
  end
  true
end

#write(dest) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'lib/polyglot.rb', line 112

def write(dest)
  path = polypath(dest)
  return if skip?(path)
  output_orig = output.clone
  relativize_urls(site.active_lang)
  write_orig(dest)
  self.output = output_orig
  site.file_langs[path] = lang
end

#write_origObject



111
# File 'lib/polyglot.rb', line 111

alias_method :write_orig, :write