Skip to content

Instantly share code, notes, and snippets.

@ashrafuzzaman
Last active December 17, 2015 00:19
Show Gist options
  • Save ashrafuzzaman/5520085 to your computer and use it in GitHub Desktop.
Save ashrafuzzaman/5520085 to your computer and use it in GitHub Desktop.
Widget helper class
module WidgetHelper
def header(&block)
content_tag :div, class: 'header', &block
end
def widget(options={}, &block)
w = Widget.new(options, self)
widget_content = capture(w, &block)
content_tag :div, class: 'wrapper' do
widget_content
end
end
class Widget
def initialize(options, template)
@options = options
@template = template
end
def title(&block)
@template.content_tag :h2 do
@template.capture(&block)
end
end
def content(&block)
@template.content_tag :div, class: 'content' do
@template.capture(&block)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment