class CanvasCc::CC::Wiki
Attributes
pages[RW]
Public Class Methods
create_resource_key(mod)
click to toggle source
# File lib/canvas_cc/cc/wiki.rb, line 36 def self.create_resource_key(mod) Wiki.new(mod).identifer end
new(mod)
click to toggle source
Calls superclass method
CanvasCc::CC::Resource::new
# File lib/canvas_cc/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 CanvasCc::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 = [CanvasCc::OpenStruct.new(:title => @title, :body => mod.summary, :href => href, :identifier => create_key(href))] end @identifier = root_page.identifier end
Public Instance Methods
create_files(export_dir)
click to toggle source
# File lib/canvas_cc/cc/wiki.rb, line 57 def create_files(export_dir) create_html(export_dir) end
create_html(export_dir)
click to toggle source
# File lib/canvas_cc/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)
click to toggle source
# File lib/canvas_cc/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_page()
click to toggle source
# File lib/canvas_cc/cc/wiki.rb, line 40 def root_page @pages.find { |page| page.title.downcase == @title.downcase } end