Information Technology Dark Side

Struggles of a Self-Taught Coder

Information Technology Dark Side header image 2

Two Helper Methods I Use Too Much

January 23rd, 2013 · 3 Comments

Carets and Icons
There’s nothing particularly brilliant about these, and they are probably only moderately useful. Mostly I’m putting them out there so that you can (preferably nicely) tell me how stupid I am if there is a better way.

Sometimes I will add options to control whether the caret goes after the string or before it.

  def caret(string)
    "<b class='caret'></b>#{string}".html_safe
  end

  def icon(icon_name)
    "<i class='#{icon_name}'></i>".html_safe
  end

  def to_paragraphs(string)
    return '' if string.nil?
    html = []
    string.split("n").each do |paragraph|
      html << "<p>#{paragraph}</p>"
    end
    html.join().html_safe
  end

After I originally published this I remembered another one… that’s why there are now 3

If you enjoyed this post, make sure you subscribe to my RSS feed!
Stumble it!

Tags: Uncategorized

3 responses so far ↓

  • 1 Matt De Leon // Jan 23, 2013 at 4:37 pm

    That’s actually pretty clever. Not sure if it’s a big enough of a problem for me to solve with a helper method.

    Side note: have you checked out font awesome?Great extension to bbootstrap with more icons and more flexible icons (size, color etc). It’s used on localstake.

  • 2 David Baldwin // Jan 23, 2013 at 6:43 pm

    A bit off topic, but you could control your carets all via CSS without adding an extra tag and “caret” class.

    You essentially add a :before/:after pseudo class to your containing element (a/li/span) that builds a caret via css borders.

    Here is an example most of the code needed which I pulled out of a recent project. Is it worth all the extra css? Ah, that is for you to decide.

    There is also a basic example of how you might do an expand/collapse.

    Caret Example

  • 3 Anthony Panozzo // Jan 28, 2013 at 11:47 pm

    Similar to #3, is http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format

Leave a Comment