Rails Plugins: How to copy artefacts to the public directory

Hi,

I want to write a plugin that uses JavaScript and I am wondering how to
put
the static content, i.e. the JavaScript, in place?

I read the documentation I found (
http://wiki.rubyonrails.org/rails/pages/Plugins and links) and looked at
the
listed plugins.

One thing I found was that subversion seems to be a prerequisite for
providing or even installing plugins. Is that right?

The other thing was that there were two plugins that provided content.
a)
Was providing a directory on the same level as the plugin itself, so I
guess
the author assumes the user would copy the content itself. B) The css
graph
plugin (http://nubyonrails.topfunky.com/pages/css_graphs) from Geoffrey
Grosenbach, provides an “images” directory in the plugin top level
directory
(http://topfunky.net/svn/plugins/css_graphs/). So I assumed that
script/plugin install would use this structure and put it below public.
But
this assumption is wrong:


DC:~/t2/testtest mkamp$ ./script/plugin install
http://topfunky.net/svn/plugins/css_graphs

A /Users/mkamp/t2/testtest/vendor/plugins/css_graphs
A /Users/mkamp/t2/testtest/vendor/plugins/css_graphs/images
A
/Users/mkamp/t2/testtest/vendor/plugins/css_graphs/images/colorbar.jpg
A /Users/mkamp/t2/testtest/vendor/plugins/css_graphs/init.rb
A /Users/mkamp/t2/testtest/vendor/plugins/css_graphs/lib
A
/Users/mkamp/t2/testtest/vendor/plugins/css_graphs/lib/css_graphs.rb
A /Users/mkamp/t2/testtest/vendor/plugins/css_graphs/MIT-LICENSE
A /Users/mkamp/t2/testtest/vendor/plugins/css_graphs/README
Exported revision 18.
DC:~/t2/testtest mkamp$ ls public/images/
rails.png

Is there no predefined way of doing this? And if not, what to do?

I started out using install.rb and just copy things over by hand. To
test
the general procedure I put the following in the install.rb:

puts IO.read(File.join(directory, ‘README’ ))

(I’ve seen that in the Rails Recipe to create your own plugin)… But
install.rb seems not to be called.


DC:~/t2/testtest mkamp$ script/plugin install svn+ssh://claudia-
und-mariano.net/repos/trunk/in_place_edit_associations
Password:
Password:
A /Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/test
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/test/in_place_edit_associations_test.rb
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/Rakefile
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/init.rb
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/tasks
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/tasks/in_place_edit_associations_tasks.rake
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/lib
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/lib/in_place_edit_associations.rb
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/install.rb
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/javascripts
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/javascripts/in_place_select_editor.js
A
/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/README
Exported revision 1.
DC:~/t2/testtest mkamp$

I am using rails_edge.

Cheers,
Mariano

script/plugin isn’t quite that clever unfortunately. There is another
plugin which provides static web assets (javascript/stylesheets) - the
UserEngine. In fact, any plugin developed as an engine (that is to
say, any plugin that includes an init_engine.rb file and is running on
a system which includes the Engines plugin) can provide static
content. Essentially, you just create a ‘public’ folder within your
plugin, and its contents are mirrored into the RAILS_ROOT/public
folder being used as the document root by your webserver.

I felt it was better to have the files automatically copied into the
main public directory rather than try and serve files directly from
within the plugin, since each directory that is exposed to the web
increases the chance of exposing sensitive parts of your filesystem to
the internet. Files are copied across each time your webserver is
started (each time environment.rb is loaded, to be precise), and only
copied if the source differs from the target.

If you want this functionality now, simply use the Engines plugin in
your application. At some point in the future this type of
functionality might make it into the core.

  • james

On 3/25/06, Mariano K. [email protected] wrote:

providing or even installing plugins. Is that right?

/Users/mkamp/t2/testtest/vendor/plugins/css_graphs/init.rb

/Users/mkamp/t2/testtest/vendor/plugins/in_place_edit_associations/test/in_place_edit_associations_test.rb
A
DC:~/t2/testtest mkamp$

  • J *
    ~

Hi James,

thank you for taking the time to answer.

I just finished watching your screencast on Rails Engines. Very
impressive.

Still, I only have a single file to copy, so I will go for the dumb
approach and implement the copy myself. To use Rails Engines would be a
bit
of an overkill for that particular feature.

As I gathered that install.rb doesn’t do anything I will implement the
copy in init.rb and copy the file over at every start, like you
described.

Cheers,
Mariano