class Moodle2CC::CanvasCC::PageWriter
Public Class Methods
new(work_dir, *pages)
click to toggle source
# File lib/moodle2cc/canvas_cc/page_writer.rb, line 4 def initialize(work_dir, *pages) @work_dir = work_dir @pages = pages end
Public Instance Methods
write()
click to toggle source
# File lib/moodle2cc/canvas_cc/page_writer.rb, line 9 def write Dir.mkdir(File.join(@work_dir, Moodle2CC::CanvasCC::Models::Page::WIKI_CONTENT)) @pages.each { |page| write_html(page) } end
Private Instance Methods
write_html(page)
click to toggle source
# File lib/moodle2cc/canvas_cc/page_writer.rb, line 17 def write_html(page) builder = Nokogiri::HTML::Builder.new(:encoding => 'UTF-8') do |doc| doc.html { |html| html.head { |head| head.meta('http-equiv' => 'Content-Type', content: 'text/html; charset=utf-8') head.meta(name: 'identifier', content: page.identifier) head.meta(name: 'editing_roles', content: page.editing_roles) head.meta(name: 'workflow_state', content: page.workflow_state) head.title page.title } html.body { |body| body << Nokogiri::HTML::fragment(page.body) } } end file = File.join(@work_dir, page.href) FileUtils.mkdir_p(File.dirname(file)) File.open(file, 'w') { |f| f.write(builder.to_html) } end