jarrett-quarto 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.4.1
@@ -47,7 +47,13 @@ module Quarto
47
47
  # on the rules you've set up, the result may
48
48
  # be XML or something else altogether.
49
49
  #
50
- # +element+ must be a <tt>REXML::Element</tt>.
50
+ # +element+ must be a <tt>REXML::Element</tt>
51
+ # or a subclass thereof. If +element+ is a
52
+ # <tt>REXML::Document</tt>, the document root and all
53
+ # its children will be transformed. If +element+
54
+ # is a <tt>REXML::Element</tt>, only the element's
55
+ # descendents will be tranformed; +element+ itself
56
+ # will not be used.
51
57
  #
52
58
  # By default, unrecognized elements (and all their
53
59
  # descendants) will be ommited from the result tree.
@@ -60,7 +66,11 @@ module Quarto
60
66
  if element.is_a?(REXML::Document)
61
67
  recursive_transform(element.root, raise_on_unrecognized_element)
62
68
  else
63
- recursive_transform(element, raise_on_unrecognized_element)
69
+ result = ''
70
+ element.children.each do |child|
71
+ result << recursive_transform(child, raise_on_unrecognized_element)
72
+ end
73
+ result
64
74
  end
65
75
  end
66
76
 
data/quarto.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{quarto}
5
- s.version = "1.4.0"
5
+ s.version = "1.4.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jarrett Colby"]
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  "spec/children_spec.rb",
46
46
  "spec/element_wrapper_spec.rb",
47
47
  "spec/generator_spec.rb",
48
+ "spec/html_tranformer_spec.rb",
48
49
  "spec/init_project_spec.rb",
49
50
  "spec/matchers/file_matchers.rb",
50
51
  "spec/matchers/rexml_matchers.rb",
@@ -22,9 +22,10 @@ describe Quarto::ElementWrapper::Base do
22
22
  @company.name.should == '37Signals'
23
23
  end
24
24
 
25
- it 'should return a REXML::Element if an elemement_attr contains markup' do
25
+ it 'should return the attribute\'s REXML::Element if an element_attr contains markup' do
26
26
  company = Company.find(:first, :xpath => "//company[name='Mega-lo-Mart']")
27
27
  company.description.should be_a(REXML::Element)
28
+ company.description.name.should == 'description'
28
29
  end
29
30
 
30
31
  it 'should define methods from XML attributes by default' do
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Quarto::HtmlTransformer do
4
+ include Quarto::REXMLMatchers
5
+
6
+ context '#transform' do
7
+ before :each do
8
+ @html = REXML::Document.new(%Q(
9
+ <description>
10
+ <p id="first_paragraph">Mega-lo-Mart is a parody of big-box stores featured in <cite>King of the Hill</cite>.</p>
11
+
12
+ <p id="second_paragraph">It is featured in Wikipedia's
13
+ <a href="http://en.wikipedia.org/wiki/List_of_fictional_companies">List&nbsp;of&nbsp;Fictional&nbsp;Companies.</a>
14
+ </p>
15
+ </description>
16
+ ))
17
+ @t = Quarto::HtmlTransformer.new
18
+ end
19
+
20
+ it 'should return valid HTML verbatim, even if the root element is not a valid HTML element' do
21
+ output = @t.transform(@html.root)
22
+ output = REXML::Document.new('<description>' + output + '</description>')
23
+ output.should have_element('p', :attributes => {'id' => 'first_paragraph'})
24
+ output.should have_element('cite', :text => 'King of the Hill')
25
+ output.should have_element('p', :attributes => {'id' => 'second_paragraph'})
26
+ output.should have_element('a', :attributes => {'href' => 'http://en.wikipedia.org/wiki/List_of_fictional_companies'})
27
+ end
28
+ end
29
+ end
@@ -9,6 +9,7 @@ describe Quarto::TransformationHelper do
9
9
  <div>
10
10
  <p>Foo</p>
11
11
  <p><a href="http://example.com">Bar</a></p>
12
+ <p>Baz&mdash;Baz</p>
12
13
  </div>
13
14
  ))
14
15
  end
@@ -29,6 +30,10 @@ describe Quarto::TransformationHelper do
29
30
  Quarto::HtmlTransformer.should_receive(:new).and_return(t)
30
31
  transform_xml(@html)
31
32
  end
33
+
34
+ it 'should return the original HTML' do
35
+ REXML::Document.new(transform_xml(@html)).to_s.should == @html.to_s.strip
36
+ end
32
37
  end
33
38
  end
34
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jarrett-quarto
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarrett Colby
@@ -80,6 +80,7 @@ test_files:
80
80
  - spec/children_spec.rb
81
81
  - spec/element_wrapper_spec.rb
82
82
  - spec/generator_spec.rb
83
+ - spec/html_tranformer_spec.rb
83
84
  - spec/init_project_spec.rb
84
85
  - spec/matchers/file_matchers.rb
85
86
  - spec/matchers/rexml_matchers.rb