List Info

Thread: Write file




Write file
country flaguser name
Germany
2007-06-27 11:23:21
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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Write file
country flaguser name
Germany
2007-06-28 03:25:22
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)  :

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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Write file
country flaguser name
Germany
2007-06-28 06:59:43
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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Write file
country flaguser name
Germany
2007-06-28 08:40:22
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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )