# Mailer Extension question

**URL:** <https://www.ruby-forum.com/t/mailer-extension-question/117025>\
**Category:** Radiant CMS\
**Created:** [October 12, 2007, 5:45am UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025 "2007-10-12T05:45:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [October 12, 2007, 5:45am UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025/1 "2007-10-12T05:45:13Z")

</div>

Perhaps more a Ruby question than a Radiant question, but…

I’d like to alter the html that the Mailer Extension outputs for  
\<r:mailer:option\> tags within a \<r:mailer:radiogroup\>. Rather than have  
the Label tag follow the Input tag, I want to wrap in Input tag in the  
Label tag (with the label text inside a span). This way, you can have  
the action of clicking on the label activate the associated control  
(even in IE 6, which for some reason, doesn’t do it with just the for  
attribute).

Is there an easy way to “monkey patch” MailerPage to alter the tag  
‘mailer:option’ method?

So, instead of:

Yes

No

I’d like to instead output:

YesNo

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [October 12, 2007, 2:00pm UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025/2 "2007-10-12T14:00:40Z")

</div>

One of the main features of Ruby is that it’s “open” in the sense that  
your code can modify any other loaded coded as desired.

In your case, make an extension that loads after the mailer extension  
and  
patches the MailerPage class as desired.

Other option is to patch your local mailer extension directly.

```
/AITOR
```

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [October 12, 2007, 2:24pm UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025/3 "2007-10-12T14:24:41Z")

</div>

I use svn:externals for my extensions, so directly editing the  
MailerPage class is out. I understand that Ruby classes are open, but  
the Pages in radiant use a DSL for tags, containing a desc, tag pair.  
This is whats throwing me off.

It sounds like you’re saying I can create an extension that loads after  
Mailer, and that defines a radius tag that is named the same as the one  
whose functionality I am looking to replace (r:mailer:option), and it  
will override the one defined in the Mailer extension. Do I understand  
you correctly? Could it be that simple?

(Sorry, c# .Net puts food on the table right now, so I’ve grown  
accustomed to be skeptical of simple solutions, because there are none  
in .Net, not that I’ve found, anyway).

==  
Will G.

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [October 12, 2007, 2:38pm UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025/4 "2007-10-12T14:38:47Z")

</div>

Yes, you can directly replace MailerExtension’s tag definition with  
something in the line of:

class MailerExtension  
desc {  
-\> you will need to duplicate the original desc here, or if you  
don’t care just don’t put it (you won’t get docs)  
}  
tag “r:mailer:option” do |tag|  
-\> your new code here  
end  
end

```
Be sure to define the tag inside the MailerExtension class so it can

```

access that context. Your tag definition will replace the original one.

```
The best of Rails is Ruby...

/AITOR
```

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [October 14, 2007, 5:50pm UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025/5 "2007-10-14T17:50:19Z")

</div>

Sadly, thats not working ☹

I did a script/generate extension MailerAlternateRender, then I tried  
the following code  
(in  
/vendor/extensions/mailer\_alternate\_render/app\_models/mailer\_alternate\_render\_tags.rb):

class MailerPage  
desc %{ Renders an @@ tag if the parent is a  
@\<r:mailer:select\>…\</r:mailer:select\>@ tag, an @@ tag if  
the parent is a @\<r:mailer:radiogroup\>…\</r:mailer:radiogroup\>@ }  
tag ‘mailer:option’ do |tag|  
@tag\_attr = tag.attr.symbolize\_keys  
raise\_error\_if\_name\_missing “mailer:option”  
result = “”  
if tag.locals.parent\_tag\_type == ‘select’  
result \<\< %Q|\<option value="#{tag\_attr.delete(:value) ||  
tag\_attr[:name]}" #{add\_attrs\_to("")}\>#{tag\_attr[:name]}|  
elsif tag.locals.parent\_tag\_type == ‘radiogroup’  
tag.globals.option\_count = tag.globals.option\_count.nil? ? 1 :  
tag.globals.option\_count += 1  
options = tag\_attr.clone.update({  
:id =\>  
“#{tag.locals.parent\_tag\_name}\_#{tag.globals.option\_count}”,  
:value =\> tag\_attr.delete(:value) || tag\_attr[:name],  
:name =\> tag.locals.parent\_tag\_name  
})  
result \<\< %Q|#{tag\_attr[:name]}|  
result \<\< input\_tag\_html( ‘radio’, options )  
result \<\< “”  
#result \<\< input\_tag\_html( ‘radio’, options )  
#result \<\< %Q|#{tag\_attr[:name]}|  
end  
end  
end

