feat: Platform tags plugin added.

This commit is contained in:
imtodor 2018-10-01 11:16:55 +03:00
Родитель 70e314b0be
Коммит de0f7c4d35
1 изменённых файлов: 49 добавлений и 0 удалений

49
_plugins/platforms_tag.rb Normal file
Просмотреть файл

@ -0,0 +1,49 @@
module Jekyll
class PlatformsTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
page = context.environments.first["page"]
folderNames = page["dir"].split('/')
platformNames = context.registers[:site].config["platforms"].clone
pageSuiteNames = page["platforms"]
nonSlFolders = context.registers[:site].config["non-sl-folders"]
nonXamarinFolders = context.registers[:site].config["non-xamarin-folders"]
result = String.new
if (folderNames & ["libraries"]).any?
unless pageSuiteNames.nil?
splittedNames = pageSuiteNames.split(',')
platformNames = platformNames.select {|suite| splittedNames.any? {|name| suite.downcase.include?(name)}}
end
if pageSuiteNames.nil?
if (folderNames & nonSlFolders).any?
platformNames.reject!{|suite| suite.downcase.include?("silverlight")}
end
if (folderNames & nonXamarinFolders).any?
platformNames.reject!{|suite| suite.downcase.include?("xamarin")}
end
end
platformNames.each_with_index do |suite, index|
if index != 0
result += "<span class='separator'> | </span>"
end
result += "<span class='platform'>#{suite}</span>"
end
"<div class='platforms'><div>#{@text} #{result}</div></div>"
end
end
end
end
Liquid::Template.register_tag('platforms', Jekyll::PlatformsTag)