Build your views by assembling self-rendering components
Switch branches/tags
Nothing to show
Latest commit 7e9cf70 Jul 24, 2011 @ChristianPeters Document ruby 1.9-based implementation alternative for ActiveComponen…


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.


**Active Component Template:**

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

heading_with_label("in #{ }", "Group", 'group'),

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


Each method represents a component.

**Comparision: Same Template in ERB:**

<div class=“kpi_report”>

<h1 class="content_header">
  <span class="content_header_text">
    <span class="label group_label">Group</span> 
    <%= title("Umsetzungsstand der Ziele") %> 
    in <%= %> <%= help_text %></span>
<div class="content">
  <div class="sub_content">
    <table cellspacing="0">
          <td width="80%">Core Processes</td>
          <% @companies.each do |t| %>
            <td><%= %></td>
          <% end %>
      <% @coreprocesses.each do |cp| %>
      <tr class="line">
        <td class="small_name_column"><%= %></td>
        <% @companies.each do |t| %>
          <td class="small_indicator_column"><%= scale_helper(cp, true,,, groupwide) %></td>
        <% end %>
      <% end %>


Copyright © 2010 Christian Peters, released under the MIT license