Memphis Ruby

Memphis Ruby

Fork me on GitHub

Memphis Ruby Posts Tagged: gem

Josh W. Lewis — January 28, 2015

This month, we had a great meetup at Coroutine’s new office space on Broad Ave.

Jason Charnes educated us on how to decorate your models as an alternative to Rails' helper system. A tradidtional Rails view helper might look like this:

module ChurchesHelper
  def remove_church_from_name(name)
    name.split(" ").reject{ |e| e == "Church" }.join(" ")

And you’d use it like this:

  <h5><%= remove_church_from_name( %></h5>

This works, and helps keep your code DRY, though you usually end up with long method names, and several concerns mixed into a module.

Draper is a RubyGem for adding decorating methods to models. With Draper, you can do something like this:

class ChurchDecorator < Draper::Decorator
  def name" ").reject{ |e| e == "Church" }.join(" ")

Which you can use in your views like this:

  <h5><%= %></h5>

It certainly feels more Object Oriented, and in my book, it’s a little clearer. Jason showed us how to get setup with Draper, and explained some of the deeper semantics. Check out Jason’s slides here.

We concluded the event with an inpromptu editor showdown. Various developers showcased their editors, with varying degrees of success (I hope I didn’t turn anyone off on Vim). We saw Vim, Atom, and PHPStorm, and talked about others like Sublime and TextMate.

Thanks to Coroutine for the meeting space and the awesome Broadway Pizza.

Tagged: ruby, gem, decorators
Josh W. Lewis — August 19, 2014

This month, we had another fun an informative meetup at Coroutine. Just one presentation this time, but a good one:

Generating Word Documents with Caracal

John Dugan gave us a great walkthrough of Caracal. It’s an open source library for generating Microsoft Word documents with an HTML-like Ruby API. Caracal lets you build word documents like this: 'example.docx' do |docx|
  # page 1
  docx.h1 'Some Title'
  docx.h2 'Some Section'
  docx.p  'Lorem ipsum dolor....'
  docx.table @my_data, border_size: 4 do
    cell_style rows[0], background: 'cccccc', bold: true

  # page 2
  docx.p  'Lorem ipsum dolor....'
  docx.ul do
    li 'Item 1'
    li 'Item 2'
  docx.img image_url('graph.png'), width: 500, height: 300

The review demonstrated the library’s functionality but also a good portion of the libraries internal architecture.

The overall response was very positive. Caracal appears to be a well thought out library. It has a great API, and it’s internals abide by the principles of SOLID.

Thanks to all who came, and to Coroutine for the food and meeting space.

Tagged: ruby, gem