diff --git a/_plugins/caption_generator.rb b/_plugins/caption_generator.rb new file mode 100644 index 0000000..3eb6377 --- /dev/null +++ b/_plugins/caption_generator.rb @@ -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 ="
" + @converter.convert(s[1]) + "
" + content.sub!(s[0]+s[1], block) + end + end + end +end diff --git a/_plugins/remove_inheritance_generator.rb b/_plugins/remove_inheritance_generator.rb new file mode 100644 index 0000000..8bc4fd3 --- /dev/null +++ b/_plugins/remove_inheritance_generator.rb @@ -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 diff --git a/_plugins/tabbedCode_generator.rb b/_plugins/tabbedCode_generator.rb new file mode 100644 index 0000000..735aabe --- /dev/null +++ b/_plugins/tabbedCode_generator.rb @@ -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] = "
" + block + "
" + + 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 diff --git a/_plugins/template_generator.rb b/_plugins/template_generator.rb new file mode 100644 index 0000000..6a54124 --- /dev/null +++ b/_plugins/template_generator.rb @@ -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