Changeset 1165

Show
Ignore:
Timestamp:
08/26/07 20:46:07 (1 year ago)
Author:
mikem836
Message:

add templates to release notes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ruport-www/release_notes-1.2.html

    r1158 r1165  
    237237      <p><b>- Abstract formatting options via Formatter::Template</b></p> 
    238238       
    239       <p>**NOTE**: mike, please fill in  
     239      <p>Templates are an entirely new feature to Ruport 1.2.  They allow you 
     240        to define a reusable set of formatting options.  You can create 
     241        multiple templates with different options and specify which one should 
     242        be used when output is rendered.</p> 
     243 
     244      <p>You define a template by using the <code>create</code> method of 
     245        Ruport::Formatter::Template.</p> 
     246 
     247      <pre> 
     248        Ruport::Formatter::Template.create(:simple) do |t| 
     249          t.page_format = { 
     250            :size   => "LETTER", 
     251            :layout => :landscape 
     252          } 
     253        end 
     254      </pre> 
     255 
     256      <p>When creating the template, you can specify whatever options you 
     257        want, but your formatter needs to know what to do with them or else 
     258        they will just be ignored.  You define an <code>apply_template</code> 
     259        method in your formatter to tell it how to process the template.</p> 
     260 
     261      <pre> 
     262        class Ruport::Formatter::PDF 
     263 
     264          def apply_template 
     265            options.paper_size = template.page_format[:size] 
     266            options.paper_orientation = template.page_format[:layout] 
     267          end 
     268 
     269        end  
     270      </pre> 
     271 
     272      <p>To use a template, just specify it using the :template option when 
     273        you render your output.  Note that even if you've defined templates 
     274        and set up the formatter to use them, they are still optional.  If you 
     275        don't specify a :template option, <code>apply_template</code> simply 
     276        won't be called.</p> 
     277 
     278      <pre> 
     279        t = Table(%w[a b c]) << [1,2,3] << [1,4,6] << [2,3,4]  
     280        puts t.to_pdf(:template => :simple)  #=> uses the :simple template 
     281        puts t.to_pdf                        #=> doesn't use a template 
     282      </pre> 
     283 
     284      <p>You can also derive a template from another, pre-existing 
     285        template, using the :base option to 
     286        Ruport::Formatter::Template.create.</p> 
     287 
     288      <pre> 
     289        Ruport::Formatter::Template.create(:derived, :base => :simple) 
     290      </pre> 
     291 
     292      <p>One thing that the templates have allowed us to do is to 
     293        standardize the interface to the different built-in formatters.  Each 
     294        formatter has an <code>apply_template</code> method predefined that 
     295        will accept a standard set of options.  If, however, you don't like 
     296        the predefined set up, it's easy to specify your own interface by 
     297        overriding the existing <code>apply_template</code> methods.  This 
     298        example shows a number of the options being used.</p> 
     299 
     300      <pre> 
     301        Ruport::Formatter::Template.create(:simple) do |t| 
     302          t.page_format = { 
     303            :size   => "LETTER", 
     304            :layout => :landscape 
     305          } 
     306          t.text_format = { 
     307            :font_size => 16 
     308          } 
     309          t.table_format = { 
     310            :font_size      => 16, 
     311            :show_headings  => false 
     312          } 
     313          t.column_format = { 
     314            :alignment => :center, 
     315            :heading => { :justification => :right } 
     316          } 
     317          t.grouping_format = { 
     318            :style => :separated 
     319          } 
     320        end 
     321      </pre> 
    240322         
    241323      <p><b>- Sorting your Grouping objects</b></p>