Small library for rendering rails partials in to bodies of text
<div class="media-image">
<%= image_tag media_image, data: { align: media_align } %>
<%= content %>
</div>
<h1><%= post.title %></h1>
Components.register([{
name: :media,
locals: [
{name: :media_image},
{name: :media_align, default: 'right'}
]
},
{
name: :post_header
}])
Instances of component start and end tags will be rendered in to their respective position. Any content inside the tag is yielded as a content
local to the partial.
body = <<-BODY
{{#post_header /}}
{{#media media_image="foo.jpg"}}
OMG
{{/media}}
BODY
puts Components::Context.new(assigns: { post: Post.find(1) }).render_html(body)
<h1>This was a post title</h1>
<div class="media-image">
<img src="foo.jpg" data-align="right">
foo
OMG
</div>