On Tue, Apr 11, 2017 at 2:15 PM, Shane Curcuru <[email protected]> wrote:
> A bunch of tools could have prettier output if we used some simple but
> consistent bootstrap styles. Is there any *easy* way to create a
> Wunderbar::HtmlMarkup function like this pseudocode?
>
> # In whimsy/asf/themes.rb
>
> # Wrap content with nicer fluid margins
> def _whimsy_content colstyle = "col-lg-11"
> _div.content.container-fluid do
> _div.row do
> _div class: colstyle do
> #{content from the caller's do...end block like _body method}
> end
> end
> end
> end
>
> If this requires complicated code to properly replicate how the builder
> stuff works, it's not worth it at the moment.
That's precisely what 'yield' is for. And because Ruby doesn't let
you push dashes into variable names, you need to use underscore for
container_fluid, wunderbar will map that back to a dash. The complete
sample would look like this:
require 'wunderbar'
class Wunderbar::HtmlMarkup
def _whimsy_content colstyle="col-lg-11"
_div.content.container_fluid do
_div.row do
_div class: colstyle do
yield
end
end
end
end
end
_html do
_whimsy_content do
_p 'blah blah blah'
end
end
The generated markup will look like this:
!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
</head>
<body>
<div class="content container-fluid">
<div class="row">
<div class="col-lg-11">
<p>blah blah blah</p>
</div>
</div>
</div>
</body>
</html>
- Sam Ruby