feat: Adding AJAX related plugins

This commit is contained in:
imtodor 2018-10-17 15:27:08 +03:00
Родитель 34bee082b8
Коммит b7611f891f
4 изменённых файлов: 167 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,20 @@
module Reading
class CaptionGenerator < Jekyll::Generator
def generate(site)
@site = site
@converter = site.find_converter_instance(Jekyll::Converters::Markdown)
site.pages.each do |p|
createCaption(p.content)
end
end
def createCaption(content)
sub_string = content.scan(/(>caption)(.*)/)
sub_string.each do |s|
block ="<div class='caption'>" + @converter.convert(s[1]) + "</div>"
content.sub!(s[0]+s[1], block)
end
end
end
end

Просмотреть файл

@ -0,0 +1,12 @@
module Reading
class RemoveInheritanceGenerator < Jekyll::Generator
def generate(site)
@site = site
site.pages.each do |p|
if p.data["description"] == "Client-side API Reference"
p.content.sub!(/(^#[^:]*).*/, '\1')
end
end
end
end
end

Просмотреть файл

@ -0,0 +1,38 @@
module Reading
class TabbedCodeGenerator < Jekyll::Generator
def generate(site)
@site = site
@converter = site.find_converter_instance(Jekyll::Converters::Markdown)
site.pages.each do |p|
createTabbedCode(p, p.content)
end
end
def createTabbedCode(page, content)
tab_start = /````\w/
tab_end = /````\s{2,}/
first_index = content.index(tab_start)
last_index = first_index && content.index(tab_end, first_index)
indexes = []
while first_index && !indexes.include?(first_index)
if last_index.nil?
Jekyll.logger.warn "Tabbed Code Error:", "Failed to generate tabbed code in #{page.path}"
end
indexes.push(first_index)
block = encode_liquid(content[first_index..last_index + 4])
block = @converter.convert(block)
content[first_index..last_index + 4] = "<div class='tabbedCode'>" + block + "</div>"
first_index = content.index(tab_start, last_index)
last_index = first_index && content.index(tab_end, last_index + 4)
end
end
def encode_liquid(content)
content = content.gsub("{{", "{{ '{{' }}")
end
end
end

Просмотреть файл

@ -0,0 +1,97 @@
module Reading
class TemplateGenerator < Jekyll::Generator
priority :highest
def generate(site)
@site = site
@converter = site.find_converter_instance(Jekyll::Converters::Markdown)
site.pages.each do |p|
process_content(p, p.content)
end
end
def process_content(page, content)
template_regexp = /@\[template[^\]]*\]\(\/([^#]*)#([^\s]*)(\s+"([^"]*)")?\)/
template_match = content.match template_regexp
while template_match
begin
result = process_template(template_match)
content.gsub!(template_match.to_s, result)
template_match = content.match template_regexp
rescue => error
Jekyll.logger.warn "Error:", "Templates processing failed in #{page.path}"
raise error
end
end
end
def process_template(match)
file_name = match[1]
section_id = match[2].downcase
has_arguments = match[3]
arguments = match[4]
unless $template_hash
$template_hash = Hash.new
end
unless $template_hash[file_name]
read_template_file(file_name)
end
result = $template_hash[file_name][section_id].to_s
if(has_arguments)
arg_plc_start = "@{"
arg_plc_end = "}"
placeholder_regex = /#{arg_plc_start}([^#{arg_plc_end}]*)#{arg_plc_end}/
arguments_hash = generate_arguments_hash(arguments, arg_plc_start, arg_plc_end)
return result.gsub(placeholder_regex, arguments_hash).rstrip
end
return result.rstrip
end
def read_template_file(file_name)
$template_hash[file_name] = Hash.new
start_regex = /#+([^#]*)/
end_regex = /#+end/i
lines = File.readlines(file_name, :encoding => 'UTF-8')
start_recording = false
id = ""
lines.each do |line|
start_match = start_regex.match(line)
end_match = end_regex.match(line)
if(end_match and start_recording)
start_recording = false
id = ""
end
if(start_recording)
$template_hash[file_name][id] = $template_hash[file_name][id].to_s << line
end
if(start_match and !start_recording and !end_match)
start_recording = true
id = start_match[1].strip.downcase
$template_hash[file_name][id] = ""
end
end
end
def generate_arguments_hash(arguments, plc_start, plc_end)
args_array = arguments.split(",").collect{|x| x.strip.split(":").collect{|value| value.strip}}
hash_args = Hash.new
Hash[args_array].each {|key, value|
hash_key = "#{plc_start}#{key}#{plc_end}"
hash_args[hash_key] = value
}
return hash_args
end
end
end