class CanvasCc::CC::WebLink
Attributes
external_link[RW]
href[RW]
url[RW]
Public Class Methods
create_resource_key(mod)
click to toggle source
Calls superclass method
CanvasCc::CC::CCHelper#create_resource_key
# File lib/canvas_cc/cc/web_link.rb, line 16 def self.create_resource_key(mod) unless external_link?(mod) create_key(File.join(WEB_RESOURCES_FOLDER, mod.reference), 'resource_') else super end end
external_link?(mod)
click to toggle source
# File lib/canvas_cc/cc/web_link.rb, line 24 def self.external_link?(mod) begin !!URI.parse(mod.reference.to_s.strip.gsub(/\s/, '+')).scheme rescue URI::InvalidURIError !!mod.reference.strip.match(/^https?\:\/\//) end end
new(mod)
click to toggle source
Calls superclass method
CanvasCc::CC::Resource::new
# File lib/canvas_cc/cc/web_link.rb, line 8 def initialize(mod) super @url = mod.reference.to_s.strip @external_link = self.class.external_link?(mod) @href = @external_link ? "#{@identifier}.xml" : File.join(WEB_RESOURCES_FOLDER, @url) @identifier = create_key(@href, 'resource_') unless @external_link end
Public Instance Methods
create_files(export_dir)
click to toggle source
# File lib/canvas_cc/cc/web_link.rb, line 51 def create_files(export_dir) create_xml(export_dir) end
create_resource_node(resources_node)
click to toggle source
# File lib/canvas_cc/cc/web_link.rb, line 32 def create_resource_node(resources_node) if @external_link resources_node.resource( :type => WEB_LINK, :identifier => identifier ) do |resource_node| resource_node.file(:href => href) end else resources_node.resource( :type => WEBCONTENT, :href => href, :identifier => identifier ) do |resource_node| resource_node.file(:href => href) end end end
create_xml(export_dir)
click to toggle source
# File lib/canvas_cc/cc/web_link.rb, line 55 def create_xml(export_dir) return unless @external_link path = File.join(export_dir, "#{identifier}.xml") FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'w') do |file| settings_node = Builder::XmlMarkup.new(:target => file, :indent => 2) settings_node.instruct! settings_node.webLink( :identifier => identifier, 'xsi:schemaLocation' => "http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imswl_v1p1.xsd", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns' => "http://www.imsglobal.org/xsd/imsccv1p1/imswl_v1p1" ) do |web_link_node| web_link_node.title @title web_link_node.url(:href => @url) end end end