class Jekyll::BuildDoc

Public Instance Methods

extractInformation(filename, version) click to toggle source
# File lib/jekyll/version/build/build-doc.rb, line 59
def extractInformation(filename, version)
  summaryList = []
  summary = File.read(filename).split('-')
  summary.each do |string|
    title = string[(string.index("[").to_i)+1..(string.index("]").to_i)-1]
    link = string[(string.index("(").to_i)+1..(string.index(")").to_i)-1]
    link.to_s.sub! '.md', ''
    link.to_s.sub! './', ''
    # Link without the need for JavaScript
    # link = self.getUrl("/docs/#{version}/#{link}")
    if !title.nil? 
      summaryList.push({ title: title, link: link })
    end
  end

  return summaryList
end
extractInformationDir(dir, version) click to toggle source
# File lib/jekyll/version/build/build-doc.rb, line 77
def extractInformationDir(dir, version)
  summaryList = []
  summary = Dir["#{dir}/*.md"]
  summary.each do |filename|
    filename = filename.split('/').last()
    title = filename.to_s.sub! '.md', ''
    link = filename
    # Link without the need for JavaScript
    # link = self.getUrl("/docs/#{version}/#{link}")
    if !title.nil? && title != 'Summary.md'
      summaryList.push({ title: title, link: link })
    end
  end

  return summaryList
end
generate(site) click to toggle source

Main plugin action, called by Jekyll-core

# File lib/jekyll/version/build/build-doc.rb, line 26
def generate(site)
  return Jekyll.logger.warn "\tJekyll Version Doc: The basic structure for the plugin's operation was not found" if !File.directory?("#{Dir.pwd}/_docs/")
 
  @site = site

  path = "#{Dir.pwd}/_docs/*"
  Dir[path].each do |filename|
    Jekyll.logger.info "\tSource: #{filename}"

    version = self.getFileVersion(filename)
    summaryFile = "#{filename}/Summary.md"
    summaryList = []

    if File.exists? summaryFile
      summaryList = self.extractInformation(summaryFile, version)
    else
      summaryList = self.extractInformationDir(filename, version)
    end

    filePath = "#{Dir.pwd}/_site/docs/#{version}"
    FileUtils.mkpath(filePath) unless File.exists?(filePath)


    summary_json = PageWithoutAFile.new(site, site.source, "/docs/#{version}", "summary.json")
    summary_json.content = summaryList.to_json
    site.pages << summary_json
    
    page = Jekyll::PageBuildDocs.new(site, site.source, "/docs/#{version}/", "#{summaryList[0].values[0]}.md", version)
    page.data["sitemap"] = false
    site.pages << page
  end
end
getFileVersion(filename) click to toggle source
# File lib/jekyll/version/build/build-doc.rb, line 94
def getFileVersion(filename)
  version = filename.split('/')
  return version[(version.length-1)]
end
getLastVersion() click to toggle source
# File lib/jekyll/version/build/build-doc.rb, line 99
def getLastVersion
  path = "#{Dir.pwd}/_docs/*"
  return Dir[path].last().to_s.split("/").last()
end
getUrl(input) click to toggle source
# File lib/jekyll/version/build/build-doc.rb, line 104
def getUrl(input)
  return if input.nil?
  return Addressable::URI.parse(
    @site.config["url"].to_s + @site.config["baseurl"] + input
  ).normalize.to_s
end