0.0
The project is in a healthy, maintained state
Ruby gem contain several modules mainly containing the helpers, concerns and services for personal use by Tranzito
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

TranzitoUtils CircleCI

tranzito_utils is a ruby gem containing these Rails helpers, concerns and services:

Name Type Description
SetPeriod Controller Concern Time period selection and browsing
SortableTable Controller Concern Sort column and direction
TimeParser Service Parse time strings into activerecord time objects
Normalize Service Normalize truthy and falsey strings
GraphingHelper Helper Graphing helper for chartkick charts
SortableHelper Helper Sort table headers

Installation

tranzito_utils (gem)

Install the gem by adding this line to your application's Gemfile:

gem "tranzito_utils"

Then run bundle install

To include the config file inside your host app run this command.

rails g tranzito_utils:install

This will add the tranzito_utils.rb file in the initializer where you can alter the default behaviour of several variables being used throughout the gem.

Usage

SortableTable

To use the SortableTable module, include it in your required controllers:

include TranzitoUtils::SortableTable

You can use the following methods of TranzitoUtils::SortableTable in your controllers. These are also the helper methods.

sort_column, sort_direction

SetPeriod

Include the SetPeriod module in your ApplicationController by adding this line:

include TranzitoUtils::SetPeriod

Add this line in the controller where you want to use the SetPeriod module:

before_action :set_period, only: [:index]

SetPeriod depends on a partial file to show the period_select view for filtering. Include in your views with this:

<%= render partial: "/tranzito_utils/period_select" %>

Helpers

For gems helpers, you need to add this into your application_helper.rb file.

include TranzitoUtils::Helpers

Flash Message

You can include the flash messages into your application by add it's partial in your layouts file.

<%= render partial: "/tranzito_utils/flash_messages" %>

Assets

To include the styles from the gem you need to add this into your application.scss, this will include the compiled CSS into your application.

@import url('/tranzito_utils-compiled.css')

tranzito_utils_js (npm)

You also need to add this NPM package in order to use the gem without any issue. You can install it using yarn or npm.

For yarn:

yarn add tranzito_utils_js

For npm

npm install tranzito_utils_js

Then import it into your application by adding this line in application.js or any .js file where you need it:

import { PeriodSelector, TimeParser } from "tranzito_utils_js"

Initialize them like this:

document.addEventListener('DOMContentLoaded', function () {
  if (!window.timeParser) { window.timeParser = new TimeParser() }
  window.timeParser.localize()

  if (document.getElementById('timeSelectionBtnGroup')) {
    const periodSelector = new PeriodSelector()
    periodSelector.init()
  }
}

(if using turbo, switch 'DOMContentLoaded' to 'turbo:load')

License

The gem is available as open source under the terms of the MIT License.

Development

Compile the updated styles:

cd tranzito_utils_js
yarn build:css

Testing

To setup testing, you have to create the database:

cd spec/dummy
RAILS_ENV=test bundle exec rails db:create db:schema:load db:migrate