public
Description: A simple Radiant extension that provides a method to easily re-render text within a Radius tag
Clone URL: git://github.com/AndrewO/rerender_text.git
Added simple rerender tag.
Andrew O'Brien (author)
Wed Mar 19 13:50:59 -0700 2008
commit  5b5c14cc05050327bc0dcfe50846e08a8bc99302
tree    5e75d5ea7098529fb2b8abdb2f17ddec9f06ace1
parent  709124fe3e1e779c3d74d2a31b32f4cdb59c5d3c
0
...
31
32
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
...
31
32
33
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
0
@@ -31,4 +31,25 @@ which sets up a new Radius context and parser to expand tags in the "rr" namespa
0
 
0
 == Using other namespaces
0
 
0
-If you need to render more than twice, you can change the namespace used for a particular parser and context using the <tt>rerender_with_namespace(text, namespace, options)</tt> method.
0
\ No newline at end of file
0
+If you need to render more than twice, you can change the namespace used for a particular parser and context using the <tt>rerender_with_namespace(text, namespace, options)</tt> method.
0
+
0
+== <r:rerender>
0
+
0
+This extension includes one tag that acts as a basic rerenderer. Sometimes the tag that contains a rerenderable tag doesn't need to do anything but call it with the correct namespace due to the fact that tags may have side-effects. For example, the example above can be
0
+
0
+<tt>
0
+<r:rerender>
0
+ <rr:table_of_contents/>
0
+
0
+<r:h1>Foo</r:h1>
0
+
0
+...
0
+
0
+<r:h2>Bar</r:h2>
0
+
0
+...
0
+
0
+</r:rerender>
0
+</tt>
0
+
0
+...as long as the <r:hx> tags add effect an instance variable of the page that's accessible to tag.globals.page.
0
\ No newline at end of file
...
1
2
 
 
 
3
4
 
 
 
 
 
 
 
 
 
5
6
7
8
 
9
10
11
...
1
2
3
4
5
6
 
7
8
9
10
11
12
13
14
15
16
17
18
 
19
20
21
22
0
@@ -1,11 +1,22 @@
0
 module RerenderText
0
   include Radiant::Taggable
0
+
0
+ desc %{
0
+ Use this to render the contained content twice
0
     
0
- def rerender_text(text, options)
0
+ Usage:
0
+ <pre><code><r:rerender [prefix="rr"]>...</r:rerender></code></pre>
0
+ }
0
+ tag "rerender" do |tag|
0
+ prefix = tag.attr["prefix"] || "rr"
0
+ rerender_text_with_prefix(tag.expand, prefix)
0
+ end
0
+
0
+ def rerender_text(text, options = {})
0
     rerender_text_with_prefix(text, "rr", options)
0
   end
0
   
0
- def rerender_text_with_prefix(text, prefix, options)
0
+ def rerender_text_with_prefix(text, prefix, options = {})
0
     _context = RerenderContext.new(self, text, options)
0
     _parser = Radius::Parser.new(_context, :tag_prefix => prefix)
0
     new_text = _parser.parse(text)
...
51
52
53
 
 
54
55
56
...
61
62
63
64
65
66
67
68
69
70
71
72
 
73
74
75
...
85
86
87
88
 
89
90
91
...
113
114
115
116
 
117
118
119
...
51
52
53
54
55
56
57
58
...
63
64
65
 
 
 
 
 
66
67
68
 
69
70
71
72
...
82
83
84
 
85
86
87
88
...
110
111
112
 
113
114
115
116
0
@@ -51,6 +51,8 @@ unless String.method_defined? :to_slug
0
 end
0
 
0
 class Page
0
+ attr_reader :headers
0
+
0
   6.times do |i|
0
     tag "h#{i + 1}" do |tag|
0
       contents = tag.expand
0
@@ -61,15 +63,10 @@ class Page
0
     end
0
   end
0
   
0
- desc "Pulls out all of the headers in a page"
0
- tag "capture_headers" do |tag|
0
- rerender_text(tag.expand, :headers => @headers)
0
- end
0
-
0
   desc "Renders the page table of contents"
0
   tag "toc" do |tag|
0
     str = "<ul id='toc'>"
0
- tag.locals.headers.each do |header|
0
+ tag.globals.page.headers.each do |header|
0
       str += %{<li><a href="##{header[:id]}">#{header[:text]}</a></li>}
0
     end
0
     str += "</ul>"
0
@@ -85,7 +82,7 @@ describe Page, "with a more complicated rerender tag" do
0
 
0
     @page = Page.new(:title => "Test Page", :slug => "test-page", :status_id => 100, :breadcrumb => "Test Page")
0
     rerender_text = %{
0
-<r:capture_headers>
0
+<r:rerender>
0
   <rr:toc/>
0
 
0
 <r:h1>Foo</r:h1>
0
@@ -113,7 +110,7 @@ magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
0
 consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
0
 Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
0
 
0
-</r:capture_headers>
0
+</r:rerender>
0
 }
0
     @page.parts << PagePart.new(:name => "body", :content => rerender_text, :filter_id => "Textile")
0
     @page.save!

Comments

    No one has commented yet.