0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
An attribute-driven hierarchy builder for Rails views.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.2.14
~> 2.14.0
 Project Readme

Gem Version Dependency Status Build Status Coverage Status Code Climate

Attributarchy

An attribute-driven hierarchy builder for Rails views.

The Gist

  1. Configure a hierarchy (or hierarchies) of attributes
  2. Create partials for each attribute that you want to render
  3. Style and/or bind JavaScript as desired
  4. 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.

Usage

Gemfile

  gem 'attributarchy'

Controller (example)

  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]

Partials (example)

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

View (example)

  build_attributarchy(:name, data_set)

Assets (example)

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".

Working With Engines

My knowledge is limited here, but to get this working in an engine you must specify a full lookup path, e.g.:

  in: "#{YourEngine::Engine.root}/app/views/your_engine/..."

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.

Examples

To see a simple example, start the dummy rails app and hit its root.