Is it possibile to create with ruby css file to write in public/stylesheets? Obviously the name of the css file is variable and the internal formatting is almost the same. Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Luigi wrote:> Is it possibile to create with ruby css file to write in > public/stylesheets? > Obviously the name of the css file is variable and the internal > formatting is almost the same. > > Thanks!File.open(pathname, mode) {block} : so i would do something like: filename = "name_of_css_file.css" css_file = File.open(RAILS_ROOT + ''public/stylesheets'' + filename, ''w'' ) { |f| f.puts "#someid { display: block; }/n" } for more info: http://www.rubycentral.com/book/html/tut_io.html check out the IO, File, FileUtils classes; they are what you are looking for. hope it helps, s -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
But in my Web ruby app directory where can I write the command lines? Thank you! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
you could create an create_css.rb file, place it in the lib/ directory,
and call it into any place where you want to use this method.
so you could do something like:
(UNTESTED CODE)
***** lib/create_css.rb ******
module CreateCss
# btw, this statement (file.open) returns nil
def make_css(filename, css_content)
File.open(RAILS_ROOT + ''public/stylesheets'' + filename,
''w'') { |f|
f.puts css_content }
end
end
and then, where ever in the app you want to do this (you could probably
even create the css_content with some form, and retrive it as params, or
whatever) just call the make_css method, and pass it the correct
parameters.
you''ll need to include the module, however.
example:
(UNTESTED CODE)
---------------------------------------------------------
require ''create_css.rb'' # includes the file
class SomeArbitraryController
include CreateCss # includes the specific module
...
...
# here you want to create the file:
def someaction
.... # do some stuff
make_css("a_new_css_file", params[:content_of_file])
... # continue doing some stuff
end
end
----------------------------------------------------------------
and walla! you should get a new file in your public folder:
public/stylesheets/a_new_css_file.css
and if you opened it and looked at the content, it would contain the
content of params[:content_of_file].
cheers,
--shai
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---
On 6/27/07, Luigi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Is it possibile to create with ruby css file to write in > public/stylesheets? > Obviously the name of the css file is variable and the internal > formatting is almost the same.Google for "dry up your css" for some approaches to this kind of thing --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---