Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Layouts and JavaScript
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  13 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Scott LaBounty  
View profile  
 More options Jun 5 2009, 8:32 am
From: Scott LaBounty <slabou...@gmail.com>
Date: Fri, 5 Jun 2009 05:32:20 -0700
Local: Fri, Jun 5 2009 8:32 am
Subject: Layouts and JavaScript

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:

@page_javascript = "page1.js"

and then in the layout do something like:

<script src="#@page_javascript" type="text/javascript"></script>

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.

--
Scott
http://steamcode.blogspot.com/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
james  
View profile  
 More options Jun 5 2009, 10:59 am
From: james <ja...@icionline.ca>
Date: Fri, 5 Jun 2009 07:59:35 -0700 (PDT)
Local: Fri, Jun 5 2009 10:59 am
Subject: Re: Layouts and JavaScript
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:

> @page_javascript = "page1.js"

> and then in the layout do something like:

> <script src="#@page_javascript" type="text/javascript"></script>

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.

James

James


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phrogz  
View profile  
 More options Jun 5 2009, 11:37 am
From: Phrogz <phr...@mac.com>
Date: Fri, 5 Jun 2009 08:37:11 -0700 (PDT)
Local: Fri, Jun 5 2009 11:37 am
Subject: Re: Layouts and JavaScript
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:

> @page_javascript = "page1.js"

> and then in the layout do something like:

> <script src="#@page_javascript" type="text/javascript"></script>

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 */
  ...

  /* category-specific */
  body.admin ...
  body.admin ...

  /* page-specific */
  body#login ...
  body#login ...

With jQuery, you can do the same thing by prefixing your selectors
that latch to objects the same say:

  $(function(){
    $('body#login #login_form').submit(function(){
      // ...
    });
  })


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott LaBounty  
View profile  
 More options Jun 5 2009, 6:40 pm
From: Scott LaBounty <slabou...@gmail.com>
Date: Fri, 5 Jun 2009 15:40:05 -0700
Local: Fri, Jun 5 2009 6:40 pm
Subject: Re: Layouts and JavaScript

Phrogz,

OK, that's pretty cool. Thanks for the tip.

Scott

--
Scott
http://steamcode.blogspot.com/

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jesusisramazing.10.pis...@geoshell.com  
View profile  
 More options Jun 5 2009, 10:56 am
From: jesusisramazing.10.pis...@geoshell.com
Date: Fri, 5 Jun 2009 10:56:01 -0400
Local: Fri, Jun 5 2009 10:56 am
Subject: Re: Layouts and JavaScript
2009/6/5 Scott LaBounty - slabou...@gmail.com:

> @page_javascript = "page1.js"

> and then in the layout do something like:

> <script src="#@page_javascript" type="text/javascript"></script>

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....>".

--
Pistos
http://blog.purepistos.net


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott LaBounty  
View profile  
 More options Jun 5 2009, 8:46 pm
From: Scott LaBounty <slabou...@gmail.com>
Date: Fri, 5 Jun 2009 17:46:33 -0700
Local: Fri, Jun 5 2009 8:46 pm
Subject: Re: Layouts and JavaScript

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?

Thanks again,

Scott

On Fri, Jun 5, 2009 at 7:56 AM, <jesusisramazing.10.pis...@geoshell.com>wrote:

--
Scott
http://steamcode.blogspot.com/

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Fellinger  
View profile  
 More options Jun 5 2009, 9:59 pm
From: Michael Fellinger <m.fellin...@gmail.com>
Date: Sat, 6 Jun 2009 10:59:09 +0900
Local: Fri, Jun 5 2009 9:59 pm
Subject: Re: Layouts and JavaScript

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?

It's from the XHTML helper:
http://github.com/manveru/ramaze/blob/master/lib/ramaze/helper/xhtml.rb
so you can use: #{ js_for(*@page_javascripts) }, and simply push the
ones that you need currently inside (of course you'll need to set
@page_javascripts).

--
^ manveru

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott LaBounty  
View profile  
 More options Jun 5 2009, 10:28 pm
From: Scott LaBounty <slabou...@gmail.com>
Date: Fri, 5 Jun 2009 19:28:45 -0700
Local: Fri, Jun 5 2009 10:28 pm
Subject: Re: Layouts and JavaScript

Cool! So to make sure I understand:

Controller:
page_javascripts = Array.new
page_javascripts << "page1_a.js"
page_javascritps << "page1_b.js"

View:
#{js_for(*@page_javascripts)}

Is that correct?

Scott

On Fri, Jun 5, 2009 at 6:59 PM, Michael Fellinger <m.fellin...@gmail.com>wrote:

