Active Component

Active Component introduces components into your Rails presentation layer. The use of components improves consistency and development speed through reuse and a new way of view code organization. Components are plain Ruby classes that are able to render themselves using a to_html method. Active Component provides several means that make it easy to write and use components.

Example

Active Component Template:

div 'kpi-report', :content => [

heading_with_label("in #{ Time.now.year }", "Group", 'group'),

report_table(@coreprocesses,
:headers  => ["Core Processes"] + @companies.collect {|company| company.name},
:cols     => [:name] + @companies.collect {|company| 
  proc {|cp| progress_chart(cp, :reporting_company_id => company.id, :chart_type => :boxes)}
}
)

]

Each method represents a component.

Comparision: Same Template in ERB:

Group <%= title("Umsetzungsstand der Ziele") %> in <%= Time.now.year %> <%= help_text %>

<% @companies.each do |t| %> <% end %> <% @coreprocesses.each do |cp| %> <% @companies.each do |t| %> <% end %> <% end %>
Core Processes<%= t.name %>
<%= cp.name %><%= scale_helper(cp, true, t.id, Time.now.year, groupwide) %>

Copyright (c) 2010 Christian Peters, released under the MIT license