JavaScript in Refinery Plugin

258 views
Skip to first unread message

flp

unread,
Sep 10, 2012, 5:56:28 PM9/10/12
to refine...@googlegroups.com
I have a js.coffee file, which seems not to be activated. In my form happens nothing, if i click the link, and so I think, i have to activate it. But I'm not sure, where i have to activate it in Refinery, when you use it in a plugin. Hopefully you can help me.

flp

Martin Markech

unread,
Sep 12, 2012, 10:42:47 AM9/12/12
to refine...@googlegroups.com
Use browser webmaster tools like Opera Dragonfly or Firebug  - network tab - to see, if your file returns 404 not found. 

If you need to autoload your js file in refinery backend, add path to it in your_app/config/initializers/refinery/core.rb file,  at the end of file:
config.register_stylesheet "folder/your_file"

If you have own engine and you want to autoload that js file in backend, create file core.rb under your_engine/config/initializers/refinery/ 
# Example for multiple JS/css files
Refinery::Core.configure do |config|
# Register extra javascript for backend
config.register_javascript "refinery/photo_gallery/admin/photo_gallery.js"
config.register_javascript "refinery/photo_gallery/admin/jquery.chosen.min.js"

#Register extra stylesheet for backend (optional options)
config.register_stylesheet "refinery/photo_gallery/admin/photo_gallery.css"
  config.register_stylesheet "refinery/photo_gallery/admin/chosen.css"
end

Hope, it helps you.

flp

unread,
Sep 13, 2012, 12:14:22 PM9/13/12
to refine...@googlegroups.com
Hey,

thank you for the answer.

Now it returns a 404 not found.

So its possible to register a js.coffee file? If I change the ending to js.coffee, it searchs a js.coffee.js file :(.

If I add the code to the core.rb of my engine, it searchs through the refinery always in the javascript directory of refinery and not in the directory of my app.

flp

Uģis Ozols

unread,
Sep 13, 2012, 3:00:40 PM9/13/12
to refine...@googlegroups.com
Hey,

Currently it's not possible to register js.coffee file because https://github.com/refinery/refinerycms/blob/master/core/app/views/refinery/admin/_javascripts.html.erb#L9-11 uses javascript_include_tag to include all registered files so it appends .js to each of those files.

You should probably open a ticket at https://github.com/refinery/refinerycms/issues.

flp

unread,
Sep 13, 2012, 3:32:45 PM9/13/12
to refine...@googlegroups.com
Ok, but can I change the path of the file to a path of the engine? I tried it, but it searched every time in javascript directory of refinery and not from the engine

Uģis Ozols

unread,
Sep 14, 2012, 1:53:21 AM9/14/12
to refine...@googlegroups.com
Let's pretend I have an engine called cars. In cars/app/assets/javascripts folder I have a file cars.js. To register this file I need to add config.register_javascript("cars") in core initializer and it will show up in the Refinery backend.

flp

unread,
Sep 14, 2012, 1:27:02 PM9/14/12
to refine...@googlegroups.com
Unfortunately not at me.

My core file is located in extensions/calendars/config/initializers/refinery/core.rb with the following code:

Refinery::Core.configure do |config|
  config.register_javascript "calendars"
end

My Js file is located in extensions/calendars/app/assets/javascripts/calendars.js.

If i invoke the page, i see through Firebug, that refinery searched the js file in the following directory:

http://localhost:3002/assets/calendars.js

Hopefully you can help me to fix the problem :)

flp

unread,
Sep 14, 2012, 1:40:23 PM9/14/12
to refine...@googlegroups.com
I use the following refinerycms:

gem 'refinerycms', :git => 'git://github.com/simplelogica/refinerycms', :branch => 'fix/engine-generator-multiple-resources-migrations-routes'

Uģis Ozols

unread,
Sep 15, 2012, 5:55:49 PM9/15/12
to refine...@googlegroups.com
It's working for me with the steps you provided.

One thing to note is that you should have core.rb initializer in your main app config/initializers/refinery folder so you shouldn't create core initializer in your extension.

Rob Yurkowski

unread,
Sep 15, 2012, 7:17:51 PM9/15/12
to refine...@googlegroups.com
Further, it *should* search inside /assets. That's how the asset pipeline works. Stick your asset inside vendor/extensions/calendars/app/assets/javascripts, and it should load.

Sent from my iPad
--
You received this message because you are subscribed to the Google
Groups "Refinery CMS" group.
To post to this group, send email to refine...@googlegroups.com
To unsubscribe from this group, send email to
refinery-cms...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/refinery-cms?hl=en
 
http://www.refinerycms.com

flp

unread,
Sep 16, 2012, 10:18:27 AM9/16/12
to refine...@googlegroups.com
Argh, the name of my file was calendar instead of calendars. It works now, thank you! :)
Reply all
Reply to author
Forward
0 new messages