class Jekyll::RdfMainGenerator

Jekyll::RdfMainGenerator enriches a Jekyll::Site with RDF triples

Public Instance Methods

generate(site) click to toggle source

generate performs the enrichment of a Jekyll::Site with rdf triples

  • site - The Jekyll::Site whose data is to be enriched

# File lib/jekyll/rdf_main_generator.rb, line 43
def generate(site)

  if(!load_config(site))
    return false#in case of error, exit routine
  end
  if(@config.key? "template_mapping")
    Jekyll.logger.error("Outdated format in _config.yml:\n  'template_mapping' detected but the following keys must be used now instead:\n    instance_template_mappings -> maps single resources to single layouts\n    class_template_mappings -> maps entire classes of resources to layouts\nJekyll-RDF wont render any pages for #{site.source}")
    return false
  end
  if(!@config['remote'].nil?)
    if (@config['remote']['endpoint'].nil?)
      raise ArgumentError, "When the key 'remote' is specified, another subkey 'endpoint' must be specified which contains the location of your graph."
    else
      graph = @config['remote']['endpoint'].strip
    end
    if @config['remote']['default_graph'].nil?
      sparql = SPARQL::Client.new(graph)
    else
      sparql = SPARQL::Client.new(graph, graph: @config['remote']['default_graph'])
    end
  elsif(!@config['path'].nil?)
    sparql = SPARQL::Client.new(RDF::Graph.load( File.join( site.config['source'], @config['path'])))
  else
    Jekyll.logger.error("No sparql endpoint defined. Jumping out of jekyll-rdf processing.")
    return false
  end

  Jekyll::JekyllRdf::Helper::RdfHelper::sparql = sparql
  Jekyll::JekyllRdf::Helper::RdfHelper::site = site
  Jekyll::JekyllRdf::Helper::RdfHelper::prefixes = File.join(site.source, @config['prefixes'].strip) unless @config['prefixes'].nil?

  # restrict RDF graph with restriction
  resources = []
  resources = resources + extract_resources(@config['restriction'], @config['include_blank'], sparql) unless @config['restriction'].nil?
  resources = resources + extract_list_resources(File.join(site.config['source'], @config['restriction_file'])) unless @config['restriction_file'].nil?
  resources = resources + extract_resources(nil, @config['include_blank'], sparql) if @config['restriction'].nil? && @config['restriction_file'].nil?  # subject + predicate + object should only be extracted if there is neither a restriction or restriction_file
  resources.uniq! unless @config['restriction'].nil? || @config['restriction_file'].nil?
  site.data['sparql'] = sparql
  site.data['resources'] = []

  parse_resources(resources)

  mapper = Jekyll::RdfTemplateMapper.new(@config['instance_template_mappings'], @config['class_template_mappings'], @config['default_template'])

  prepare_pages(site, mapper)

  mapper.print_warnings
  return true
end