Is it possible to use __END__ in .erb file?


(Wolf) #1

Hi,
I would love to use __END__ / DATA in my .erb file (executed
via `erb file.erb`. I've tried

  <html>
    <head />
    <body>
      <%= DATA %>
    </body>
  </html>
  <%
  __END__
  foobar

but that does not work

  Traceback (most recent call last):
    5: from /usr/bin/erb:170:in `<main>'
    4: from /usr/bin/erb:149:in `run'
    3: from /usr/lib/ruby/2.5.0/erb.rb:858:in `run'
    2: from /usr/lib/ruby/2.5.0/erb.rb:876:in `result'
    1: from /usr/lib/ruby/2.5.0/erb.rb:876:in `eval'
  genki.html.erb:4023:in `<main>': uninitialized constant DATA (NameError)

Is it possible to do this somehow?

W.

···

--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.


(Ralph Shnelvar) #2

Re: Is it possible to use END in .erb file?
Wolf,

(a) You probably want to ask this in

“Ruby on Rails: Talk” rubyonrails-talk@googlegroups.com

(b) Almost anything is possible in an .erb file. What are you trying to accomplish?

Ralph

Tuesday, July 31, 2018, 7:57:55 AM, you wrote:

**W> Hi,

I would love to use END / DATA in my .erb file (executed

via erb file.erb. I’ve tried

    <html>
            <head />
            <body>
                    <%= DATA %>
            </body>
    </html>
    <%
    __END__
    foobar

but that does not work

    Traceback (most recent call last):
            5: from /usr/bin/erb:170:in `<main>'
            4: from /usr/bin/erb:149:in `run'
            3: from /usr/lib/ruby/2.5.0/erb.rb:858:in `run'
            2: from /usr/lib/ruby/2.5.0/erb.rb:876:in `result'
            1: from /usr/lib/ruby/2.5.0/erb.rb:876:in `eval'
    genki.html.erb:4023:in `<main>': uninitialized constant DATA (NameError)

Is it possible to do this somehow?

W.

**Ralph


(Wolf) #3

(a) You probably want to ask this in
  "Ruby on Rails: Talk" <rubyonrails-talk@googlegroups.com>

I'm not sure what relation to rails is here. I'm using the
standalone `erb` executable that comes with ruby out-of-the-box.
Though I have no idea, is that something made by rails people?

Or do rails people just have more experience with this particular
executable?

(b) Almost anything is possible in an .erb file. What are you trying to
accomplish?

I'm trying to work around slow syntax highlighting in vim. It does not
really play nice with this long heredoc I have in my file (it's *really*
slow), so I thought moving it into __END__ could help with that.

But did not found a way to do it so far :confused:

W.

···

On , Ralph Shnelvar wrote:
--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.


(Andy Jones) #4

I'm trying to work around slow syntax highlighting in vim. It does not really play nice with this long heredoc I have in my file (it's *really* slow), so I thought moving it into __END__ could help with that.

Are you by any chance using jRuby? If you are, vim will use jRuby too, which might be slower. (It used to be a lot slower, but these days not so much).

If this is the cause of the slowness, try adding this to your .vimrc: "autocmd FileType ruby compiler ruby"

(At least I _think_ that was how I fixed it here. I've lost the note I made. But it's there in my .vimrc.)

Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer>

Please note that we have updated our privacy policy in line with new data protection regulations. Please refer to our website to view the ways in which we handle your data.


(Wolf) #5

Using MRI. I think it's more likely that it just does not like the fact
that the heredoc is 3.5k lines long...

W.

···

On , Andy Jones wrote:

Are you by any chance using jRuby? If you are, vim will use jRuby too, which might be slower. (It used to be a lot slower, but these days not so much).

If this is the cause of the slowness, try adding this to your .vimrc: "autocmd FileType ruby compiler ruby"

--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.


(Andy Jones) #6

Using MRI. I think it's more likely that it just does not like the fact that the heredoc is 3.5k lines long...

!!!!!

I can think of some other reasons to not do that. Does someone have to maintain this file?

Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer>

Please note that we have updated our privacy policy in line with new data protection regulations. Please refer to our website to view the ways in which we handle your data.


(Wolf) #7

Well, I do. But I don't think there are any maintainence as far as the
heredoc goes. What is a pain is syntax highlight being slow on that. So
I would like to move it into __END__ section (where it works just fine)
however cannot figure out how to do that in .erb file.

W.

···

On , Andy Jones wrote:

I can think of some other reasons to not do that. Does someone have to maintain this file?

--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.


(Jonathan Harden) #8

Hi Wolf,

I'm not sure I can help with the specific question, but as for slow syntax
highlighting in vim if you are on vim8 I could recommend moving to ALE. I
moved from syntastic to ALE since ALE is asynchronous, with syntastic when
I opened large files I had to wait while the linter was run before the file
would open, with ALE the file opens, and after a few moments the linter
hints appear, for me this feels a lot less like an interruption in my
workflow.

Ale home: https://github.com/w0rp/ale

Hope this helps

···

On Tue, 31 Jul 2018 at 18:42 Wolf <wolf@wolfsden.cz> wrote:

On , Andy Jones wrote:
> I can think of some other reasons to not do that. Does someone have to
maintain this file?

Well, I do. But I don't think there are any maintainence as far as the
heredoc goes. What is a pain is syntax highlight being slow on that. So
I would like to move it into __END__ section (where it works just fine)
however cannot figure out how to do that in .erb file.

W.
--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>


(Andy Jones) #9

Thinking outside the box here ... But you could move the contents of that heredoc to ... a separate file?

* Solves your highlighting problem

* You say the bit you need to maintain of that program is not the heredoc, so that would make maintenance easier.

···

-----Original Message-----
From: ruby-talk [mailto:ruby-talk-bounces@ruby-lang.org] On Behalf Of Wolf
Sent: 31 July 2018 18:42
To: Ruby users
Subject: Re: Is it possible to use __END__ in .erb file?

On , Andy Jones wrote:

I can think of some other reasons to not do that. Does someone have to maintain this file?

Well, I do. But I don't think there are any maintainence as far as the heredoc goes. What is a pain is syntax highlight being slow on that. So I would like to move it into __END__ section (where it works just fine) however cannot figure out how to do that in .erb file.

W.
--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer>

Please note that we have updated our privacy policy in line with new data protection regulations. Please refer to our website to view the ways in which we handle your data.


(Marvin Gülker) #10

ERB is not a normal Ruby file. I don't have insights into how the ERB
library processes RHTML (which is how the format is called), but it
certainly uses neither #require nor #load. Most likely something with
#eval, and #eval won't coöperate with __END__.

    irb(main):002:0> eval "p DATA.read\n__END__\nfoo"
    NameError: uninitialized constant DATA
    Did you mean? Data
      from (irb):2:in `eval'
      from (irb):2:in `eval'
      from (irb):2
      from /usr/bin/irb:11:in `<main>'
    irb(main):003:0>

That being said, the solution for your "problem" is:

1. Put the string in a seprate file and read the file in, or
2. Disable syntax highlighting in your editor for your ERB file.

I'm an Emacs user and don't know how to do 2), but I'm sure somebody
here on the list will give you a hint.

Marvin

···

Am 31. Juli 2018 um 19:42 Uhr +0200 schrieb Wolf:

Well, I do. But I don't think there are any maintainence as far as the
heredoc goes. What is a pain is syntax highlight being slow on that. So
I would like to move it into __END__ section (where it works just fine)
however cannot figure out how to do that in .erb file.

--
Blog: https://mg.guelker.eu
PGP/GPG ID: F1D8799FBCC8BC4F