Rails people,
Suppose I have an HTML file in public/ :
<html>
I am static.html
</html>
And suppose I have a layout file in app/views/layouts/ :
<html>
<table>
<tr>I am layout_for_static.rhtml </tr>
<tr><%= @content_for_layout %> </tr>
</table>
</html>
I''m trying to figure out a way to get the static
file to act as a template so that I get it loaded
into @content_for_layout
Anyone have any thoughts on this ?
I''m thinking I need to write a before_filter in application.rb
and maybe work a bit with config/routes.rb
Anyone have any thoughts on this ?
-Dan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
The statement,
You simply cannot have anything in /public that needs rails interaction.
is of great help.
So, my approach will probably be:
script/generate controller serve_static
Then tar-copy my tree of static .html, .htm, .txt, .jpg, .gif ...
to:
app/views/serve_static
Then put this in
config/routes.rb :
# You can have the root of your site routed by hooking up ''''
# -- just remember to delete public/index.html.
map.connect '''', :controller => "serve_static"
Next, I need to figure out how to deal with an arbitrary URL.
For example:
/I/am/just_some/page.txt
/me/too.html
/ya/Im/a/picture.jpg
/mr/htm/here.htm
/Iam/just/slash/so/call/indexhtml/
/Im/not/even/slash
I know that I''ll have access to
request.request_uri
So, I''m smelling a case statement with 8 whens
based on
.txt
.html
.jpg
.gif
.png
.htm
/
""
Let''s say I know that I want to render a .txt file,
how do I actually render it?
I guess I should take a close look at render()
or any of its cousins.
Any thoughts anyone?
Thanks!
-Dan
---------- Forwarded message ----------
From: Dan Bikle <dan.bikle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Sep 18, 2006 1:39 PM
Subject: Layout for static pages?
To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Rails people,
Suppose I have an HTML file in public/ :
<html>
I am static.html
</html>
And suppose I have a layout file in app/views/layouts/ :
<html>
<table>
<tr>I am layout_for_static.rhtml </tr>
<tr><%= @content_for_layout %> </tr>
</table>
</html>
I''m trying to figure out a way to get the static
file to act as a template so that I get it loaded
into @content_for_layout
Anyone have any thoughts on this ?
I''m thinking I need to write a before_filter in application.rb
and maybe work a bit with config/routes.rb
Anyone have any thoughts on this ?
-Dan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
ok,
I wrote something that is about 80% there.
idea 1:
script/generate controller serve_static index
2:
copy all the static content here:
app/views/serve_static
3:
add a line to the END of routes.rb
map.connect ''*anything'', :controller =>
"serve_static" , :action =>
''index''
4.
Edit index()
inside of
app/controllers/serve_static_controller.rb
All the info I need is inside of request.request_uri
Just two lines gets me 50% there:
def index
the_file_name = ''serve_static'' + request.request_uri
render(:file => the_file_name, :layout => true, :use_full_path
=>true,
:content_type => "text/html")
end
5.
Get more elaborate:
-look at file suffixes to guess about content_type: jpg, txt, html, xml...
-rescue if I make a bad assumption about file existence
Result:
class ServeStaticController < ApplicationController
def index
logger.info ''request.request_uri is ''
logger.info request.request_uri.inspect
# get the file name from the request_uri
the_file_name = ''serve_static'' + request.request_uri
logger.info ''the_file_name is ''
logger.info the_file_name
# Look for something like this:
# /some/path//gna.rl-e_y#%jnk/-/file.whatever
# We want to know if whatever exists and if so, what it is.
regexp = /(^\/.+)(\.\w+$)/
the_match = regexp.match request.request_uri
logger.info ''the_match.to_a.inspect is ''
logger.info the_match.to_a.inspect
case
when the_match.to_a[2] == nil
# No file extension so maybe we have index.html there
begin
render(:file => the_file_name + ''/index.html'' ,
:layout => true,
:use_full_path =>true)
rescue
# If nothing there, just render index.rhtml
render
end
else
logger.info ''the suffix is '' + the_match.to_a[2]
begin
case
when the_match.to_a[2] == ''.jpg''
render(:file => the_file_name, :layout => false, :use_full_path
=>true, :content_type => "image/jpg")
when the_match.to_a[2] == ''.gif''
render(:file => the_file_name, :layout => false, :use_full_path
=>true, :content_type => "image/gif")
when the_match.to_a[2] == ''.png''
render(:file => the_file_name, :layout => false, :use_full_path
=>true, :content_type => "image/png")
when the_match.to_a[2] == ''.txt''
render(:file => the_file_name, :layout => true, :use_full_path
=>true, :content_type => "text/text")
when the_match.to_a[2] == ''.xml''
render(:file => the_file_name, :layout => true, :use_full_path
=>true, :content_type => "text/xml")
else
render(:file => the_file_name, :layout => true, :use_full_path
=>true, :content_type => "text/html")
end
rescue
# If nothing there, just render index.rhtml
render
end
end
end
end
On 9/18/06, Dan Bikle <dan.bikle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> The statement,
>
>
> You simply cannot have anything in /public that needs rails interaction.
>
> is of great help.
>
> So, my approach will probably be:
>
> script/generate controller serve_static
>
> Then tar-copy my tree of static .html, .htm, .txt, .jpg, .gif ...
> to:
> app/views/serve_static
>
> Then put this in
> config/routes.rb :
>
>
> # You can have the root of your site routed by hooking up
''''
> # -- just remember to delete public/index.html.
> map.connect '''', :controller =>
"serve_static"
>
> Next, I need to figure out how to deal with an arbitrary URL.
>
> For example:
>
> /I/am/just_some/page.txt
> /me/too.html
> /ya/Im/a/picture.jpg
> /mr/htm/here.htm
> /Iam/just/slash/so/call/indexhtml/
> /Im/not/even/slash
>
> I know that I''ll have access to
> request.request_uri
>
> So, I''m smelling a case statement with 8 whens
> based on
> .txt
> .html
> .jpg
> .gif
> .png
> .htm
> /
> ""
>
> Let''s say I know that I want to render a .txt file,
> how do I actually render it?
>
> I guess I should take a close look at render()
> or any of its cousins.
>
> Any thoughts anyone?
>
>
> Thanks!
>
> -Dan
>
>
> ---------- Forwarded message ----------
> From: Dan Bikle <dan.bikle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Date: Sep 18, 2006 1:39 PM
> Subject: Layout for static pages?
> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>
> Rails people,
>
> Suppose I have an HTML file in public/ :
>
> <html>
> I am static.html
> </html>
>
> And suppose I have a layout file in app/views/layouts/ :
>
> <html>
> <table>
> <tr>I am layout_for_static.rhtml </tr>
> <tr><%= @content_for_layout %> </tr>
> </table>
> </html>
>
> I''m trying to figure out a way to get the static
> file to act as a template so that I get it loaded
> into @content_for_layout
>
> Anyone have any thoughts on this ?
>
> I''m thinking I need to write a before_filter in application.rb
> and maybe work a bit with config/routes.rb
>
> Anyone have any thoughts on this ?
>
> -Dan
>
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
"Dan Bikle" wrote> > I wrote something that is about 80% there. >[snip] Just curious. Why would one want to do this? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
My end-users can write simple HTML and .txt files . They want me to supply layouts, and other webmaster skills. On 9/19/06, Long <long755-bJEeYj9oJeDQT0dZR+AlfA@public.gmane.org> wrote:> > > "Dan Bikle" wrote > > > > I wrote something that is about 80% there. > > > [snip] > > Just curious. Why would one want to do this? > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
One note - it may be a little icky, but you could revert back to the old-style idea of server-side includes for layouts, using ERB directly. Check out this http://www.brainbag.net/blog/articles/2005/12/22/using-erb-rhtml-templates-on-dreamhost for an idea of how to make it work. Essentially, you would use ERB in the files in /public to include headers/footers on the page. Getting shtml and PHP flashbacks.. On 9/19/06, Dan Bikle <dan.bikle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > My end-users can write simple HTML and .txt files . > They want me to supply layouts, and other webmaster skills. > > > On 9/19/06, Long < long755-bJEeYj9oJeDQT0dZR+AlfA@public.gmane.org> wrote: > > > > > > "Dan Bikle" wrote > > > > > > I wrote something that is about 80% there. > > > > > [snip] > > > > Just curious. Why would one want to do this? > > > > > > > >-- Matt Jones mdj.acme-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org President/Technical Director, Acme Art Company (acmeartco.org) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---