
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
##Description
MetaReports provides Rails classes and templates for reports. It provides a common metadata structure that can be passed to the desired template format. If your report does not fit within the metadata convention it is very easy to create specific templates.
MetaReports exports to HTML, PDF, and XLSX formats. More are to come.
##Provides
Note: Before 0.1.0 MetaReports provided an engine that served reports. The engine has been dropped. Look at the rspec/dummy app for one approach to serving reports.
##Usage
###Installation
Add meta_reports your Gemfile:
gem 'meta_reports'
gem 'prawn-table' # if you are using the latest prawn, table is not included
Run the bundle
command to install it.
Install the templates:
bundle exec rails generate meta_reports:install_templates
This copies over the meta_reports color model and the templates:
app/models/meta_reports/color.rb
: The MetaReports::Color model for storing colors.app/views/meta_reports/*
: All templates.Now create a data structure using MetaReports::Data and MetaReports::Table, and pass it off to the default templates.
###Writing a report
###MetaData
The key component of MetaReports is the metadata format. This allows you to write a data method once and export it to any supported format. If you follow convention, the default templates will work out of the box.
Data: A MetaReports::Data instance, which is a thinly wrapped hash. Returned by each report method. Methods:
Table: A MetaReports::Table instance, which is a thinly wrapped two dimensional array of cells.
Cell: A cell is either a single value, or a hash specifying options:
###Examples
Here is a simple example. See the example class for more.
def self.moo(params)
MetaReports::Data.new do |d|
d.title = 'Le Moo'
d.subtitle = 'Ahem'
d.tables["The Big Moo"] = MetaReports::Table.new do |t|
t << ['Number', 'Title', 'Hey']
t << [1, 'Ode to Moo', 'Ow']
t << [2, 'Odious Moo', 'Eww']
t << [3, "#{params[:moo_type]} Moo", 'No Way!']
t << [3, 'Format', {content: "PDF/XLSX", html: "<span>HTML</span>", class: 'attention'}]
end
end
end
###Colors
There is currently an incomplete implementation of shared colors. Define your colors by name in the MetaReports::Color class in the COLORS hash constant. If a table row or cell contains a corresponding class name it will have that color in HTML and PDF. XLSX support is planned. It is also intended to implement a means of specifying cell text color.
Specify colors using the COLORS hash constant in your MetaReports::Color class. An example COLORS hash is below:
COLORS = {
even: 'efefef',
odd: 'ffffff',
yellow: ['ffffaa', 'ffffcc', 'f9f9a4', 'f9f9c6'],
highlight: '$yellow_1 !important',
hover: ['ffcccc', 'ffc5c5']
}
To specify a color for a cell, use a hash and specify the color name in the class:
table << [{content: "Colored cell", class: 'yellow'}]
To specify a color for a row, store the row's color in the table row_classes hash:
table.row_classes[row] = 'yellow'
Note the row number begins with zero, and excludes the header if enabled.
MetaReports defaults to inline styling for HTML. You can use the rake task to create a CSS stylesheet with corresponding colors and class names. Each table must have inline_css set to false for this to occur:
MetaReports::Data.new do |d|
d.title = 'Class based row/cell background colors'
d.tables["Table 1"] = MetaReports::Table.new do |t|
t << %w{One simple row}
t.inline_css = false
end
end
When you run rake meta_reports:export_colors
task it exports two SCSS files, one including HTML styles, the other including SCSS variables (for your use in other files.) The export uses the following conventions:
Given the above example the generated lib/metareports_color_variables.scss
SASS file will be:
$even: #efefef;
$odd: #ffffff;
$yellow_0: #ffffaa;
$yellow_1: #ffffcc;
$yellow_2: #f9f9a4;
$yellow_3: #f9f9c6;
$highlight: $_yellow_1;
$hover_0: #ffcccc;
$hover_1: #ffc5c5;
And the generated assets/stylesheets/lib/metareports_colors.scss
SASS file would be:
@import 'metareports_color_variables.scss';
tr.even { background: $even; }
tr.odd { background: $odd; }
tr.yellow:nth-child(4n+0) { background: $yellow_0; }
tr.yellow:nth-child(4n+1) { background: $yellow_1; }
tr.yellow:nth-child(4n+2) { background: $yellow_2; }
tr.yellow:nth-child(4n+3) { background: $yellow_3; }
tr.highlight { background: $yellow_1 !important; }
tr.hover:nth-child(2n+0) { background: $hover_0; }
tr.hover:nth-child(2n+1) { background: $hover_1; }
Note that you can specify !important
and it will be reproduced in the CSS style.
To export only the variables file, use the meta_reports:export_color_variables
Rake task.
To export only the colors file, use the meta_reports:export_colors_only
Rake task.
##TODO
##Changelog
##Development
Fork the project on github, edit away, and pull.
##Authors, License and Stuff
Code by Noel Peden and released under MIT license.
FAQs
Unknown package
We found that meta_reports demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.