I’ve also tried putting it in a MailerAlternateRenderTags module  
(replacing the class declaration),  
and including Page.send :include, MailerAlternateRenderTags in  
mailer\_alternate\_render\_extension.rb

Any thoughts?

==  
Will G.

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [October 14, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025/6 "2007-10-14T17:52:40Z")

</div>

Sorry, that’s  
vendor/extensions/mailer\_alternate\_render/app/models/mailer\_alternate\_render\_tags.rb

==  
Will G.

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [October 14, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025/7 "2007-10-14T20:08:57Z")

</div>

Did you get an error? Or your changes did not apply?

In the second case, probably your extension is being loaded before  
the  
mailer extension. Search this list on how to specify the loading order  
of  
extensions.

```
Anyway, don't let pass Sean's offering to apply your changes to the

```

original code.

```
/AITOR
```

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [October 14, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025/8 "2007-10-14T19:44:23Z")

</div>

Will,

It sounds like you’re jumping through a bunch of unnecessary hoops.  
Could you just create a patch for the existing code, put it in a ticket,  
and let me know about it? I’ll fix it up right away.

Sean

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [October 14, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025/9 "2007-10-14T20:14:12Z")

</div>

Thanks, Sean!

Ticket #564

[http://dev.radiantcms.org/radiant/ticket/564](http://dev.radiantcms.org/radiant/ticket/564)

==  
Will G.

---

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [April 11, 2009, 3:26pm UTC](https://www.ruby-forum.com/t/mailer-extension-question/117025/10 "2009-04-11T15:26:40Z")

</div>

So I went and solved my own problem by modifying things  
([http://github.com/adsmart/radiant-directory-mailer-extension](http://github.com/adsmart/radiant-directory-mailer-extension)) and it  
turns out that it was a very simply addition.

Simply change recipients to directory in you mailer part and add  
recipients\_field. The value of the recipients field is now a list of the  
indexes of items in the directory to use as the recipients.

That is, given a mailer of:  
subject: “Sent from your mailer form”  
recipient\_field: destination  
directory:  
- removed\_email\_address@domain.invalid  
- removed\_email\_address@domain.invalid

and the form from my original post, the message will be sent only to the  
email address(es) that are selected in the form.

I do need help with one bit. I’m not well versed on (T|B)DD so I haven’t  
modified the specs to account for the new behaviour. I’m not quite sure  
how to do it.

Manually keeping the form and the mailer config in sync is more prone to  
error than I’d like so I’m thinking of adding a tag that would let you  
do:

\<r:mailer:select name=“destination”\>  
\<r:directory /\>  
\</r:mailer:select\>

To get the names, I’m not sure if I prefer  
directory:  
- removed\_email\_address@domain.invalid  
- removed\_email\_address@domain.invalid  
names:  
- “First Address”  
- “Second Address”

or  
directory:  
-  
name: “First Address”  
email: removed\_email\_address@domain.invalid  
-  
name: “Second Address”  
email: removed\_email\_address@domain.invalid

either approach has its advantages and disadvantages.

On Thu, 2009-04-09 at 23:26 -0700, Adam van den Hoven wrote:

> ```
> <r:option value="0">First</r:option>
> from_field: email
> 
> ```
> 
> I’d rather not have to customize the extension if I don’t have to.

–  
Adam van den Hoven  
Hybrid Web D.  
Little Fyr Media  
p: 604.618.0845  
e: removed\_email\_address@domain.invalid  
w: [http://www.littlefyr.com](http://www.littlefyr.com)
