railsdog/deface — pull request #42 by robertoles (2012-05-17 12:25:11+00:00)
Title: Ability to register custom actions

Hi,

I thought it would be nice to be able to register a new action type to deface. Obviously the main actions cover 99% of requirements, but I have noticed when upgrading a spree store recently, that, as the spree core templates changes we need to make more obscure changes to the html in order to keep our existing layout, and some times the easiest way to active that would be to roll our own actions.

I have done a little work this morning refactoring the Applicator / Override / Environment classes to allow for this, but the work is still unfinished (mainly the absence of making this work for actions which allow an end selector, and the fact that I haven't moved any specs around yet) but I wanted some feedback before I carry on, as I don't want to do anymore if you guys don't see deface going in this direction.

A brief example of the attached code works...

# spree_app/lib/deface/my_custom_action.rb

class MyCustomAction < Deface::Actions::Action
def execute target_element
# do something to the target element
end
end

# spree_app/config/initializers/deface.rb

require 'lib/my_custom_action'
SpreeApp::Application.config.deface.register_action MyCustomAction

# spree_app/app/overrides/an_override.rb
Deface::Override.new(my_custom_action: '#some_element', virtual_path 'a/path', partial: 'a/partial', name: 'foo')

And feedback would be great, Thanks