--
Scott
http://steamcode.blogspot.com/

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott LaBounty  
View profile  
 More options Jun 6 2009, 9:40 pm
From: Scott LaBounty <slabou...@gmail.com>
Date: Sat, 6 Jun 2009 18:40:04 -0700
Local: Sat, Jun 6 2009 9:40 pm
Subject: Re: Layouts and JavaScript

Hmmm...

I put this:

        @page_javascript = "js/admin.js"

in the controller and this in the layout:

        <?r #{js(@page_javascript)} ?>

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

--
Scott
http://steamcode.blogspot.com/

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Fellinger  
View profile  
 More options Jun 6 2009, 9:46 pm
From: Michael Fellinger <m.fellin...@gmail.com>
Date: Sun, 7 Jun 2009 10:46:37 +0900
Local: Sat, Jun 6 2009 9:46 pm
Subject: Re: Layouts and JavaScript
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.

--
^ manveru

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott LaBounty  
View profile  
 More options Jun 6 2009, 10:41 pm
From: Scott LaBounty <slabou...@gmail.com>
Date: Sat, 6 Jun 2009 19:41:06 -0700
Local: Sat, Jun 6 2009 10:41 pm
Subject: Re: Layouts and JavaScript

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).

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'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/view/etanni.r b:30:in
`eval'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/view/etanni.r b:30:in
`result'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/view/etanni.r b:6:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:89: in
`block (2 levels) in render'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:97: in
`wrap_in_layout'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:89: in
`block in render'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/helper/aspect .rb:36:in
`aspect_wrap'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/helper/aspect .rb:87:in
`wrap_action_call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:84: in
`render'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:35: in
`block in call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:116 :in
`wrap_in_current'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:35: in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:107 :in
`wrap_in_layout'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:89: in
`block in render'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/helper/aspect .rb:36:in
`aspect_wrap'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/helper/aspect .rb:87:in
`wrap_action_call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:84: in
`render'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:35: in
`block in call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:116 :in
`wrap_in_current'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/action.rb:35: in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/node.rb:295:i n
`block (2 levels) in action_found'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/node.rb:295:i n
`catch'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/node.rb:295:i n
`block in action_found'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/node.rb:295:i n
`catch'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/node.rb:295:i n
`action_found'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/node.rb:279:i n
`try_resolve'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/node.rb:264:i n
`call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/urlmap.rb:46:in
`block in call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in
`each'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/dynamap.rb:40 :in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/route.rb:75:i n
`call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/cascade.rb:19:in
`block in call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/cascade.rb:17:in
`each'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/cascade.rb:17:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/current.rb:22 :in
`call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/cascade.rb:19:in
`block in call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/cascade.rb:17:in
`each'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/cascade.rb:17:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/ramaze-2009.06.04/lib/ramaze/app.rb:93: in
`call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/urlmap.rb:46:in
`block in call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in
`each'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/dynamap.rb:40 :in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/ramaze-2009.06.04/lib/ramaze/reloader.r b:88:in
`call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/head.rb:9:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/ramaze-2009.06.04/lib/vendor/etag.rb:11 :in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/conditionalget.rb:2 5:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/content_length.rb:1 3:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/ramaze-2009.06.04/lib/vendor/route_exce ptions.rb:22:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/showstatus.rb:20:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/showexceptions.rb:2 4:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/commonlogger.rb:20: in
`_call'

/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/commonlogger.rb:13: in
`call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/lint.rb:47:in
`_call'
    /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/lint.rb:35:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/innate-2009.06/lib/innate/middleware_co mpiler.rb:52:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/content_length.rb:1 3:in
`call'

/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.0.0/lib/rack/handler/webrick.rb: 46:in
`service'
    /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
    /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
    /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in
start_thread'

Thanks again for the help.

Scott

On Sat, Jun 6, 2009 at 6:46 PM, Michael Fellinger <m.fellin...@gmail.com>wrote:

--
Scott
http://steamcode.blogspot.com/

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Fellinger  
View profile  
 More options Jun 6 2009, 11:43 pm
From: Michael Fellinger <m.fellin...@gmail.com>
Date: Sun, 7 Jun 2009 12:43:39 +0900
Local: Sat, Jun 6 2009 11:43 pm
Subject: Re: Layouts and JavaScript

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.

--
^ manveru


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott LaBounty  
View profile  
 More options Jun 7 2009, 6:59 pm
From: Scott LaBounty <slabou...@gmail.com>
Date: Sun, 7 Jun 2009 15:59:09 -0700
Local: Sun, Jun 7 2009 6:59 pm
Subject: Re: Layouts and JavaScript

Michael,

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:

--
Scott
http://steamcode.blogspot.com/

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google