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(" ")
end
end
And you’d use it like this:
<h5><%= remove_church_from_name(c.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
model.name.split(" ").reject{ |e| e == "Church" }.join(" ")
end
end
Which you can use in your views like this:
<h5><%= @church.name %></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.
This month, we had another fun an informative meetup at Coroutine. Just one presentation this time, but a good one:
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:
Caracal::Document.save 'example.docx' do |docx|
# page 1
docx.h1 'Some Title'
docx.hr
docx.br
docx.h2 'Some Section'
docx.p 'Lorem ipsum dolor....'
docx.br
docx.table @my_data, border_size: 4 do
cell_style rows[0], background: 'cccccc', bold: true
end
# page 2
docx.page
docx.p 'Lorem ipsum dolor....'
docx.ul do
li 'Item 1'
li 'Item 2'
end
docx.br
docx.img image_url('graph.png'), width: 500, height: 300
end
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.