dolores-cml 0.6.1 → 0.6.2

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
- 0.6.1
1
+ 0.6.2
data/cml.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cml}
8
- s.version = "0.6.1"
8
+ s.version = "0.6.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Van Pelt"]
data/lib/cml/parser.rb CHANGED
@@ -5,7 +5,7 @@ module CML
5
5
  def initialize(content, opts = {})
6
6
  @opts = opts
7
7
  #Because nokogiri is munging my CDATA sections, we parse it out ahead of time
8
- @cdata = content.scan(/(<(script|style)[^>]*?>)(.*?)(<\/\2)/m)
8
+ @cdata = content.scan(/(<(script|style)[^>]*?>)(.*?)(<\/\2>)/m)
9
9
  @doc = Parser.parse(content)
10
10
  @cftags = @doc.xpath("//cml:*[not(ancestor::cml:*)]")
11
11
  normalize if opts[:normalize]
@@ -17,7 +17,7 @@ module CML
17
17
  def self.parse(content)
18
18
  #This sucks, we remove scripts, styles, and close non self closed tags
19
19
  #We could potentially add CDATA clauses to them, but this is "easier"
20
- xhtml = content.gsub(/(<(script|style)[^>]*?>)(.*?)(<\/\2)/m, "\\1\\4").gsub(/(<(input|link|img|br|hr).*?)\/?>/,'\1/>') #base, basefont, area, meta
20
+ xhtml = content.gsub(/(<(script|style)[^>]*?>)(.*?)(<\/\2>)/m, "\\1\\4").gsub(/(<(input|link|img|br|hr).*?)\/?>/,'\1/>') #base, basefont, area, meta
21
21
  Nokogiri::XML("<root xmlns:cml=\"http://crowdflower.com\">#{xhtml}</root>")
22
22
  end
23
23
 
@@ -108,7 +108,11 @@ module CML
108
108
  def to_cml
109
109
  cml = @doc.to_xhtml.gsub(/<\/?root[^>]*?>|<\/?>/,'').gsub(/(<(input|link|img|br|hr).*?)\/?>/,'\1/>')
110
110
  #Hack to ensure the next sub doesn't match...
111
- @cdata.each { |matches| cml.sub!(/(<(?:script|style)[^>]*>)</m, "\\1#{matches[2].empty? ? " " : matches[2]}<") }
111
+ @cdata.each do |matches|
112
+ html.sub!(/(<(script|style)[^>]*>)<\/\2>/m) do |m|
113
+ "#{$1}#{matches[2].empty? ? " " : matches[2]}</#{$2}>"
114
+ end
115
+ end
112
116
  cml
113
117
  end
114
118
 
@@ -116,8 +120,12 @@ module CML
116
120
  #We convert the entire document and strip root tags / rando empty tags ALA libxml 2.6.32
117
121
  #We're also adding self closing tags
118
122
  html = convert(opts).to_xhtml.gsub(/<\/?root[^>]*?>|<\/?>/,'').gsub(/(<(input|link|img|br|hr).*?)\/?>/,'\1/>')
119
- #Let's re-insert that CDATA
120
- @cdata.each { |matches| html.sub!(/(<(?:script|style)[^>]*>)</m, "\\1#{matches[2].empty? ? " " : matches[2]}<") }
123
+ #Let's re-insert that CDATA, tricky because scripts will sometimes contain single quotes...
124
+ @cdata.each do |matches|
125
+ html.sub!(/(<(script|style)[^>]*>)<\/\2>/m) do |m|
126
+ "#{$1}#{matches[2].empty? ? " " : matches[2]}</#{$2}>"
127
+ end
128
+ end
121
129
  wrap(html)
122
130
  end
123
131
 
data/spec/complex_spec.rb CHANGED
@@ -64,7 +64,7 @@ describe "CML Complex" do
64
64
  <script src="/javascripts/upload.js" type="text/javascript" charset="utf-8"> </script>
65
65
 
66
66
  <script type="text/javascript">
67
- var cool;
67
+ var cool ='cool\'s';
68
68
  </script>
69
69
  <style type="text/css">
70
70
  a { font: awesome;}
@@ -1,10 +1,12 @@
1
1
  <script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&amp;appid=Knx84fDV34H2VnhVU1DoD7chT1wjJ2r36uf4dZW7Vc5si9sqQRAYU_g8fo7zV.wF"></script>
2
2
  <script src="/javascripts/upload.js" type="text/javascript" charset="utf-8"></script>
3
3
 
4
+
4
5
  <script type="text/javascript">
5
- var cool;
6
+ var cool = 'cool\'s'
6
7
  </script>
7
-
8
8
  <style type="text/css">
9
- a { font:awesome;}
9
+ .invisible{
10
+ a { font: awesome;}
11
+ }
10
12
  </style>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dolores-cml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Van Pelt