Class: Moodle2CC::CC::Wiki

Inherits:
Object
  • Object
show all
Includes:
CCHelper, Resource
Defined in:
lib/moodle2cc/cc/wiki.rb

Direct Known Subclasses

Moodle2CC::Canvas::Wiki

Constant Summary

Constants included from CCHelper

CCHelper::ASSESSMENT_CC_QTI, CCHelper::ASSESSMENT_META, CCHelper::ASSESSMENT_NON_CC_FOLDER, CCHelper::ASSESSMENT_TYPE, CCHelper::ASSIGNMENT_GROUPS, CCHelper::ASSIGNMENT_SETTINGS, CCHelper::BASIC_LTI, CCHelper::BLTI_NAMESPACE, CCHelper::CANVAS_NAMESPACE, CCHelper::CANVAS_PLATFORM, CCHelper::CC_ASSIGNMENT_FOLDER, CCHelper::CC_EXTENSION, CCHelper::CC_WIKI_FOLDER, CCHelper::COURSE_SETTINGS, CCHelper::COURSE_SETTINGS_DIR, CCHelper::COURSE_TOKEN, CCHelper::DISCUSSION_TOPIC, CCHelper::EVENTS, CCHelper::EXTERNAL_FEEDS, CCHelper::EXTERNAL_TOOLS, CCHelper::FILES_META, CCHelper::GRADING_STANDARDS, CCHelper::IMS_DATE, CCHelper::IMS_DATETIME, CCHelper::LEARNING_OUTCOMES, CCHelper::LOR, CCHelper::MANIFEST, CCHelper::MEDIA_OBJECTS_FOLDER, CCHelper::MODULE_META, CCHelper::MOODLE_FILEBASE_TOKEN, CCHelper::MOODLE_SLASH_TOKEN, CCHelper::OBJECT_TOKEN, CCHelper::QTI_ASSESSMENT_TYPE, CCHelper::QTI_EXTENSION, CCHelper::QUESTION_BANK, CCHelper::RUBRICS, CCHelper::SYLLABUS, CCHelper::WEBCONTENT, CCHelper::WEB_CONTENT_TOKEN, CCHelper::WEB_LINK, CCHelper::WEB_RESOURCES_FOLDER, CCHelper::WIKI_FOLDER, CCHelper::WIKI_TOKEN, CCHelper::XSD_URI

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

#create_organization_item_node, included

Methods included from CCHelper

convert_file_path_tokens, #convert_file_path_tokens, create_key, #create_key, create_mod_key, #create_mod_key, #create_resource_key, file_query_string, #file_slug, file_slug, #get_html_title_and_body, #get_html_title_and_body_and_id, #get_html_title_and_body_and_meta_fields, ims_date, #ims_date, ims_datetime, #ims_datetime, media_object_info

Constructor Details

#initialize(mod) ⇒ Wiki

Returns a new instance of Wiki.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/moodle2cc/cc/wiki.rb', line 8

def initialize(mod)
  super
  @href_template ||= "#{CC_WIKI_FOLDER}/%s.html"
  page_versions = mod.pages.inject({}) do |result, page|
    version = result[page.page_name]
    result[page.page_name] = page.version if version.nil? || page.version > version
    result
  end

  @pages = mod.pages.map do |page|
    if page.version == page_versions[page.page_name]
      title_slug = file_slug(@title)
      body = page.content
      slug = [title_slug, file_slug(page.page_name)].join('-')
      href = @href_template % slug
      Moodle2CC::OpenStruct.new(:title => page.page_name, :body => body, :href => href, :identifier => create_key(href))
    end
  end.compact

  if @pages.empty?
    slug = file_slug(@title)
    href = @href_template % slug
    @pages = [Moodle2CC::OpenStruct.new(:title => @title, :body => mod.summary, :href => href, :identifier => create_key(href))]
  end

  @identifier = root_page.identifier
end

Instance Attribute Details

#pagesObject

Returns the value of attribute pages.



6
7
8
# File 'lib/moodle2cc/cc/wiki.rb', line 6

def pages
  @pages
end

Class Method Details

.create_resource_key(mod) ⇒ Object



36
37
38
# File 'lib/moodle2cc/cc/wiki.rb', line 36

def self.create_resource_key(mod)
  Wiki.new(mod).identifer
end

Instance Method Details

#create_files(export_dir) ⇒ Object



57
58
59
# File 'lib/moodle2cc/cc/wiki.rb', line 57

def create_files(export_dir)
  create_html(export_dir)
end

#create_html(export_dir) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/moodle2cc/cc/wiki.rb', line 61

def create_html(export_dir)
  template = File.expand_path('../templates/wiki_content.html.erb', __FILE__)
  @pages.each do |page|
    path = File.join(export_dir, page.href)
    FileUtils.mkdir_p(File.dirname(path))
    File.open(path, 'w') do |file|
      erb = ERB.new(File.read(template))
      file.write(erb.result(page.instance_eval { binding }))
    end
  end
end

#create_resource_node(resources_node) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/moodle2cc/cc/wiki.rb', line 44

def create_resource_node(resources_node)
  @pages.each do |page|
    href = page.href
    resources_node.resource(
      :href => href,
      :type => WEBCONTENT,
      :identifier => create_key(href)
    ) do |resource_node|
      resource_node.file(:href => href)
    end
  end
end

#root_pageObject



40
41
42
# File 'lib/moodle2cc/cc/wiki.rb', line 40

def root_page
  @pages.find { |page| page.title.downcase == @title.downcase }
end