README.markdown in deface-0.7.0 vs README.markdown in deface-0.7.1
- old
+ new
@@ -10,16 +10,30 @@
Deface is a library that allows you to customize HTML ERB views in a Rails application without editing the underlying view.
It allows you to easily target html & erb elements as the hooks for customization using CSS selectors as supported by Nokogiri.
Demo & Testing
----------------
+--------------
You can play with Deface and see its parsing in action at [deface.heroku.com](http://deface.heroku.com)
+Production & Precompiling
+------------------------
+
+Deface now supports precompiling where all overrides are loaded and applied to the original views and the resulting templates are then saved to your application's `app/compiled_views` directory. To precompile run:
+
+ bundle exec rake deface:precompile
+
+It's important to disable Deface once precompiling is used to prevent overrides getting applied twice. To disable add the following line to your application's `production.rb` file:
+
+ config.deface.enabled = false
+
+NOTE: You can also use precompiling in development mode.
+
+
Deface::Override
-=======
+================
A new instance of the Deface::Override class is initialized for each customization you wish to define. When initializing a new override you must supply only one Target, Action & Source parameter and any number of Optional parameters. Note: the source parameter is not required when the "remove" action is specified.
Target
------
@@ -29,10 +43,16 @@
------
* <tt>:remove</tt> - Removes all elements that match the supplied selector
* <tt>:replace</tt> - Replaces all elements that match the supplied selector
+* <tt>:replace_contents</tt> - Replaces the contents of all elements that match the supplied selector
+
+* <tt>:surround</tt> - Surrounds all elements that match the supplied selector, expects replacement markup to contain <%= render_original %> placeholder
+
+* <tt>:surround_contents</tt> - Surrounds the contents of all elements that match the supplied selector, expects replacement markup to contain <%= render_original %> placeholder
+
* <tt>:insert_after</tt> - Inserts after all elements that match the supplied selector
* <tt>:insert_before</tt> - Inserts before all elements that match the supplied selector
* <tt>:insert_top</tt> - Inserts inside all elements that match the supplied selector, as the first child.
@@ -70,11 +90,11 @@
* <tt>:attributes</tt> - A hash containing all the attributes to be set on the matched elements, eg: :attributes => {:class => "green", :title => "some string"}
Examples
========
-Replaces all instances of _h1_ in the `posts/_form.html.erb` partial with `<h1>New Post</h1>`
+Replaces all instances of `h1` in the `posts/_form.html.erb` partial with `<h1>New Post</h1>`
Deface::Override.new(:virtual_path => "posts/_form",
:name => "example-1",
:replace => "h1",
:text => "<h1>New Post</h1>")
@@ -98,10 +118,17 @@
Deface::Override.new(:virtual_path => "posts/new",
:name => "example-4",
:remove => "code[erb-loud]:contains('helper_method')",
:original => "<%= helper_method %>")
+Wraps the `div` with id of `products` in ruby if statement, the <%= render_original %> in the `text` indicates where the matching content should be re-included.
+
+ Deface::Override.new(:virtual_path => "posts/new",
+ :name => "example-5",
+ :surround => "div#products",
+ :text => "<% if @product.present? %><%= render_original %><% end %>")
+
Sets (or adds if not present) the `class` and `title` attributes to all instances of `a` with an id of `link` in `posts/index.html.erb`
Deface::Override.new(:virtual_path => 'posts/index',
:name => 'add_attrs_to_a_link',
:set_attributes => 'a#link',
@@ -109,12 +136,12 @@
Remove an entire ERB if statement (and all it's contents) in the 'admin/products/index.html.erb' template, using the :closing_selector.
Deface::Override.new(:virtual_path => 'admin/products/index',
:name => "remove_if_statement",
- :remove => "code[:erb-silent]:contains('if @product.sold?')",
- :closing_selector => "code[:erb-silent]:contains('end')"
+ :remove => "code[erb-silent]:contains('if @product.sold?')",
+ :closing_selector => "code[erb-silent]:contains('end')"
Scope
=====
Deface scopes overrides by virtual_path (or partial / template file), that means all override names only need to be unique within that single file.
@@ -138,14 +165,18 @@
rake deface:get_result[shared/_head]
rake deface:get_result['admin/products/index']
-**deface:test_selector** - Applies a given CSS selector against a parital or template and outputs the markup for each match (if any). *test_selector* requires two arguments, the first is the virtual_path for the partial / template, the second is the CSS selector to apply:
+**deface:test_selector** - Applies a given CSS selector against a partial or template and outputs the markup for each match (if any). *test_selector* requires two arguments, the first is the virtual_path for the partial / template, the second is the CSS selector to apply:
rake deface:test_selector[shared/_head,title]
rake deface:test_selector['admin/products/index','div.toolbar']
+
+**deface:precompile** - Generates compiled views that contain all overrides applied. See `Production & Precompiling` section above for more.
+
+ rake deface:precompile
Implementation
==============