ruhl 0.9.2 → 0.9.3

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.9.2
1
+ 0.9.3
data/lib/ruhl.rb CHANGED
@@ -66,10 +66,11 @@ module Ruhl
66
66
  html = tag.to_html
67
67
 
68
68
  new_content = results.collect do |item|
69
- if actions.length == 0 && tag.children.length == 0
70
- t = tag.dup
71
- t.inner_html = item.to_s
72
- t
69
+ # Call to_s on the item only if there are no other actions
70
+ # and there are no other nested data-ruhls
71
+ if actions.length == 0 && tag.xpath('.//*[@data-ruhl]').length == 0
72
+ tag.inner_html = item.to_s
73
+ tag.to_html
73
74
  else
74
75
  Ruhl::Engine.new(html, :local_object => item).render(scope)
75
76
  end
data/ruhl.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruhl}
8
- s.version = "0.9.2"
8
+ s.version = "0.9.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Stone"]
12
- s.date = %q{2009-10-15}
12
+ s.date = %q{2009-10-16}
13
13
  s.description = %q{Make your HTML dynamic with the addition of a data-ruhl attribute.}
14
14
  s.email = %q{andy@stonean.com}
15
15
  s.extra_rdoc_files = [
@@ -4,19 +4,28 @@
4
4
  </head>
5
5
  <body>
6
6
  <h1>Ruby:</h1>
7
- <ul>
8
- <li data-ruhl="_collection: points_of_interest"></li>
9
- </ul>
7
+ <ul id='call-to_s'>
8
+ <li data-ruhl="_collection: points_of_interest">
9
+ <span>sample</span>
10
+ </li>
11
+ </ul>
12
+
13
+ <h1>Ruby user:</h1>
14
+ <ul id='_use-call-to_s' data-ruhl="_use:user">
15
+ <li data-ruhl="_collection: nicknames">
16
+ <span>sample</span>
17
+ </li>
18
+ </ul>
10
19
 
11
20
  <h1>Ruby Titlized:</h1>
12
- <ul>
21
+ <ul id='call-upcase'>
13
22
  <li data-ruhl="_collection: points_of_interest">
14
- <span data-ruhl="capitalize"/>
23
+ <span data-ruhl="upcase"/>
15
24
  </li>
16
25
  </ul>
17
26
 
18
27
  <h1>Ruby reversed:</h1>
19
- <ul>
28
+ <ul id='call-reverse'>
20
29
  <li data-ruhl="_collection: points_of_interest, reverse"></li>
21
30
  </ul>
22
31
  </body>
data/spec/ruhl_spec.rb CHANGED
@@ -182,7 +182,6 @@ describe Ruhl do
182
182
  end
183
183
  end
184
184
 
185
-
186
185
  describe "use.html" do
187
186
  before do
188
187
  @html = File.read html(:use)
@@ -201,15 +200,68 @@ describe Ruhl do
201
200
  @doc.xpath('/html/body/div//input')[2]['value'].should == "jane@stonean.com"
202
201
  end
203
202
  end
204
-
203
+
205
204
  describe "collection_of_strings.html" do
206
205
  before do
207
206
  @html = File.read html(:collection_of_strings)
207
+ @doc = create_doc
208
208
  end
209
209
 
210
- it "will have the string values in the li's" do
211
- doc = create_doc
212
- puts doc.to_s
210
+ describe "with no nested data-ruhls or other actions" do
211
+ it "will have 5 line items" do
212
+ @doc.xpath("//ul[@id='call-to_s']").first.children.length.should == 10
213
+ end
214
+
215
+ it "will have correct content" do
216
+ @doc.xpath("//ul[@id='call-to_s']//li").first.inner_html.should == "Object oriented"
217
+ end
218
+
219
+ describe 'called from within a _use' do
220
+ it "will have correct line items" do
221
+ @doc.xpath("/html/body//ul[@id='_use-call-to_s']/li").children.length.should == 2
222
+ end
223
+
224
+ it "will have correct content" do
225
+ @doc.xpath("/html/body/ul[@id='_use-call-to_s']//li").first.inner_html.should == "Auntie"
226
+ end
227
+ end
228
+ end
229
+
230
+ describe "with a nested data-ruhl" do
231
+ it "will have 5 line items" do
232
+ @doc.xpath("/html/body//ul[@id='call-upcase']").first.children.length.should == 10
233
+ end
234
+
235
+ it "will have correct content" do
236
+ @doc.xpath("/html/body/ul[@id='call-upcase']/li//span").first.inner_html.
237
+ should == "OBJECT ORIENTED"
238
+ end
239
+ end
240
+
241
+ describe "with an additional action" do
242
+ it "will have 5 line items" do
243
+ @doc.xpath("/html/body//ul[@id='call-reverse']").first.children.length.should == 10
244
+ end
245
+
246
+ it "will have correct content" do
247
+ @doc.xpath("/html/body/ul[@id='call-reverse']//li").first.inner_html.
248
+ should == "detneiro tcejbO"
249
+ end
250
+
251
+ it "last item will have correct content" do
252
+ @doc.xpath("/html/body/ul[@id='call-reverse']//li").last.inner_html.
253
+ should == "ecruos nepo"
254
+ end
255
+ end
256
+ end
257
+
258
+ describe "when no method" do
259
+ before do
260
+ @html = "<p data-ruhl='nonexistant_method'>I am bad</p>"#File.read html(:debug)
261
+ end
262
+
263
+ it 'should complain' do
264
+ lambda{ @doc = create_doc }.should raise_error(NoMethodError)
213
265
  end
214
266
  end
215
267
  end
data/spec/spec.opts CHANGED
@@ -1,3 +1,2 @@
1
1
  --color
2
- --format
3
- progress
2
+ --format s
data/spec/spec_helper.rb CHANGED
@@ -19,13 +19,14 @@ end
19
19
 
20
20
 
21
21
  class TestUser
22
- attr_accessor :id, :first_name, :last_name, :email
22
+ attr_accessor :id, :first_name, :last_name, :email, :nicknames
23
23
 
24
24
  def initialize(first, last , email = nil)
25
25
  @first_name = first
26
26
  @last_name = last
27
27
  @email = email
28
28
  @id = rand(100)
29
+ @nicknames = ['Auntie','Pattern']
29
30
  end
30
31
 
31
32
  def radio_input(tag = nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruhl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Stone
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-15 00:00:00 -04:00
12
+ date: 2009-10-16 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency