{"action":"created","comment":{"url":"https://api.github.com/repos/alleyinteractive/huron/pulls/comments/86884873","pull_request_review_id":7520449,"id":86884873,"diff_hunk":"@@ -146,47 +148,200 @@ class InsertNodes {\n    *                          for the template ID to replace\n    * @param {object} meta - Module metadata\n    */\n-  replaceTemplate(context, meta) {\n+  replaceTemplate(meta, context = false) {\n     let tags = null;\n \n-    meta.type = this.validateType(meta.type);\n-    tags = context.querySelectorAll(`[data-huron-id=\"${meta.id}\"][data-huron-type=\"${meta.type}\"]`);\n-\n-    if (tags && meta.render) {\n-      for (let i = 0; i < tags.length; i++) {\n-        let currentTag = tags.item(i);\n-        let modifier = currentTag.dataset.huronModifier;\n-        let rendered = null;\n-\n-        if (meta.data) {\n-          // If we have a modifier, use it, otherwise use the entire data set\n-          if (modifier && meta.data[modifier]) {\n-            rendered = meta.render(meta.data[modifier]);\n-          } else {\n-            rendered = meta.render(meta.data);\n+    if (this.validateType(meta.type)) {\n+      if (!context) {\n+        // Reset inserted cache\n+        this._inserted = [];\n+        tags = document.querySelectorAll(\n+          `[data-huron-id=\"${meta.id}\"][data-huron-type=\"${meta.type}\"]`\n+        );\n+      } else {\n+        // Search for this module within a hash context\n+        tags = this.generateHashContext(meta, context);\n+      }\n+\n+      if (tags && tags.length && meta.render) {\n+        tags.forEach((currentTag) => {\n+          if (-1 === this._inserted.indexOf(currentTag)) {\n+            const modifier = currentTag.dataset.huronModifier;\n+            const parent = currentTag.parentNode;\n+            const rendered = this.applyModifier(modifier, meta);\n+            let renderedContents = null;\n+            let renderedTemplate = null;\n+\n+            // Remove existing module tags\n+            this.removeOldTags(meta.hash, currentTag.previousSibling);\n+\n+            // Get the contents of the rendered template\n+            renderedContents = [\n+              ...this.convertToElement(rendered)\n+                .querySelector('template')\n+                .content\n+                .children\n+            ];\n+\n+            // Insert each tag of the template contents before placeholder\n+            renderedContents.forEach((element) => {\n+              if (1 === element.nodeType) {\n+                element.dataset.parentHash = meta.hash;\n+                parent.insertBefore(element, currentTag);\n+              }\n+            });\n+\n+            // Add module hash to this placeholder\n+            currentTag.dataset.selfHash = meta.hash;\n+\n+            // Add this placeholder to the inserted cache,\n+            // to make sure we don't insert it twice\n+            this._inserted.push(currentTag);","path":"src/js/huron.js","position":168,"original_position":168,"commit_id":"ac65a0fcce7509a8958541ad0adf5ec52089ecd4","original_commit_id":"ac65a0fcce7509a8958541ad0adf5ec52089ecd4","user":{"login":"pattiereaves","id":44990,"avatar_url":"https://avatars.githubusercontent.com/u/44990?v=3","gravatar_id":"","url":"https://api.github.com/users/pattiereaves","html_url":"https://github.com/pattiereaves","followers_url":"https://api.github.com/users/pattiereaves/followers","following_url":"https://api.github.com/users/pattiereaves/following{/other_user}","gists_url":"https://api.github.com/users/pattiereaves/gists{/gist_id}","starred_url":"https://api.github.com/users/pattiereaves/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pattiereaves/subscriptions","organizations_url":"https://api.github.com/users/pattiereaves/orgs","repos_url":"https://api.github.com/users/pattiereaves/repos","events_url":"https://api.github.com/users/pattiereaves/events{/privacy}","received_events_url":"https://api.github.com/users/pattiereaves/received_events","type":"User","site_admin":false},"body":"ahhh that's smart!","created_at":"2016-11-07T22:30:57Z","updated_at":"2016-11-07T22:34:11Z","html_url":"https://github.com/alleyinteractive/huron/pull/37#discussion_r86884873","pull_request_url":"https://api.github.com/repos/alleyinteractive/huron/pulls/37","_links":{"self":{"href":"https://api.github.com/repos/alleyinteractive/huron/pulls/comments/86884873"},"html":{"href":"https://github.com/alleyinteractive/huron/pull/37#discussion_r86884873"},"pull_request":{"href":"https://api.github.com/repos/alleyinteractive/huron/pulls/37"}}},"pull_request":{"url":"https://api.github.com/repos/alleyinteractive/huron/pulls/37","id":92665578,"html_url":"https://github.com/alleyinteractive/huron/pull/37","diff_url":"https://github.com/alleyinteractive/huron/pull/37.diff","patch_url":"https://github.com/alleyinteractive/huron/pull/37.patch","issue_url":"https://api.github.com/repos/alleyinteractive/huron/issues/37","number":37,"state":"open","locked":false,"title":"Template replacement with any number of child nodes","user":{"login":"ostowe","id":2472666,"avatar_url":"https://avatars.githubusercontent.com/u/2472666?v=3","gravatar_id":"","url":"https://api.github.com/users/ostowe","html_url":"https://github.com/ostowe","followers_url":"https://api.github.com/users/ostowe/followers","following_url":"https://api.github.com/users/ostowe/following{/other_user}","gists_url":"https://api.github.com/users/ostowe/gists{/gist_id}","starred_url":"https://api.github.com/users/ostowe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ostowe/subscriptions","organizations_url":"https://api.github.com/users/ostowe/orgs","repos_url":"https://api.github.com/users/ostowe/repos","events_url":"https://api.github.com/users/ostowe/events{/privacy}","received_events_url":"https://api.github.com/users/ostowe/received_events","type":"User","site_admin":false},"body":"This allows for a more exact copy of site markup structure (instead of extraneous wrapper divs)\r\n\r\nPlease review, but testing this out in DFM before merging","created_at":"2016-11-07T21:15:57Z","updated_at":"2016-11-07T22:34:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8ac55a22de4d2ed0d55bb184339c6a48ae3a9224","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/alleyinteractive/huron/pulls/37/commits","review_comments_url":"https://api.github.com/repos/alleyinteractive/huron/pulls/37/comments","review_comment_url":"https://api.github.com/repos/alleyinteractive/huron/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alleyinteractive/huron/issues/37/comments","statuses_url":"https://api.github.com/repos/alleyinteractive/huron/statuses/ac65a0fcce7509a8958541ad0adf5ec52089ecd4","head":{"label":"alleyinteractive:feature/1.0/template-replacement","ref":"feature/1.0/template-replacement","sha":"ac65a0fcce7509a8958541ad0adf5ec52089ecd4","user":{"login":"alleyinteractive","id":1733454,"avatar_url":"https://avatars.githubusercontent.com/u/1733454?v=3","gravatar_id":"","url":"https://api.github.com/users/alleyinteractive","html_url":"https://github.com/alleyinteractive","followers_url":"https://api.github.com/users/alleyinteractive/followers","following_url":"https://api.github.com/users/alleyinteractive/following{/other_user}","gists_url":"https://api.github.com/users/alleyinteractive/gists{/gist_id}","starred_url":"https://api.github.com/users/alleyinteractive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alleyinteractive/subscriptions","organizations_url":"https://api.github.com/users/alleyinteractive/orgs","repos_url":"https://api.github.com/users/alleyinteractive/repos","events_url":"https://api.github.com/users/alleyinteractive/events{/privacy}","received_events_url":"https://api.github.com/users/alleyinteractive/received_events","type":"Organization","site_admin":false},"repo":{"id":47849410,"name":"huron","full_name":"alleyinteractive/huron","owner":{"login":"alleyinteractive","id":1733454,"avatar_url":"https://avatars.githubusercontent.com/u/1733454?v=3","gravatar_id":"","url":"https://api.github.com/users/alleyinteractive","html_url":"https://github.com/alleyinteractive","followers_url":"https://api.github.com/users/alleyinteractive/followers","following_url":"https://api.github.com/users/alleyinteractive/following{/other_user}","gists_url":"https://api.github.com/users/alleyinteractive/gists{/gist_id}","starred_url":"https://api.github.com/users/alleyinteractive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alleyinteractive/subscriptions","organizations_url":"https://api.github.com/users/alleyinteractive/orgs","repos_url":"https://api.github.com/users/alleyinteractive/repos","events_url":"https://api.github.com/users/alleyinteractive/events{/privacy}","received_events_url":"https://api.github.com/users/alleyinteractive/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alleyinteractive/huron","description":null,"fork":false,"url":"https://api.github.com/repos/alleyinteractive/huron","forks_url":"https://api.github.com/repos/alleyinteractive/huron/forks","keys_url":"https://api.github.com/repos/alleyinteractive/huron/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alleyinteractive/huron/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alleyinteractive/huron/teams","hooks_url":"https://api.github.com/repos/alleyinteractive/huron/hooks","issue_events_url":"https://api.github.com/repos/alleyinteractive/huron/issues/events{/number}","events_url":"https://api.github.com/repos/alleyinteractive/huron/events","assignees_url":"https://api.github.com/repos/alleyinteractive/huron/assignees{/user}","branches_url":"https://api.github.com/repos/alleyinteractive/huron/branches{/branch}","tags_url":"https://api.github.com/repos/alleyinteractive/huron/tags","blobs_url":"https://api.github.com/repos/alleyinteractive/huron/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alleyinteractive/huron/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alleyinteractive/huron/git/refs{/sha}","trees_url":"https://api.github.com/repos/alleyinteractive/huron/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alleyinteractive/huron/statuses/{sha}","languages_url":"https://api.github.com/repos/alleyinteractive/huron/languages","stargazers_url":"https://api.github.com/repos/alleyinteractive/huron/stargazers","contributors_url":"https://api.github.com/repos/alleyinteractive/huron/contributors","subscribers_url":"https://api.github.com/repos/alleyinteractive/huron/subscribers","subscription_url":"https://api.github.com/repos/alleyinteractive/huron/subscription","commits_url":"https://api.github.com/repos/alleyinteractive/huron/commits{/sha}","git_commits_url":"https://api.github.com/repos/alleyinteractive/huron/git/commits{/sha}","comments_url":"https://api.github.com/repos/alleyinteractive/huron/comments{/number}","issue_comment_url":"https://api.github.com/repos/alleyinteractive/huron/issues/comments{/number}","contents_url":"https://api.github.com/repos/alleyinteractive/huron/contents/{+path}","compare_url":"https://api.github.com/repos/alleyinteractive/huron/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alleyinteractive/huron/merges","archive_url":"https://api.github.com/repos/alleyinteractive/huron/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alleyinteractive/huron/downloads","issues_url":"https://api.github.com/repos/alleyinteractive/huron/issues{/number}","pulls_url":"https://api.github.com/repos/alleyinteractive/huron/pulls{/number}","milestones_url":"https://api.github.com/repos/alleyinteractive/huron/milestones{/number}","notifications_url":"https://api.github.com/repos/alleyinteractive/huron/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alleyinteractive/huron/labels{/name}","releases_url":"https://api.github.com/repos/alleyinteractive/huron/releases{/id}","deployments_url":"https://api.github.com/repos/alleyinteractive/huron/deployments","created_at":"2015-12-11T20:29:16Z","updated_at":"2016-04-06T21:08:51Z","pushed_at":"2016-11-07T21:25:33Z","git_url":"git://github.com/alleyinteractive/huron.git","ssh_url":"git@github.com:alleyinteractive/huron.git","clone_url":"https://github.com/alleyinteractive/huron.git","svn_url":"https://github.com/alleyinteractive/huron","homepage":null,"size":224,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":1,"default_branch":"master"}},"base":{"label":"alleyinteractive:1.0","ref":"1.0","sha":"0c5f40409807543cd8630e54f400647011fa2011","user":{"login":"alleyinteractive","id":1733454,"avatar_url":"https://avatars.githubusercontent.com/u/1733454?v=3","gravatar_id":"","url":"https://api.github.com/users/alleyinteractive","html_url":"https://github.com/alleyinteractive","followers_url":"https://api.github.com/users/alleyinteractive/followers","following_url":"https://api.github.com/users/alleyinteractive/following{/other_user}","gists_url":"https://api.github.com/users/alleyinteractive/gists{/gist_id}","starred_url":"https://api.github.com/users/alleyinteractive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alleyinteractive/subscriptions","organizations_url":"https://api.github.com/users/alleyinteractive/orgs","repos_url":"https://api.github.com/users/alleyinteractive/repos","events_url":"https://api.github.com/users/alleyinteractive/events{/privacy}","received_events_url":"https://api.github.com/users/alleyinteractive/received_events","type":"Organization","site_admin":false},"repo":{"id":47849410,"name":"huron","full_name":"alleyinteractive/huron","owner":{"login":"alleyinteractive","id":1733454,"avatar_url":"https://avatars.githubusercontent.com/u/1733454?v=3","gravatar_id":"","url":"https://api.github.com/users/alleyinteractive","html_url":"https://github.com/alleyinteractive","followers_url":"https://api.github.com/users/alleyinteractive/followers","following_url":"https://api.github.com/users/alleyinteractive/following{/other_user}","gists_url":"https://api.github.com/users/alleyinteractive/gists{/gist_id}","starred_url":"https://api.github.com/users/alleyinteractive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alleyinteractive/subscriptions","organizations_url":"https://api.github.com/users/alleyinteractive/orgs","repos_url":"https://api.github.com/users/alleyinteractive/repos","events_url":"https://api.github.com/users/alleyinteractive/events{/privacy}","received_events_url":"https://api.github.com/users/alleyinteractive/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alleyinteractive/huron","description":null,"fork":false,"url":"https://api.github.com/repos/alleyinteractive/huron","forks_url":"https://api.github.com/repos/alleyinteractive/huron/forks","keys_url":"https://api.github.com/repos/alleyinteractive/huron/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alleyinteractive/huron/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alleyinteractive/huron/teams","hooks_url":"https://api.github.com/repos/alleyinteractive/huron/hooks","issue_events_url":"https://api.github.com/repos/alleyinteractive/huron/issues/events{/number}","events_url":"https://api.github.com/repos/alleyinteractive/huron/events","assignees_url":"https://api.github.com/repos/alleyinteractive/huron/assignees{/user}","branches_url":"https://api.github.com/repos/alleyinteractive/huron/branches{/branch}","tags_url":"https://api.github.com/repos/alleyinteractive/huron/tags","blobs_url":"https://api.github.com/repos/alleyinteractive/huron/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alleyinteractive/huron/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alleyinteractive/huron/git/refs{/sha}","trees_url":"https://api.github.com/repos/alleyinteractive/huron/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alleyinteractive/huron/statuses/{sha}","languages_url":"https://api.github.com/repos/alleyinteractive/huron/languages","stargazers_url":"https://api.github.com/repos/alleyinteractive/huron/stargazers","contributors_url":"https://api.github.com/repos/alleyinteractive/huron/contributors","subscribers_url":"https://api.github.com/repos/alleyinteractive/huron/subscribers","subscription_url":"https://api.github.com/repos/alleyinteractive/huron/subscription","commits_url":"https://api.github.com/repos/alleyinteractive/huron/commits{/sha}","git_commits_url":"https://api.github.com/repos/alleyinteractive/huron/git/commits{/sha}","comments_url":"https://api.github.com/repos/alleyinteractive/huron/comments{/number}","issue_comment_url":"https://api.github.com/repos/alleyinteractive/huron/issues/comments{/number}","contents_url":"https://api.github.com/repos/alleyinteractive/huron/contents/{+path}","compare_url":"https://api.github.com/repos/alleyinteractive/huron/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alleyinteractive/huron/merges","archive_url":"https://api.github.com/repos/alleyinteractive/huron/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alleyinteractive/huron/downloads","issues_url":"https://api.github.com/repos/alleyinteractive/huron/issues{/number}","pulls_url":"https://api.github.com/repos/alleyinteractive/huron/pulls{/number}","milestones_url":"https://api.github.com/repos/alleyinteractive/huron/milestones{/number}","notifications_url":"https://api.github.com/repos/alleyinteractive/huron/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alleyinteractive/huron/labels{/name}","releases_url":"https://api.github.com/repos/alleyinteractive/huron/releases{/id}","deployments_url":"https://api.github.com/repos/alleyinteractive/huron/deployments","created_at":"2015-12-11T20:29:16Z","updated_at":"2016-04-06T21:08:51Z","pushed_at":"2016-11-07T21:25:33Z","git_url":"git://github.com/alleyinteractive/huron.git","ssh_url":"git@github.com:alleyinteractive/huron.git","clone_url":"https://github.com/alleyinteractive/huron.git","svn_url":"https://github.com/alleyinteractive/huron","homepage":null,"size":224,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alleyinteractive/huron/pulls/37"},"html":{"href":"https://github.com/alleyinteractive/huron/pull/37"},"issue":{"href":"https://api.github.com/repos/alleyinteractive/huron/issues/37"},"comments":{"href":"https://api.github.com/repos/alleyinteractive/huron/issues/37/comments"},"review_comments":{"href":"https://api.github.com/repos/alleyinteractive/huron/pulls/37/comments"},"review_comment":{"href":"https://api.github.com/repos/alleyinteractive/huron/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alleyinteractive/huron/pulls/37/commits"},"statuses":{"href":"https://api.github.com/repos/alleyinteractive/huron/statuses/ac65a0fcce7509a8958541ad0adf5ec52089ecd4"}}}}
{"actor":{"display_login":"pattiereaves"}}