How to edit haml in radiant core?

Hello,

My goal is to use only extensions, and don’t modify radiant core.
I will try to be clear with an example. I would like to customize the
avalaible layout list when you are creating / editing a page.
But it’s not possible, because the request is done directly in
views/admin/page/edit.html.haml (there is not a var which could be
change by an extension…).
How could I do that?

Here is the code :

  • render_region :parts_bottom do |parts_bottom|
    • parts_bottom.edit_layout_and_type do
      .row
      %p
      %label{:for=>“page_layout_id”}
      Layout
      = select “page”, “layout_id”, [[’’, ‘’]] +
      Layout.find(:all).map { |s| [s.name, s.id] }

I would like to give an other layout list without removing these lines?
(and I wouldn’t like to hide them with javascript).

What is the best way to do that?

Thank you,
Vincent

I’m not sure I understand exactly what you want to do, but I think
this should do it:

In your whatever_extension.rb activate method do:

admit.page.edit.add :parts_bottom, ‘your_additional_partial’, :after
=> ‘edit_layout_and_type’

Then it will look for a file in ‘vendor/extensions/whatever/app/views/
admin/page/your_additional_partial’ to inject into the interface.

I described the process in the help extension. If it’s a new instance
of Radiant (or is running on edge) just run ‘script/extension install
help’
or if you have the Ray extension
http://github.com/johnmuhl/radiant-ray-extension/tree/master
run ‘rake ray:help’
or take a look at the Help docs directly at
http://github.com/saturnflyer/radiant-help-extension/tree/master/HELP_developer.rdoc
and read the ‘Partial Injection’ area. It applies to the way this
works in the rest of the application as well.
You can also read http://wiki.radiantcms.org/
Using_the_Shards_Extension (the Shards extension is now part of the
core, so you can ignore the installation and configuration details)

If you want to alter the list of Layouts the Help extension provides a
‘replace’ method for the admin UI that you could use to completely
change the default list of Layouts.

Does that answer your question?

Hello Jim,

I had already use shards to inject and extend functionnalities to pages,
it’s not a problem.
Here, I would like to remove or replace an ‘existing’ part : layout
list, to replace it by my list for example.

I didn’t see we can ‘replace’ a part, thank you.
Do you have any documentation about the replace method?
What does it looks like?

Thank you !
Vincent

It works just like the ‘add’ method. I have this in the Help extension:
Radiant::AdminUI::RegionSet.class_eval do
def replace(region=nil, partial=nil)
raise ArgumentError, “You must specify a region and a
partial” unless region and partial
self[region].replace([partial])
end
end
So you can just do

admin.page.edit.replace :the_part, ‘my_part’

The only documentation is where I implemented it
http://github.com/saturnflyer/radiant-help-extension/tree/6b691a675955bdf934ebba7f3ec6bf3142094b90/help_extension.rb

Although, now that I look at it, I realize that this is pointless
because you can just create a partial of the same name and Radiant
will pick it up.
So just create a partial in your extension in ‘app/views/admin/page/
edit_layout_and_type’ and It will be picked up instead of the default.

Sorry for the long-winded response.

Jim G. wrote:

admin.page.edit.replace :the_part, ‘my_part’
instead of the default.

Sorry for the long-winded response.
Yes, or since regions are just arrays on the admin object, you can
remove the offending one and replace it with your own. These two lines
do that in the concurrent_draft extension (where view is one of page,
snippet, or layout):

  admin.send(view).edit.form_bottom.delete 'edit_buttons'
  admin.send(view).edit.add :form_bottom, 'admin/edit_buttons'

Sean

That’s just perfect !
I created a file named _edit_layout_and_type.rhtml in my extension and
it’s working !

Thank you, radiant is realy flexible !
Vincent

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs