Class: Senkyoshi::WikiPage

Inherits:
Content show all
Includes:
Senkyoshi
Defined in:
lib/senkyoshi/models/wikipage.rb

Constant Summary

Constants included from Senkyoshi

DIR_BASE, FILE_BASE, MAIN_CANVAS_MODULE, MASTER_MODULE, PRE_RESOURCE_TYPE, RESOURCE_TYPE, VERSION

Constants inherited from Content

Content::CONTENT_TYPES, Content::MODULE_TYPES

Instance Attribute Summary

Attributes inherited from Content

#body, #extendeddata, #files, #title, #url

Attributes inherited from FileResource

#id

Instance Method Summary collapse

Methods included from Senkyoshi

build_file, build_heirarchy, cleanup, configure, connect_content, create_canvas_course, create_random_hex, get_attribute_value, get_description, get_single_pre_data, get_text, initialize_course, iterate_files, iterate_xml, iterator_master, parse, parse_and_process_single, pre_iterator, read_file, reset, true?

Methods inherited from Content

#create_module, from, #iterate_xml, #set_module

Methods inherited from FileResource

#create_module, from, #initialize, #iterate_xml

Methods inherited from Resource

#_find_directories, #_fix_path, #_matches_directory_xid?, #_search_and_replace, #cleanup, #fix_html, get_pre_data, #matches_xid?, #strip_xid

Constructor Details

This class inherits a constructor from Senkyoshi::FileResource

Instance Method Details

#_component_label(node) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/senkyoshi/models/wikipage.rb', line 90

def _component_label(node)
  visible = Senkyoshi.true?(node.search("vislableToStudents/@value").to_s)
  if visible
    component_label = node.search("componentLabel/@value").to_s
    overridden = Senkyoshi.true?(node.search("labelOverridden/@value").to_s)
    if overridden
      component_label
    else
      component_label.split(".").last.capitalize
    end
  else
    ""
  end
end

#_extendeddata(extendeddata) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/senkyoshi/models/wikipage.rb', line 80

def _extendeddata(extendeddata)
  Nokogiri::XML(extendeddata).
    search("LessonPlanComponent").
    map do |node|
      _component_label(node) + node.search("componentValue/@value").to_s
    end.
    compact.
    join(" ")
end

#_set_body(original_body, url, extendeddata) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/senkyoshi/models/wikipage.rb', line 51

def _set_body(original_body, url, extendeddata)
  body = original_body.dup

  if !url.empty?
    body = %{
      <a href="#{url}">
        #{url}
      </a>
      #{body}
    }
  end
  if @referred_to_title.present?
    body = %{
      <a href="$CANVAS_COURSE_REFERENCE$#{@referred_to_title}">
        Course Link: #{@referred_to_title}
      </a>
      #{body}
    }
  end
  if extendeddata
    body = %{
      #{body}
      #{_extendeddata(extendeddata)}
    }
  end

  body
end

#canvas_conversion(course, resources) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/senkyoshi/models/wikipage.rb', line 22

def canvas_conversion(course, resources)
  unless @title == "--TOP--"
    page_count = course.pages.
      select { |p| p.title.start_with? @title }.count
    @title = "#{@title}-#{page_count + 1}" if page_count > 0
    page = CanvasCc::CanvasCC::Models::Page.new
    @body = _set_body(@body, @url, @extendeddata)
    page.body = fix_html(@body, resources)
    page.identifier = @id
    page.page_name = @title
    page.workflow_state = "active"

    # Add page links to page body
    @files.each do |file|
      if canvas_file = course.files.detect { |f| f.identifier == file.name }
        page.body << file.canvas_conversion(resources, canvas_file)
      else
        page.body <<
          "<p>File: #{file.linkname} -- doesn't exist in blackboard</p>"
      end
    end
    course.pages << page

    course = create_module(course)
  end

  course
end