dolores-cml 0.5.6 → 0.6.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 +1 -1
- data/cml.gemspec +7 -3
- data/lib/cml/parser.rb +12 -4
- data/spec/complex_spec.rb +16 -0
- data/spec/fixtures/script-style.cml +10 -0
- metadata +5 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.1
|
data/cml.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{cml}
|
5
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.1"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Chris Van Pelt"]
|
9
|
-
s.date = %q{2009-09-
|
12
|
+
s.date = %q{2009-09-16}
|
10
13
|
s.description = %q{CML let's you easily create form elements and custom interfaces for the CrowdFlower Croud Labor platform}
|
11
14
|
s.email = %q{vanpelt@doloreslabs.com}
|
12
15
|
s.extra_rdoc_files = [
|
@@ -44,6 +47,7 @@ Gem::Specification.new do |s|
|
|
44
47
|
"spec/fixtures/complex.cml",
|
45
48
|
"spec/fixtures/html.cml",
|
46
49
|
"spec/fixtures/invalid.cml",
|
50
|
+
"spec/fixtures/script-style.cml",
|
47
51
|
"spec/fixtures/segfault.cml",
|
48
52
|
"spec/meta_spec.rb",
|
49
53
|
"spec/normalize_spec.rb",
|
@@ -64,7 +68,7 @@ Gem::Specification.new do |s|
|
|
64
68
|
s.homepage = %q{http://github.com/dolores/cml}
|
65
69
|
s.rdoc_options = ["--charset=UTF-8"]
|
66
70
|
s.require_paths = ["lib"]
|
67
|
-
s.rubygems_version = %q{1.3.
|
71
|
+
s.rubygems_version = %q{1.3.5}
|
68
72
|
s.summary = %q{CML is CrowdFlower Markup Language}
|
69
73
|
s.test_files = [
|
70
74
|
"spec/complex_spec.rb",
|
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)[^>]*?>)(
|
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)[^>]*?>)(
|
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
|
|
@@ -105,11 +105,19 @@ module CML
|
|
105
105
|
to_html
|
106
106
|
end
|
107
107
|
|
108
|
+
def to_cml
|
109
|
+
cml = @doc.to_xhtml.gsub(/<\/?root[^>]*?>|<\/?>/,'').gsub(/(<(input|link|img|br|hr).*?)\/?>/,'\1/>')
|
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]}<") }
|
112
|
+
cml
|
113
|
+
end
|
114
|
+
|
108
115
|
def to_html(opts = nil)
|
109
116
|
#We convert the entire document and strip root tags / rando empty tags ALA libxml 2.6.32
|
110
|
-
|
117
|
+
#We're also adding self closing tags
|
118
|
+
html = convert(opts).to_xhtml.gsub(/<\/?root[^>]*?>|<\/?>/,'').gsub(/(<(input|link|img|br|hr).*?)\/?>/,'\1/>')
|
111
119
|
#Let's re-insert that CDATA
|
112
|
-
@cdata.each { |matches| html.sub!(/(<(?:script|style)[^>]*>)</m, "\\1#{matches[2]}<") }
|
120
|
+
@cdata.each { |matches| html.sub!(/(<(?:script|style)[^>]*>)</m, "\\1#{matches[2].empty? ? " " : matches[2]}<") }
|
113
121
|
wrap(html)
|
114
122
|
end
|
115
123
|
|
data/spec/complex_spec.rb
CHANGED
@@ -57,6 +57,22 @@ describe "CML Complex" do
|
|
57
57
|
@p.to_html
|
58
58
|
end
|
59
59
|
|
60
|
+
it "script / styles" do
|
61
|
+
@p = Parser.new(File.read(File.dirname(__FILE__) + "/fixtures/script-style.cml"), {:prefix => "u12345"})
|
62
|
+
@p.to_html.should sorta_match(<<-HTML)
|
63
|
+
<div class="cml" id="u12345"><script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=Knx84fDV34H2VnhVU1DoD7chT1wjJ2r36uf4dZW7Vc5si9sqQRAYU_g8fo7zV.wF"> </script>
|
64
|
+
<script src="/javascripts/upload.js" type="text/javascript" charset="utf-8"> </script>
|
65
|
+
|
66
|
+
<script type="text/javascript">
|
67
|
+
var cool;
|
68
|
+
</script>
|
69
|
+
<style type="text/css">
|
70
|
+
a { font: awesome;}
|
71
|
+
</style>
|
72
|
+
</div>
|
73
|
+
HTML
|
74
|
+
end
|
75
|
+
|
60
76
|
it "parses scripts and styles" do
|
61
77
|
@p = Parser.new(File.read(File.dirname(__FILE__) + "/fixtures/html.cml"), {:prefix => "u12345"})
|
62
78
|
@p.to_html.length.should > 900
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=Knx84fDV34H2VnhVU1DoD7chT1wjJ2r36uf4dZW7Vc5si9sqQRAYU_g8fo7zV.wF"></script>
|
2
|
+
<script src="/javascripts/upload.js" type="text/javascript" charset="utf-8"></script>
|
3
|
+
|
4
|
+
<script type="text/javascript">
|
5
|
+
var cool;
|
6
|
+
</script>
|
7
|
+
|
8
|
+
<style type="text/css">
|
9
|
+
a { font:awesome;}
|
10
|
+
</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.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Van Pelt
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- spec/fixtures/complex.cml
|
83
83
|
- spec/fixtures/html.cml
|
84
84
|
- spec/fixtures/invalid.cml
|
85
|
+
- spec/fixtures/script-style.cml
|
85
86
|
- spec/fixtures/segfault.cml
|
86
87
|
- spec/meta_spec.rb
|
87
88
|
- spec/normalize_spec.rb
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- spec/validation_spec.rb
|
101
102
|
has_rdoc: false
|
102
103
|
homepage: http://github.com/dolores/cml
|
104
|
+
licenses:
|
103
105
|
post_install_message:
|
104
106
|
rdoc_options:
|
105
107
|
- --charset=UTF-8
|
@@ -120,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
122
|
requirements: []
|
121
123
|
|
122
124
|
rubyforge_project:
|
123
|
-
rubygems_version: 1.
|
125
|
+
rubygems_version: 1.3.5
|
124
126
|
signing_key:
|
125
127
|
specification_version: 3
|
126
128
|
summary: CML is CrowdFlower Markup Language
|