Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
648a91b
commit c1bcbb3
Showing
10 changed files
with
140 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'redcarpet' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
redcarpet (3.2.3) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
redcarpet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Hw2Edxml::VerticalChunk < Hw2Edxml::Chunk | ||
|
||
# This is the only kind of chunk that can contain other chunks, so we override #to_edxml | ||
# and #write_self! to recursively output them. | ||
|
||
attr_accessor :chunks | ||
|
||
def initialize(elt) | ||
@chunks = [] | ||
super(elt.to_s, elt.text) | ||
end | ||
|
||
def to_edxml | ||
@xml.vertical(:display_name => display_name) do | ||
chunks.each do |chunk| | ||
@xml.__send__(chunk.type, :url_name => chunk.id) | ||
end | ||
end | ||
@output | ||
end | ||
|
||
def write_self! | ||
super # first, write the vertical/999.xml file | ||
chunks.each { |chunk| chunk.write_self! } # the nested chunks | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'spec_helper' | ||
describe Hw2Edxml::VerticalChunk do | ||
|
||
describe 'outputs nested XML' do | ||
before :each do | ||
@chunks = [ | ||
double('chunk1', :type => 'problem', :id => 'p1'), | ||
double('chunk2', :type => 'html', :id => 'h1'), | ||
double('chunk3', :type => 'problem', :id => 'r1') | ||
] | ||
@subj = Hw2Edxml::VerticalChunk.new(REXML::Document.new('<h1>Foo</h1>')) | ||
@subj.chunks = @chunks | ||
end | ||
subject { @subj.to_edxml } | ||
it { should have_xml_element('vertical').with_attribute(:display_name, 'Foo') } | ||
it { should have_xml_element('vertical/problem').with_attribute(:url_name, 'p1') } | ||
end | ||
end |