Ruby View

KDRS Search & View can be extended for advanced data manipulation and presentation. Some basic XML config is need to activate the view. We encourage the use of XML where possible, and then use Ruby views when needed. This allows for readability in the community.

Table of Contents

  1. Ruby View
  2. Make a new file for the view
  3. Reference the view from xml
  4. Minimum template
  5. Data
  6. Columns
  7. Html
  8. Ruby
  9. CSS

Make a new file for the view

In the templates/your_system/ directory on your host, create a new file for your view. It must start with underscore. Use lowercase. The html.erb extention will make sure that the Ruby server will process the file first, then the html engine.

/var/kdrs/sv/templates/school_system/_diploma.html.erb

Reference the view from xml

The program flow will be redirected to this view. You will be in control of the presentation.

    <table>
        <rubyview>diploma</rubyview>

Minimum template

<!-- DATA PREPARATION -->
<% 
    # Your data will be in the @docs variable
    # Adjust your data as needed before presentation
%>

<!-- DATA PRESENTATION -->
<%= render 'table' %>

Note Use ‘=’ to output Ruby on screen`

This view template will generate the same view as the default template. The difference is that you can manipulate the data as needed, and change the presentation with new styling, titles, extra text, tables etc. Maybe you want some different layout on print. This and more you can change from here.

Data

The data from xml will be available to the view in the @docs variable. If you need more data from other tables, you can fetch those here. See the examples for how this is done.

Columns

Select the fields you want to show as columns in the view

    @show_fields = ["first name", "last name"] 
    @show_fields  <<  "land"  #alternative syntax 

Html

You can write plain html in this file

    <h1>Hello, there!</h1>

Ruby

You can write plain Ruby in this file, as long as you use the brackets.

    <% Ruby here %>

Ruby can be used to edit the data, or write HTML code, like in this example:

<% 5.times do %>
    <h1>Hello, there!</h1>
<% end %>

CSS

You can style your data with css, or adjust margins

<style>    
  .my-style {
    background-color: lightgray;
    font-size: larger;
    /* vscode editor will help suggest what to write here */
    /* you can also use chatgpt to write css */
  }
</style>

Note: It is technically possible use Javascript for advanced presentation. However - we encourage the use of Ruby whenever possible for human readability and code sharing.


Table of contents