Would this be the way to do something like this? I realized in my last post that I had included some javascript for a single page in the layout and that probably wasn't the right thing to do.
Can't <script></script> tags be added anywhere? They shouldn't have
to be at the top of your layout. You could place page specific
javascript between <script></script> tags at the bottom of the view
perhaps.
If you have page specific javascript, and it isn't a boat-load of js,
then perhaps just include it on all pages. It'll get cached anyway.
Look at how large jquery is, and people include that site-wide!
Sorry if I'm mis-understanding what you're trying to do. Hope this
helps.
I've done this myself in the past. I've also done the following:
For page-specific CSS, instead of separate CSS sheets, I have this in
my layout:
<body id="<%=@page_id%>" class="<%=page_class%>">
where the id is usually the action and the class I set commonly
amongst similar pages. Then I have a single CSS file that's a little
bigger, but cached, with content like:
/* common css */
...
On Fri, Jun 5, 2009 at 8:37 AM, Phrogz <phr...@mac.com> wrote:
> On Jun 5, 6:32 am, Scott LaBounty <slabou...@gmail.com> wrote:
> > What's the best way to include page specific JavaScript in a layout. My
> > thought was in the controller do something along the lines of:
> I've done this myself in the past. I've also done the following:
> For page-specific CSS, instead of separate CSS sheets, I have this in
> my layout:
> <body id="<%=@page_id%>" class="<%=page_class%>">
> where the id is usually the action and the class I set commonly
> amongst similar pages. Then I have a single CSS file that's a little
> bigger, but cached, with content like:
> /* common css */
> ...
I haven't tried it, but that looks like it should work. But see also the "js" method, as exemplified in the prototype given with "ramaze create". It's a shortcut to make "<script src....>".
Thanks, but I'm not exactly sure what you mean here. Do you mean when you do
a ramaze --create (I haven't used that before, I normally just build by hand
for my simple examples)? Can you point me to some documentation?
Thanks again,
Scott
On Fri, Jun 5, 2009 at 7:56 AM, <jesusisramazing.10.pis...@geoshell.com>wrote:
> I haven't tried it, but that looks like it should work. But see also
> the "js" method, as exemplified in the prototype given with "ramaze
> create". It's a shortcut to make "<script src....>".
On Sat, Jun 6, 2009 at 9:46 AM, Scott LaBounty<slabou...@gmail.com> wrote: > Pistos,
> Thanks, but I'm not exactly sure what you mean here. Do you mean when you do > a ramaze --create (I haven't used that before, I normally just build by hand > for my simple examples)? Can you point me to some documentation?
>> I haven't tried it, but that looks like it should work. But see also >> the "js" method, as exemplified in the prototype given with "ramaze >> create". It's a shortcut to make "<script src....>".
> On Sat, Jun 6, 2009 at 9:46 AM, Scott LaBounty<slabou...@gmail.com> wrote:
> > Pistos,
> > Thanks, but I'm not exactly sure what you mean here. Do you mean when you
> do
> > a ramaze --create (I haven't used that before, I normally just build by
> hand
> > for my simple examples)? Can you point me to some documentation?
> >> I haven't tried it, but that looks like it should work. But see also
> >> the "js" method, as exemplified in the prototype given with "ramaze
> >> create". It's a shortcut to make "<script src....>".
It looks like my layout stop processing at that point. I get a blank screen
and if I look at the source, I see the line before the <?r code there but
nothing following.
> On Fri, Jun 5, 2009 at 6:59 PM, Michael Fellinger <m.fellin...@gmail.com>wrote:
>> On Sat, Jun 6, 2009 at 9:46 AM, Scott LaBounty<slabou...@gmail.com>
>> wrote:
>> > Pistos,
>> > Thanks, but I'm not exactly sure what you mean here. Do you mean when
>> you do
>> > a ramaze --create (I haven't used that before, I normally just build by
>> hand
>> > for my simple examples)? Can you point me to some documentation?
>> >> I haven't tried it, but that looks like it should work. But see also
>> >> the "js" method, as exemplified in the prototype given with "ramaze
>> >> create". It's a shortcut to make "<script src....>".
> It looks like my layout stop processing at that point. I get a blank > screen and if I look at the source, I see the line before the <?r > code there but nothing following.
> Any ideas?
> Scott
> On Fri, Jun 5, 2009 at 7:28 PM, Scott LaBounty <slabou...@gmail.com> > wrote:
> > On Fri, Jun 5, 2009 at 6:59 PM, Michael Fellinger > > <m.fellin...@gmail.com>wrote:
> >> On Sat, Jun 6, 2009 at 9:46 AM, Scott LaBounty<slabou...@gmail.com> > >> wrote: > >> > Pistos,
> >> > Thanks, but I'm not exactly sure what you mean here. Do you mean > >> > when > >> you do > >> > a ramaze --create (I haven't used that before, I normally just > >> > build by > >> hand > >> > for my simple examples)? Can you point me to some documentation?
> >> >> I haven't tried it, but that looks like it should work. But > >> >> see also the "js" method, as exemplified in the prototype given > >> >> with "ramaze create". It's a shortcut to make "<script > >> >> src....>".
I'm not sure I understand why what I had earlier would start a comment. If
you have a moment, perhaps you could explain a bit more (I'm probably
missing something obvious).
Anyway ... now I get:
NoMethodError at / undefined method `js' for #<MainController:0x9242b70>
Ruby /home/slabounty/RamazeTutorial/Poll/layout/page.xhtml: in binding, line
17 Web GET localhost/
and the following stack trace:
NoMethodError: undefined method `js' for #<MainController:0x9242b70>
/home/slabounty/RamazeTutorial/Poll/layout/page.xhtml:17:in `binding'
> On Sat, 6 Jun 2009 18:40:04 -0700
> Scott LaBounty <slabou...@gmail.com> wrote:
> > Hmmm...
> > I put this:
> > @page_javascript = "js/admin.js"
> > in the controller and this in the layout:
> > <?r #{js(@page_javascript)} ?>
> #{ js @page_javascript }
> the <?r #{ ?> will start a comment, which will mess up the rest of the
> template
> evaluation.
> > It looks like my layout stop processing at that point. I get a blank
> > screen and if I look at the source, I see the line before the <?r
> > code there but nothing following.
> > Any ideas?
> > Scott
> > On Fri, Jun 5, 2009 at 7:28 PM, Scott LaBounty <slabou...@gmail.com>
> > wrote:
> > > On Fri, Jun 5, 2009 at 6:59 PM, Michael Fellinger
> > > <m.fellin...@gmail.com>wrote:
> > >> On Sat, Jun 6, 2009 at 9:46 AM, Scott LaBounty<slabou...@gmail.com>
> > >> wrote:
> > >> > Pistos,
> > >> > Thanks, but I'm not exactly sure what you mean here. Do you mean
> > >> > when
> > >> you do
> > >> > a ramaze --create (I haven't used that before, I normally just
> > >> > build by
> > >> hand
> > >> > for my simple examples)? Can you point me to some documentation?
> > >> >> I haven't tried it, but that looks like it should work. But
> > >> >> see also the "js" method, as exemplified in the prototype given
> > >> >> with "ramaze create". It's a shortcut to make "<script
> > >> >> src....>".
On Sun, Jun 7, 2009 at 11:41 AM, Scott LaBounty<slabou...@gmail.com> wrote: > Michael,
> I'm not sure I understand why what I had earlier would start a comment. If > you have a moment, perhaps you could explain a bit more (I'm probably > missing something obvious).
<?r ?> is transformed via: .gsub!(/<\?r\s+(.*?)\s+\?>/m, "#{STOP} \\1; #{ADD} #{START}")
e = Etanni.new('hi there <?r #{foo} ?> bar') puts e.compile
Will result in:
_out_ = <<E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82.chomp hi there E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82 #{foo}; _out_ << <<E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82.chomp bar E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82 _out_
As you can see, the #{foo} simply starts a commented line, so the following heredoc is dropped, if there are no more <?r ?> afterward, nothing from what follows will be show anymore. As a general rule, don't use comments inside the ruby processing instructions. You want output, so use proper string interpolation:
e = Etanni.new('hi there #{foo} bar') puts e.compile
Will result in:
_out_ = <<E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82.chomp hi there #{foo} bar E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82 _out_
And "hi there #{foo} bar" will properly interpolate in the following eval. Etanni is a very simple templating engine, if you don't understand what i just wrote, read the source (all 4 lines of it), and learn, or stop using this undocumented, obscure, and hardly used engine, and use something like ERB which gives you <%# %> to make comments, <%= %> for interpolation, and <% %> for ruby, no confusing interpolation.
> Anyway ... now I get:
> NoMethodError at /
> undefined method `js' for #<MainController:0x9242b70>
Because it's a helper, you have to use helper(:xhtml) in your controller before using it.
OK, I don't understand everything you wrote, but I did clue in as to why
what I was trying to do wouldn't work.
Putting in the helper(:xhtml) made everything work fine.
I suppose I could start using ERB (or one of the others), but one of the
things that moved me to Ramaze in the first place was the simplicity. For
what I'm trying to accomplish (learning a bit about web programming, sharing
with others what I've learned), Ramaze is pretty much perfect. I'm not sure
I need a bigger templating engine, probably just need to learn the four
lines of code so that I understand what's in there better.
Thanks for taking the time to help,
Scott
On Sat, Jun 6, 2009 at 8:43 PM, Michael Fellinger <m.fellin...@gmail.com>wrote:
> On Sun, Jun 7, 2009 at 11:41 AM, Scott LaBounty<slabou...@gmail.com>
> wrote:
> > Michael,
> > I'm not sure I understand why what I had earlier would start a comment.
> If
> > you have a moment, perhaps you could explain a bit more (I'm probably
> > missing something obvious).
> e = Etanni.new('hi there <?r #{foo} ?> bar')
> puts e.compile
> Will result in:
> _out_ =
> <<E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82.chomp
> hi there
> E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82
> #{foo}; _out_ <<
> <<E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82.chomp
> bar
> E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82
> _out_
> As you can see, the #{foo} simply starts a commented line, so the
> following heredoc is dropped, if there are no more <?r ?> afterward,
> nothing from what follows will be show anymore. As a general rule,
> don't use comments inside the ruby processing instructions. You want
> output, so use proper string interpolation:
> e = Etanni.new('hi there #{foo} bar')
> puts e.compile
> Will result in:
> _out_ =
> <<E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82.chomp
> hi there #{foo} bar
> E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82
> _out_
> And "hi there #{foo} bar" will properly interpolate in the following eval.
> Etanni is a very simple templating engine, if you don't understand
> what i just wrote, read the source (all 4 lines of it), and learn, or
> stop using this undocumented, obscure, and hardly used engine, and use
> something like ERB which gives you <%# %> to make comments, <%= %> for
> interpolation, and <% %> for ruby, no confusing interpolation.
> > Anyway ... now I get:
> > NoMethodError at /
> > undefined method `js' for #<MainController:0x9242b70>
> Because it's a helper, you have to use helper(:xhtml) in your
> controller before using it.