From: Dominic Rose on
Hello,
I'm having a problem to output things in the write order with erb1.9
and lighttpd . I don't know if it's the normal comportement of erb but
this is how it works for me:

Content of my ERB file: test{<%= 1 %>2<% puts 3 %>}

On my web browser I get this output:
3
test{12}

puts or print comes before any text.. Do you wich function instead of
puts would print test{123}?

Thanks wery much
--
Posted via http://www.ruby-forum.com/.

From: Rein Henrichs on
On 2010-06-10 07:59:42 -0700, Dominic Rose said:

> Hello,
> I'm having a problem to output things in the write order with erb1.9
> and lighttpd . I don't know if it's the normal comportement of erb but
> this is how it works for me:
>
> Content of my ERB file: test{<%= 1 %>2<% puts 3 %>}
>
> On my web browser I get this output:
> 3
> test{12}
>
> puts or print comes before any text.. Do you wich function instead of
> puts would print test{123}?
>
> Thanks wery much

Do not combine puts with <%= %> output in your erb templates. puts
prints to STDOUT, which may or may not be where your erb template is
rendered. Just use <%= %>.

--
Rein Henrichs
http://puppetlabs.com
http://reinh.com

From: Dominic Rose on
Rein Henrichs wrote:
> On 2010-06-10 07:59:42 -0700, Dominic Rose said:
>
>>
>> puts or print comes before any text.. Do you wich function instead of
>> puts would print test{123}?
>>
>> Thanks wery much
>
> Do not combine puts with <%= %> output in your erb templates. puts
> prints to STDOUT, which may or may not be where your erb template is
> rendered. Just use <%= %>.

If I want to print something on the middle of a script I should do
"%><%= thing_to_print %><%" and that's what I was trying to avoid. Do
you know if I can do somthing like that ?

def print string
$__erbout.write string
end

Except that I don't know what is the erbout real identifier.
--
Posted via http://www.ruby-forum.com/.

From: Rein Henrichs on
On 2010-06-12 06:52:12 -0700, Dominic Rose said:

> Rein Henrichs wrote:
>> On 2010-06-10 07:59:42 -0700, Dominic Rose said:
>>
>>>
>>> puts or print comes before any text.. Do you wich function instead of
>>> puts would print test{123}?
>>>
>>> Thanks wery much
>>
>> Do not combine puts with <%= %> output in your erb templates. puts
>> prints to STDOUT, which may or may not be where your erb template is
>> rendered. Just use <%= %>.
>
> If I want to print something on the middle of a script I should do
> "%><%= thing_to_print %><%" and that's what I was trying to avoid. Do
> you know if I can do somthing like that ?
>
> def print string
> $__erbout.write string
> end
>
> Except that I don't know what is the erbout real identifier.

Just use <%= %>.
--
Rein Henrichs
http://puppetlabs.com
http://reinh.com

From: Phrogz on
On Jun 12, 7:52 am, Dominic Rose <ofusi...(a)gmail.com> wrote:
> If I want to print something on the middle of a script I should do
> "%><%= thing_to_print %><%" and that's what I was trying to avoid. Do
> you know if I can do somthing like that ?
>
> def print string
>     $__erbout.write string
> end

Firstly:
As noted in the documentation, you can specify the erb out variable in
the call to ERB.new:
http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html#M000301
If you don't have control over that, you can look at the source and
see what (if any) name they are supplying and use that.


Secondly:
After I asked to have "puts" work almost 5 years ago, people on the
list
helped create a patch to ERB to allow print and puts to concatenate to
this string. See [1] below. This was followed by some discussion
(again prompted by me) for a RCR to allow this to work. See [2] below.
The discussion there is probably worth reading before we dive into
this again.

[1] http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/152709?152641-153992+split-mode-vertical

[2] http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/155537?155365-157410+split-mode-vertical
 |  Next  |  Last
Pages: 1 2
Prev: right*, not write
Next: RVM Snow Leopard