An attribute-driven hierarchy builder for Rails views.
- Configure a hierarchy (or hierarchies) of attributes
- Create partials for each attribute that you want to render
- Feed the attributarchy some data
The result: Dynamic, hierarchical views that allow you to easily dish out an array of layouts, styles, and behavior. All as simple or complex as you'd like.
include Attributarchy has_attributarchy \ #----------# # Required # #----------# # Name it, as you can define multiple :name, # Specify an array of attributes that constitute the (?:attribut|hier)archy as: [:attribute, ...], #----------# # Optional # #----------# # Specify an additional lookup path (as a string) or paths (as an array) in: %w[this_path that_path], # Specify an attribute (as a symbol) or attributes (as an array) that will # only be used for grouping -- not rendering without_rendering: [:a_no_show]
In your controller's view directory (or another location configured via
:in), define a partial for all rendering attributes. The locals provided to these are:
group_data— The data set of the grouped-by attribute
group_value— The name of the grouped-by attribute
group_level— An integer representing the position of the grouping within the hierarchy
The entire attributarchy will be wrapped in a
div with the class "attributarchy" and each attributarchy will be wrapped in a
div with the class of "attribute-attributarchy".
My knowledge is limited here, but to get this working in an engine you must specify a full lookup path, e.g.:
I believe this is the only way to do this short of converting the gem to a rail tie, but I'm not positive. Besides, I don't want Attributarchy included in every controller anyway — it seems quite specialized.
To see a simple example, start the dummy rails app and hit its root.