jam 0.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/HISTORY ADDED
@@ -0,0 +1,21 @@
1
+ = Jam Change History
2
+
3
+ == 0.2 / 2009-06-15
4
+
5
+ This release cleans up the code and adds support for
6
+ extensions. Currently only Nokigiri is supported as
7
+ a backend engine.
8
+
9
+ Changes:
10
+
11
+ * Rewrote the backend to support #jam extensions.
12
+
13
+ == 0.1 / 2009-06-01
14
+
15
+ This is the first version of Jam, as extracted from the
16
+ Cherry project.
17
+
18
+ Changes:
19
+
20
+ * Happy Birthday!
21
+
@@ -0,0 +1,52 @@
1
+ #!mast bin demo js lib meta test [A-Z]*
2
+ bin
3
+ bin/jam
4
+ demo
5
+ demo/array.rb
6
+ demo/attribute.rb
7
+ demo/demi
8
+ demo/demi/fixtures
9
+ demo/demi/fixtures/ex1.html
10
+ demo/demi/fixtures/samples.yaml
11
+ demo/demi/integration
12
+ demo/demi/integration/01_jam.rd
13
+ demo/demi/integration/02_xpath.rd
14
+ demo/demi/integration/samples.rd
15
+ demo/demi/unit
16
+ demo/demi/unit/hpricot.rd
17
+ demo/demi/unit/libxml.rd
18
+ demo/demi/unit/nokogiri.rd
19
+ demo/demi/unit/rexml.rd
20
+ demo/hash.rb
21
+ demo/helloworld.rb
22
+ demo/object.rb
23
+ demo/table.rb
24
+ js
25
+ js/jquery.jam.js
26
+ lib
27
+ lib/jam
28
+ lib/jam/cherry.rb
29
+ lib/jam/css2xpath.rb
30
+ lib/jam/css_to_xpath.rb
31
+ lib/jam/engine.rb
32
+ lib/jam/hpricot.rb
33
+ lib/jam/libxml.rb
34
+ lib/jam/nokogiri.rb
35
+ lib/jam/rexml.rb
36
+ lib/jam/template.rb
37
+ lib/jam.rb
38
+ meta
39
+ meta/abstract
40
+ meta/author
41
+ meta/created
42
+ meta/homepage
43
+ meta/package
44
+ meta/project
45
+ meta/status
46
+ meta/summary
47
+ meta/timestamp
48
+ meta/title
49
+ meta/version
50
+ TODO
51
+ README
52
+ HISTORY
data/README ADDED
@@ -0,0 +1,39 @@
1
+ = Jam
2
+
3
+ http://jam.rubyforge.org
4
+
5
+ Jam is a data-driven templater system. Jam provides 100% sepearation between
6
+ logic and presentation.
7
+
8
+ Jam can operate on the back-end via Ruby or on the front-end via Javascript/jQuery
9
+ off-loading some of the back-end work load, while also providing 100% SOC
10
+ (Seperation of Concern).
11
+
12
+
13
+ == Examples
14
+
15
+ Here is an example of usage in Javascript.
16
+
17
+ data = {
18
+ hello: "Hello, World!"
19
+ }
20
+
21
+ $.jam(data)
22
+
23
+ Jam templates are especially useful when filled via AJAX with JSON data.
24
+ For this reason a shortcut is provided.
25
+
26
+ $.jam_ajax('http://somewhere/data.json')
27
+
28
+
29
+ == TODO
30
+
31
+ Jam will likely witch from jQuery to Swizzle on the Javascript side in the future.
32
+
33
+
34
+ = License
35
+
36
+ Jam - Ruby/Javascript Templates
37
+
38
+ Copyright (c) 2007,2008 Tiger Ops
39
+
data/TODO ADDED
@@ -0,0 +1,22 @@
1
+ = TODO
2
+
3
+ == Tag Erasing
4
+
5
+ Add erase attribute, jam="erase" or erase="true" or other?
6
+ This will be used to to remove the tag from the xml/xhtml.
7
+
8
+ == Punt Adapter Support to Cherry?
9
+
10
+ It would be much easier to create cherry, and then use that
11
+ to provide different backend adapters.
12
+
13
+ I may limit direct support to Nokogiri and let Cherry handle
14
+ the others. Hpricot adapter works pretty well though (despite
15
+ the unit test bombing). So maybe support Hpricot directly too.
16
+ I'd like to support LibXML-Ruby directly since I helped with
17
+ that project for so long, but it's API is not quite as easy
18
+ to support. So... get Nokogiri working first at least.
19
+
20
+
21
+
22
+
data/bin/jam ADDED
File without changes
@@ -0,0 +1,16 @@
1
+ require 'jam'
2
+
3
+ t = <<-END
4
+ <example>
5
+ <ul><li id="list"></li></ul>
6
+ </example>
7
+ END
8
+
9
+ tmpl = Jam::Template.new t, "LibXML"
10
+
11
+ data = { :list => %w{ A B C } }
12
+
13
+ out = tmpl.expand(data)
14
+
15
+ puts out
16
+
@@ -0,0 +1,24 @@
1
+ require 'jam'
2
+
3
+ tmpl = Jam::Template.new <<-END
4
+ <example id="a"></example>]
5
+ END
6
+
7
+ data = { 'a/@class' => "test" }
8
+
9
+ out = tmpl.render(data)
10
+
11
+ puts out
12
+
13
+ # nested example
14
+
15
+ tmpl = Jam::Template.new <<-END
16
+ <example id="a"></example>]
17
+ END
18
+
19
+ data = { :a => { '@class' => "test" } }
20
+
21
+ out = tmpl.render(data)
22
+
23
+ puts out
24
+
@@ -0,0 +1,10 @@
1
+ <html>
2
+
3
+ <body>
4
+ <h1>Hello</h1>
5
+
6
+ <div id="a">
7
+ </div>
8
+ </body>
9
+
10
+ </html>
@@ -0,0 +1,19 @@
1
+ ---
2
+
3
+ - data:
4
+ a: A
5
+ b: B
6
+ template:
7
+ <x><y><m id="a">dummy</m><n id="b">dummy</n></y></x>
8
+ result:
9
+ <x><y><m id="a">A</m><n id="b">B</n></y></x>
10
+
11
+ - data:
12
+ a: [ A, B, C ]
13
+ template:
14
+ <x><y><m id="a">dummy</m></y></x>
15
+ result:
16
+ <x><y><m id="a">A</m><m id="a">B</m><m id="a">C</m></y></x>
17
+
18
+
19
+
@@ -0,0 +1,41 @@
1
+ = Jam Template Interpolation
2
+
3
+ Load the template library.
4
+
5
+ require 'jam'
6
+
7
+ == Hash
8
+
9
+ Template rendering with a basic hash.
10
+
11
+ tmpl = Jam::Template.new <<-EOS
12
+ <x><y><m id="a">dummy</m><n id="b">dummy</n></y></x>
13
+ EOS
14
+
15
+ data = {
16
+ :a => "A",
17
+ :b => "B"
18
+ }
19
+
20
+ out = tmpl.expand(data).gsub(/\n\s*/,'')
21
+
22
+ out.should == %{<x><y><m id="a">A</m><n id="b">B</n></y></x>}
23
+
24
+ == Lists
25
+
26
+ Template rendering with an Array.
27
+
28
+ tmpl = Jam::Template.new <<-EOS
29
+ <x><y><m id="a">dummy</m></y></x>
30
+ EOS
31
+
32
+ data = {
33
+ :a => [ "A", "B", "C" ]
34
+ }
35
+
36
+ out = tmpl.expand(data).gsub(/\n\s*/,'')
37
+
38
+ out.should == %{<x><y><m id="a">A</m><m id="a">B</m><m id="a">C</m></y></x>}
39
+
40
+ QED.
41
+
@@ -0,0 +1,41 @@
1
+ = Jam Template Interpolation
2
+
3
+ Load the template library.
4
+
5
+ require 'jam'
6
+
7
+ == Hash
8
+
9
+ Template rendering with a basic hash.
10
+
11
+ tmpl = Jam::Template.new <<-EOS
12
+ <x><y><m id="a">dummy</m><n id="b">dummy</n></y></x>
13
+ EOS
14
+
15
+ data = {
16
+ :a => "A",
17
+ :b => "B"
18
+ }
19
+
20
+ out = tmpl.expand(data).gsub(/\n\s*/,'')
21
+
22
+ out.should == %{<x><y><m id="a">A</m><n id="b">B</n></y></x>}
23
+
24
+ == Lists
25
+
26
+ Template rendering with an Array.
27
+
28
+ tmpl = Jam::Template.new <<-EOS
29
+ <x><y><m id="a">dummy</m></y></x>
30
+ EOS
31
+
32
+ data = {
33
+ :a => [ "A", "B", "C" ]
34
+ }
35
+
36
+ out = tmpl.expand(data).gsub(/\n\s*/,'')
37
+
38
+ out.should == %{<x><y><m id="a">A</m><m id="a">B</m><m id="a">C</m></y></x>}
39
+
40
+ QED.
41
+
@@ -0,0 +1,28 @@
1
+ = Jam Template Interpolation
2
+
3
+ Load the template library.
4
+
5
+ require 'jam'
6
+
7
+ == Nokogiri
8
+
9
+ Run samples through Nokogiri adapter.
10
+
11
+ table('samples.yaml') do |sample|
12
+ tmp = Jam::Template.new(sample['template'])
13
+ out = tmp.expand(sample['data']).gsub(/\n\s*/,'')
14
+ out.should == sample['result']
15
+ end
16
+
17
+ == Hpricot
18
+
19
+ Run samples through Hpricot adapter.
20
+
21
+ table('samples.yaml') do |sample|
22
+ tmp = Jam::Template.new(sample['template'])
23
+ out = tmp.expand(sample['data']).gsub(/\n\s*/,'')
24
+ out.should == sample['result']
25
+ end
26
+
27
+ QED.
28
+
@@ -0,0 +1,150 @@
1
+ = Unit Tests for Jam Hpricot Adapter
2
+
3
+ Require adapter.
4
+
5
+ require "jam/hpricot"
6
+
7
+ This automatically requires 'hpricot' too.
8
+
9
+ == Jam::Hpricot
10
+
11
+ Support objects for following tests.
12
+
13
+ @xml = "<root><a>A</a><b>B</b><c>C</c></root>"
14
+ @eng = Jam::Hpricot.new
15
+
16
+ BEFORE: We will resuse this XML document.
17
+
18
+ before {
19
+ @doc = @eng.document(@xml)
20
+ }
21
+
22
+ === #append
23
+
24
+ Append should be able to append an XML node.
25
+
26
+ node = @doc.search('root')
27
+ node2 = node.search('a').dup
28
+
29
+ @eng.append(node, node2)
30
+
31
+ out = node.to_s.gsub(/\n\s*/,'')
32
+ out.should == '<root><a>A</a><b>B</b><c>C</c><a>A</a></root>'
33
+
34
+ Append should be able to append a set of nodes.
35
+
36
+ node = @doc.search('root')
37
+ nodeset = @doc.search('root/*')
38
+
39
+ @eng.append(node, nodeset)
40
+
41
+ out = node.to_s.gsub(/\n\s*/,'')
42
+ out.should == '<root><a>A</a><b>B</b><c>C</c><a>A</a><b>B</b><c>C</c></root>'
43
+
44
+ Append should be able to append an XML text fragment.
45
+
46
+ node = @doc.search('root')
47
+
48
+ @eng.append(node, '<d>D</d>')
49
+
50
+ out = node.to_s.gsub(/\n\s*/,'')
51
+ out.should == '<root><a>A</a><b>B</b><c>C</c><d>D</d></root>'
52
+
53
+ === #replace_content_with_text
54
+
55
+ It should replace node children with given text.
56
+
57
+ node = @doc.search('root')
58
+
59
+ @eng.replace_content_with_text(node, 'H')
60
+
61
+ out = node.to_s.gsub(/\n\s*/,'')
62
+ out.should == '<root>H</root>'
63
+
64
+ It should be able to replace the children of each node of a NodeSet with text.
65
+
66
+ node = @doc.root
67
+ nodeset = @doc.root.children
68
+
69
+ @eng.replace_content_with_text(nodeset, 'H')
70
+
71
+ out = node.to_s.gsub(/\n\s*/,'')
72
+ out.should == '<root><a>H</a><b>H</b><c>H</c></root>'
73
+
74
+ === #cleanup
75
+
76
+ This will clean a document, or node, of any elements that request it.
77
+
78
+ doc = @eng.document('<root><a jam="erase">This is text.</a></root>')
79
+
80
+ @eng.cleanup(doc)
81
+
82
+ out = doc.root.to_s.gsub(/\n\s*/,'')
83
+ out.should == '<root>This is text.</root>'
84
+
85
+
86
+ == Hpricot::Doc
87
+
88
+ === #jam
89
+
90
+ Jam data into a Hpricot Document.
91
+
92
+ xml = Hpricot(%{
93
+ <root><x><m id="a">dummy</m><n id="b">dummy</n></x></root>
94
+ })
95
+
96
+ data = {
97
+ :a => "A",
98
+ :b => "B"
99
+ }
100
+
101
+ out = xml.jam(data)
102
+ out = out.root.to_s.gsub(/\n\s*/,'')
103
+
104
+ out.should == %{<root><x><m id="a">A</m><n id="b">B</n></x></root>}
105
+
106
+ == Hpricot::Elem
107
+
108
+ === #jam
109
+
110
+ Jam data into a Hpricot Node.
111
+
112
+ xml = Hpricot(%{
113
+ <root><x><m id="a">dummy</m><n id="b">dummy</n></x></root>
114
+ })
115
+
116
+ node = xml.root
117
+
118
+ data = {
119
+ :a => "A",
120
+ :b => "B"
121
+ }
122
+
123
+ out = node.jam(data)
124
+ out = out.to_s.gsub(/\n\s*/,'')
125
+
126
+ out.should == %{<root><x><m id="a">A</m><n id="b">B</n></x></root>}
127
+
128
+ == Hpricot::Elements
129
+
130
+ === #jam
131
+
132
+ Jam data into a Hpricot Elements.
133
+
134
+ xml = Hpricot(%{
135
+ <root><x><m id="a" class="q">dummy</m><n id="b" class="q">dummy</n></x></root>
136
+ })
137
+
138
+ nodeset = xml.search('.q')
139
+
140
+ p nodeset.search('#a')
141
+
142
+ data = { :a => "A", :b => "B" }
143
+
144
+ out = nodeset.jam(data)
145
+ out = out.to_s.gsub(/\n\s*/,'')
146
+
147
+ out.should == %{<m class="q" id="a">A</m><n class="q" id="b">B</n>}
148
+
149
+ QED.
150
+