Last active
December 17, 2015 00:19
-
-
Save ashrafuzzaman/5520085 to your computer and use it in GitHub Desktop.
Widget helper class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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