I want to use the same controller for every javascript file...so I was
thinking something like this? What I''m not sure of is what to pass to
File.read.
class Javascript < R ''/*.js''
JS = File.read()
def get
@headers[''Content-Type''] = ''text/javascript;
charset=utf-8''
JS
end
end
Is there a better way to do this? I was looking at adam''s project:
https://github.com/minikomi/tokyoartparties/blob/master/src/Drinking.rb
and I didn''t see a controller for his css, so I''m kind of
wondering
how he does it...
Thanks,
-Tony
class LoadScript < R ''/(.*).js''
def get(script)
@headers[''Content-Type''] = ''text/javascript;
charset=utf-8''
return File.read("my scripts/#{script}.js");
end
end
Keep in mind the R constructor takes a regexp, and passes the bracketed sections
as arguments to the get, post, put, etc... methods on the class when called.
?Jenna / @Bluebie
On Thursday, 10 February 2011 at 11:54 AM, Tony Miller wrote:
> I want to use the same controller for every javascript file...so I was
> thinking something like this? What I''m not sure of is what to pass
to
> File.read.
>
> class Javascript < R ''/*.js''
> JS = File.read()
> def get
> @headers[''Content-Type''] = ''text/javascript;
charset=utf-8''
> JS
> end
> end
>
> Is there a better way to do this? I was looking at adam''s project:
> https://github.com/minikomi/tokyoartparties/blob/master/src/Drinking.rb
> and I didn''t see a controller for his css, so I''m kind of
wondering
> how he does it...
>
> Thanks,
> -Tony
> _______________________________________________
> Camping-list mailing list
> Camping-list at rubyforge.org
> http://rubyforge.org/mailman/listinfo/camping-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/camping-list/attachments/20110210/02307970/attachment-0001.html>
Thanks Jenna, this works great! I think I understand how the R constructor works a little more now... On Wed, Feb 9, 2011 at 5:23 PM, Jenna Fox <a at creativepony.com> wrote:> class LoadScript < R ''/(.*).js'' > def get(script) > @headers[''Content-Type''] = ''text/javascript; charset=utf-8'' > return File.read("my scripts/#{script}.js"); > end > end > Keep in mind the R constructor takes a regexp, and passes the bracketed > sections as arguments to the get, post, put, etc... methods on the class > when called. > > ? > Jenna / @Bluebie > > On Thursday, 10 February 2011 at 11:54 AM, Tony Miller wrote: > > I want to use the same controller for every javascript file...so I was > thinking something like this? What I''m not sure of is what to pass to > File.read. > > class Javascript < R ''/*.js'' > JS = File.read() > def get > @@headers[''Content-Type''] = ''text/javascript; charset=utf-8'' > JS > end > end > > Is there a better way to do this? I was looking at adam''s project: > https://github.com/minikomi/tokyoartparties/blob/master/src/Drinking.rb > and I didn''t see a controller for his css, so I''m kind of wondering > how he does it... > > Thanks, > -Tony > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >
Glad I could help. :) ?Jenna / @Bluebie On Thursday, 10 February 2011 at 2:53 PM, Tony Miller wrote:> Thanks Jenna, this works great! I think I understand how the R > constructor works a little more now... > > On Wed, Feb 9, 2011 at 5:23 PM, Jenna Fox <a at creativepony.com> wrote: > > class LoadScript < R ''/(.*).js'' > > def get(script) > > @headers[''Content-Type''] = ''text/javascript; charset=utf-8'' > > return File.read("my scripts/#{script}.js"); > > end > > end > > Keep in mind the R constructor takes a regexp, and passes the bracketed > > sections as arguments to the get, post, put, etc... methods on the class > > when called. > > > > ? > > Jenna / @Bluebie > > > > On Thursday, 10 February 2011 at 11:54 AM, Tony Miller wrote: > > > > I want to use the same controller for every javascript file...so I was > > thinking something like this? What I''m not sure of is what to pass to > > File.read. > > > > class Javascript < R ''/*.js'' > > JS = File.read() > > def get > > @@headers[''Content-Type''] = ''text/javascript; charset=utf-8'' > > JS > > end > > end > > > > Is there a better way to do this? I was looking at adam''s project: > > https://github.com/minikomi/tokyoartparties/blob/master/src/Drinking.rb > > and I didn''t see a controller for his css, so I''m kind of wondering > > how he does it... > > > > Thanks, > > -Tony > > _______________________________________________ > > Camping-list mailing list > > Camping-list at rubyforge.org > > http://rubyforge.org/mailman/listinfo/camping-list > > > > > > _______________________________________________ > > Camping-list mailing list > > Camping-list at rubyforge.org > > http://rubyforge.org/mailman/listinfo/camping-list > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/camping-list/attachments/20110210/8526b6d5/attachment.html>
On 10.02.2011 02:23, Jenna Fox wrote:> class LoadScript < R ''/(.*).js'' > def get(script) > @headers[''Content-Type''] = ''text/javascript; charset=utf-8'' > return File.read("my scripts/#{script}.js"); > end > endremember [http://en.wikipedia.org/wiki/Directory_traversal] ? even if you accor access to just .js files it?s not good practice to use ?script? unchecked. ? Matthias