class Moodle2CC::CC::WebContent

Attributes

body[RW]

Public Class Methods

new(mod) click to toggle source
Calls superclass method Moodle2CC::CC::Resource::new
# File lib/moodle2cc/cc/web_content.rb, line 8
def initialize(mod)
  super
  @rel_path = File.join(CC_WIKI_FOLDER, "#{file_slug(@title)}.html")
  body = mod.alltext
  body = mod.content || '' if body.nil? || body.length == 0
  if body.nil? || body.length == 0 && mod.summary
    body = mod.summary
    url = mod.reference.to_s.strip
    unless url.gsub(%r{http(s)?://}, '').length == 0
      body += %(<p><a href="#{CGI.escapeHTML(url)}" title="#{CGI.escapeHTML(@title)}">#{@title}</a></p>)
    end
  end
  @body = convert_file_path_tokens(body)
end

Public Instance Methods

create_files(export_dir) click to toggle source
# File lib/moodle2cc/cc/web_content.rb, line 34
def create_files(export_dir)
  create_html(export_dir)
end
create_html(export_dir) click to toggle source
# File lib/moodle2cc/cc/web_content.rb, line 38
def create_html(export_dir)
  template = File.expand_path('../templates/wiki_content.html.erb', __FILE__)
  path = File.join(export_dir, @rel_path)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w') do |file|
    erb = ERB.new(File.read(template))
    file.write(erb.result(binding))
  end
end
create_resource_node(resources_node) click to toggle source
# File lib/moodle2cc/cc/web_content.rb, line 23
def create_resource_node(resources_node)
  href = @rel_path
  resources_node.resource(
    :type => WEBCONTENT,
    :identifier => identifier,
    :href => href
  ) do |resource_node|
    resource_node.file(:href => href)
  end
end