Hi Everybody I was having a play around with the idea of embedding ruby inside my stylesheets - this could let you do things such as have variables or constants set at the top of your stylesheet which can then be used throughout. Not sure how useful everybody would find this, but this is what I have so far. What do people think of the idea, and is it something you think should be considered for a future Rails release (with a nice helper for inserting .rcss files the same as you can insert your regular stylesheets)? First of all, you need to have the file, erbcss.cgi - put this in your public folder and chmod +x: ---snip: erbcss.cgi--- #!/usr/local/bin/ruby require ''date'' require ''erb'' # set the content type print "Content-type: text/plain\n" # introduce some cache control and # ask the browser to cache for one hour expiry_date = Time.now.gmtime + 60*60 print "Cache-control: must-revalidate\n" print "Expires: " + expiry_date.strftime("%a, %d %b %Y %H:%M:%S GMT\n\n") # parse the file fh = File.open( ENV[''DOCUMENT_ROOT'']+ARGV[0] ) script = fh.read erb = ERB.new(script) fh.close # print the output print erb.result ---snip: erbcss.cgi--- Now you need to add the following to your .htaccess file: ---snip: .htaccess--- AddHandler rubystyle .rcss Action rubystyle /erbcss.cgi? ---snip: .htaccess--- Any .rcss files should now be parsed by the erbcss.cgi parser and cached for an hour. An example file: ---snip: example.rcss--- <% color_one = "red" color_two = "#FFF" %> /** example stylesheet **/ body { margin: 0; padding: 0; background: <%= color_one %>; } h1, p { color: <%= color_two %>; } ---snip: example.rcss--- Cheers, Luke
You can do this with rails in its current state. If you set your StylesController to send text/css, and you use page caching, this is simple solution. The only problem is your view will have a .rhtml extension. Joshua Sierles On 8/6/05, Luke Redpath <luke-lJ1peEkt3K8wCQPON/xxHQmknBWnwzYrtUK59QYPAWc@public.gmane.org> wrote:> > Hi Everybody > > I was having a play around with the idea of embedding ruby inside my > stylesheets - this could let you do things such as have variables or > constants set at the top of your stylesheet which can then be used > throughout. > > Not sure how useful everybody would find this, but this is what I have > so far. What do people think of the idea, and is it something you think > should be considered for a future Rails release (with a nice helper for > inserting .rcss files the same as you can insert your regular > stylesheets)? > > First of all, you need to have the file, erbcss.cgi - put this in your > public folder and chmod +x: > > ---snip: erbcss.cgi--- > #!/usr/local/bin/ruby > require ''date'' > require ''erb'' > > # set the content type > print "Content-type: text/plain\n" > > # introduce some cache control and > # ask the browser to cache for one hour > expiry_date = Time.now.gmtime + 60*60 > print "Cache-control: must-revalidate\n" > print "Expires: " + > expiry_date.strftime("%a, %d %b %Y %H:%M:%S GMT\n\n") > > # parse the file > fh = File.open( ENV[''DOCUMENT_ROOT'']+ARGV[0] ) > script = fh.read > erb = ERB.new(script) > fh.close > > # print the output > print erb.result > ---snip: erbcss.cgi--- > > Now you need to add the following to your .htaccess file: > > ---snip: .htaccess--- > AddHandler rubystyle .rcss > Action rubystyle /erbcss.cgi? > ---snip: .htaccess--- > > Any .rcss files should now be parsed by the erbcss.cgi parser and cached > for an hour. > > An example file: > > ---snip: example.rcss--- > <% > color_one = "red" > color_two = "#FFF" > %> > > /** example stylesheet **/ > body { > margin: 0; padding: 0; > background: <%= color_one %>; > } > h1, p { > color: <%= color_two %>; > } > ---snip: example.rcss--- > > Cheers, > Luke > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Aug 6, 2005, at 10:12 AM, Joshua Sierles wrote:> You can do this with rails in its current state. If you set your > StylesController to send text/css, and you use page caching, this > is simple solution. The only problem is your view will have > a .rhtml extension. >Do you mean "your css will have a .rhtml extension"?> Joshua Sierles >Thanks to both you and Luke for showing this on the list--I''d wondered if there was an easy solution or not. Duane Johnson (canadaduane)
Funny the things you think are obvious - this was the first thing I did with Rails. You can see a rather clever example of this plus a nice way to store CSS rules on this patch from the up-and-coming rails superstar Tuxxxie: http://dev.rubyonrails.org/ticket/1883 Incidentally, doing this gives you a whole slew of easy ways to tackle hard problems such as ours: displaying a shop in right-to-left and left-to-right languages, and flipping over the whole css-based layout. Joshua Sierles On 8/6/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Aug 6, 2005, at 10:12 AM, Joshua Sierles wrote: > > > You can do this with rails in its current state. If you set your > > StylesController to send text/css, and you use page caching, this > > is simple solution. The only problem is your view will have > > a .rhtml extension. > > > > Do you mean "your css will have a .rhtml extension"? > > > > Joshua Sierles > > > > Thanks to both you and Luke for showing this on the list--I''d > wondered if there was an easy solution or not. > > Duane Johnson > (canadaduane) > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi all, I have some problems with the :protocol and :host parameters of url_for etc.: To switch between http and https after a user login, I first tried the following (in the login form): start_form_tag ({:action => ''login'', :only_path => true, :protocol => ''https://'', :host => ''someDomain''}) The action of the form was nevertheless rendered as "/user/login". Then I tried the same in the redirect of the controller login method: redirect_to :controller => ''folders'', :only_path => true, :protocol => ''https://'', :host => ''someDomain'' - but to no avail either. Again, the url was rendered simply as "/folders". I am I doing something wrong here, or are the parameters not working correctly? Or would you recommend another method of protocol switching altogether? Thanks for any help! Wolfgang
Hi all, I have some problems with the :protocol and :host parameters of url_for etc.: To switch between http and https after a user login, I first tried the following (in the login form): start_form_tag ({:action => ''login'', :only_path => true, :protocol => ''https://'', :host => ''someDomain''}) The action of the form was nevertheless rendered as "/user/login". Then I tried the same in the redirect of the controller login method: redirect_to :controller => ''folders'', :only_path => true, :protocol => ''https://'', :host => ''someDomain'' - but to no avail either. Again, the url was rendered simply as "/folders". I am I doing something wrong here, or are the parameters not working correctly? Or would you recommend another method of protocol switching altogether? Thanks for any help! Wolfgang
On 28.10.2005, at 13.37, Wolfgang Wopperer wrote:> Hi all, > > I have some problems with the :protocol and :host parameters of > url_for > etc.: > > To switch between http and https after a user login, I first tried the > following (in the login form): > > start_form_tag ({:action => ''login'', :only_path => true, :protocol => > ''https://'', :host => ''someDomain''}) > > The action of the form was nevertheless rendered as "/user/login". > Then I > tried the same in the redirect of the controller login method: > > redirect_to :controller => ''folders'', :only_path => true, :protocol => > ''https://'', :host => ''someDomain'' > > - but to no avail either. Again, the url was rendered simply as "/ > folders". > > I am I doing something wrong here, or are the parameters not working > correctly? Or would you recommend another method of protocol switching > altogether?Setting :only_path to true will result in the exact behavior you describe. Try setting it to false. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks a lot - it works fine now. I thought that :path_only => true would be a prerequisite to provide a custom protocol and host, but now I see it''s exactly the opposite. Wolfgang> -----Ursprungliche Nachricht----- > Von: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]Im Auftrag von Jarkko Laine > Gesendet: Freitag, 28. Oktober 2005 12:44 > An: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Betreff: Re: [Rails] :protocol and :host parameters ineffectual > > > On 28.10.2005, at 13.37, Wolfgang Wopperer wrote: > > > Hi all, > > > > I have some problems with the :protocol and :host parameters of > > url_for > > etc.: > > > > To switch between http and https after a user login, I first tried the > > following (in the login form): > > > > start_form_tag ({:action => ''login'', :only_path => true, :protocol => > > ''https://'', :host => ''someDomain''}) > > > > The action of the form was nevertheless rendered as "/user/login". > > Then I > > tried the same in the redirect of the controller login method: > > > > redirect_to :controller => ''folders'', :only_path => true, :protocol => > > ''https://'', :host => ''someDomain'' > > > > - but to no avail either. Again, the url was rendered simply as "/ > > folders". > > > > I am I doing something wrong here, or are the parameters not working > > correctly? Or would you recommend another method of protocol switching > > altogether? > > Setting :only_path to true will result in the exact behavior you > describe. Try setting it to false. > > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > >