Skip to content

Instantly share code, notes, and snippets.

@jaz303
Created September 9, 2010 20:44
Show Gist options
  • Save jaz303/572538 to your computer and use it in GitHub Desktop.
Save jaz303/572538 to your computer and use it in GitHub Desktop.
module SomeHelper
#
# Block Menu
def block_menu(&block)
BlockMenuBuilder.new(self).render(&block)
end
class BlockMenuBuilder
def initialize(template)
@template = template
end
def render(&block)
html = "<div class='block-menu'>\n"
html << @template.capture(self, &block)
html << "</div>\n"
html.html_safe
end
def item(icon, title, url = false, &block)
html = "<a class='#{url ? '' : 'inactive'}' href='#{url ? url : '#'}'>\n"
html << " <span class='icon' style='#{@template.background_icon(icon)}'></span>\n"
html << " <span class='title'>#{@template.h(title)}</span>\n"
html << " <span class='caption'>\n"
html << " #{@template.capture(&block)}" if block_given?
html << " </span>"
html << "</a>"
html.html_safe
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment