Created
January 10, 2013 04:20
-
-
Save bloudermilk/4499445 to your computer and use it in GitHub Desktop.
How I use POROs to build maintainable views
This file contains hidden or 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 FieldsetWithSubtext | |
| def fieldset_with_subtext(main_text, subtext, options = {}, &block) | |
| View.new(self, main_text, subtext, options, &block) | |
| end | |
| class View | |
| attr_reader :context, :main_text, :subtext, :options, :block | |
| def initialize(context, main_text, subtext, options = {}, &block) | |
| @context = context | |
| @main_text = main_text | |
| @subtext = subtext | |
| @options = options | |
| @block = block | |
| end | |
| def template | |
| %<%s <small>%s</small>> % contents | |
| end | |
| def contents | |
| [main_text, subtext] | |
| end | |
| def to_s | |
| context.field_set_tag(template.html_safe, options, &block) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment