Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec/basicsSpec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ describe "Transparency", ->
template.render data
expect(template).toBeEqual expected

it "should accept context as a string", ->
template = '<div class="hello"></div>'
data = hello: 'Hello'
expected = $ '<div><div class="hello">Hello</div></div>'

template = $ window.Transparency.render template, data
expect(template).toBeEqual expected

it "should match model keys to template by element id, class, name attribute and data-bind attribute", ->
template = $ """
<div class="container">
Expand Down
11 changes: 11 additions & 0 deletions spec/basicsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
template.render(data);
return expect(template).toBeEqual(expected);
});
it("should accept context as a string", function() {
var data, expected, template;

template = '<div class="hello"></div>';
data = {
hello: 'Hello'
};
expected = $('<div><div class="hello">Hello</div></div>');
template = $(window.Transparency.render(template, data));
return expect(template).toBeEqual(expected);
});
it("should match model keys to template by element id, class, name attribute and data-bind attribute", function() {
var data, expected, template;

Expand Down
6 changes: 6 additions & 0 deletions src/transparency.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Transparency.render = (context, models = [], directives = {}, options = {}) ->
return unless context
models = [models] unless _.isArray models

# If context was passed in as an HTML string, then convert it to a div element with innHTML as passed in HTML string.
if typeof context == 'string'
_html_string = context
context = document.createElement('div')
context.innerHTML = _html_string

# Context element, state and functionality is wrapped to `Context` object. Get it, or create a new
# if it doesn't exist yet.
context = helpers.data(context).context ||= new Context(context, Transparency)
Expand Down