{"action":"created","comment":{"url":"https://api.github.com/repos/krakenjs/engine-munger/pulls/comments/31482955","id":31482955,"diff_hunk":"@@ -15,51 +15,198 @@\n  │   See the License for the specific language governing permissions and       │\n  │   limitations under the License.                                            │\n  \\*───────────────────────────────────────────────────────────────────────────*/\n+\"use strict\";\n+var path = require('path');\n+var debug = require('debuglog')('engine-munger');\n+var fs = require('fs');\n+var permutron = require('permutron');\n+var oldView = require('express/lib/view');\n+var karka = require('karka');\n+var aproba = require('aproba');\n+var bcp47 = require('bcp47');\n+var bcp47stringify = require('bcp47-stringify');\n \n-'use strict';\n-var engine = require('adaro'),\n-    munger = require('./lib/munger');\n+/**\n+ * Make a View class that uses our configuration, set far in advance of\n+ * instantiation because Express passes very little to the actual constructor.\n+ */\n+function makeViewClass(config) {\n+    aproba('O', arguments);\n \n+    var conf = normalizeConfigs(config);\n \n-exports.dust = function (setting, config) {\n-    var settings =  (arguments.length > 1) ? setting : {},\n-        configs = (arguments.length > 1) ? config : setting,\n-        renderer;\n+    var proto = Object.create(oldView.prototype);\n \n-    if (!configs || !(configs.specialization || configs.i18n)) {\n-        return engine.dust(settings);\n-    }\n+    // Unfortunately, since we don't know the actual file to resolve until\n+    // we get request context (in `render`), we can't say whether it exists or not.\n+    //\n+    // Express checks that this is truthy to see if it should return an error or\n+    // run the render, so we hard code it to true.\n+    proto.path = true;\n+\n+    proto.lookup = function lookup(name, options, cb) {\n+        if (arguments.length === 1) {\n+            // This is the unoverriden constructor calling us. Ignore the call.\n+            return true;\n+        }\n+\n+        var ext = path.extname(name);\n+\n+        if (conf[ext] && conf[ext].specialization) {\n+            var nameNoExt = name.slice(0, -ext.length);\n+            var newName = conf[ext].specialization.resolve(nameNoExt, options) + ext;\n+            debug(\"specialization mapped '%s' to '%s'\", name, newName);\n+            name = newName;\n+        }\n+\n+        var search = [];\n+        search.push([].concat(conf[ext] && conf[ext].root ? conf[ext].root : this.root));\n+\n+        if (conf[ext] && conf[ext].i18n) {\n+            var i18n = conf[ext].i18n;\n+            var locales = [];\n+            if (options.locale) {\n+                locales.push(i18n.formatPath(typeof options.locale === 'object' ? options.locale : bcp47.parse(options.locale.replace(/_/g, '-'))));\n+            }\n+            if (i18n.fallback) {\n+                locales.push(i18n.formatPath(i18n.fallback));\n+            }\n+            debug(\"trying locales %j\", locales);\n+            search.push(locales);\n+        }\n+\n+        search.push([name, path.join(path.basename(name), 'index' + ext)]);\n+\n+        debug('lookup \"%s\"', name);\n+\n+        permutron.raw(search, function (candidate, next) {\n+            var resolved = path.resolve.apply(null, candidate);\n+            limitStat(resolved, function (err, stat) {\n+                if (!err && stat.isFile()) {\n+                    debug('found \"%s\"', resolved);\n+                    cb(null, resolved);\n+                } else if ((!err && stat.isDirectory()) || (err && err.code === 'ENOENT')) {\n+                    next();\n+                } else {\n+                    cb(err);","path":"index.js","position":87,"original_position":87,"commit_id":"206295ab86d119b5877bbebfa1e955802bad8013","original_commit_id":"206295ab86d119b5877bbebfa1e955802bad8013","user":{"login":"grawk","id":1031360,"avatar_url":"https://avatars.githubusercontent.com/u/1031360?v=3","gravatar_id":"","url":"https://api.github.com/users/grawk","html_url":"https://github.com/grawk","followers_url":"https://api.github.com/users/grawk/followers","following_url":"https://api.github.com/users/grawk/following{/other_user}","gists_url":"https://api.github.com/users/grawk/gists{/gist_id}","starred_url":"https://api.github.com/users/grawk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grawk/subscriptions","organizations_url":"https://api.github.com/users/grawk/orgs","repos_url":"https://api.github.com/users/grawk/repos","events_url":"https://api.github.com/users/grawk/events{/privacy}","received_events_url":"https://api.github.com/users/grawk/received_events","type":"User","site_admin":false},"body":"I guess it looks like there is no need to check that err is defined here..","created_at":"2015-06-01T23:56:30Z","updated_at":"2015-06-01T23:56:30Z","html_url":"https://github.com/krakenjs/engine-munger/pull/30#discussion_r31482955","pull_request_url":"https://api.github.com/repos/krakenjs/engine-munger/pulls/30","_links":{"self":{"href":"https://api.github.com/repos/krakenjs/engine-munger/pulls/comments/31482955"},"html":{"href":"https://github.com/krakenjs/engine-munger/pull/30#discussion_r31482955"},"pull_request":{"href":"https://api.github.com/repos/krakenjs/engine-munger/pulls/30"}}},"pull_request":{"url":"https://api.github.com/repos/krakenjs/engine-munger/pulls/30","id":36642904,"html_url":"https://github.com/krakenjs/engine-munger/pull/30","diff_url":"https://github.com/krakenjs/engine-munger/pull/30.diff","patch_url":"https://github.com/krakenjs/engine-munger/pull/30.patch","issue_url":"https://api.github.com/repos/krakenjs/engine-munger/issues/30","number":30,"state":"open","locked":false,"title":"Changes to become v1.x","user":{"login":"aredridel","id":2876,"avatar_url":"https://avatars.githubusercontent.com/u/2876?v=3","gravatar_id":"","url":"https://api.github.com/users/aredridel","html_url":"https://github.com/aredridel","followers_url":"https://api.github.com/users/aredridel/followers","following_url":"https://api.github.com/users/aredridel/following{/other_user}","gists_url":"https://api.github.com/users/aredridel/gists{/gist_id}","starred_url":"https://api.github.com/users/aredridel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aredridel/subscriptions","organizations_url":"https://api.github.com/users/aredridel/orgs","repos_url":"https://api.github.com/users/aredridel/repos","events_url":"https://api.github.com/users/aredridel/events{/privacy}","received_events_url":"https://api.github.com/users/aredridel/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-06-01T15:56:26Z","updated_at":"2015-06-01T23:56:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"65218b5fcf13d56741b411e61b5c6767d180708c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/krakenjs/engine-munger/pulls/30/commits","review_comments_url":"https://api.github.com/repos/krakenjs/engine-munger/pulls/30/comments","review_comment_url":"https://api.github.com/repos/krakenjs/engine-munger/pulls/comments{/number}","comments_url":"https://api.github.com/repos/krakenjs/engine-munger/issues/30/comments","statuses_url":"https://api.github.com/repos/krakenjs/engine-munger/statuses/206295ab86d119b5877bbebfa1e955802bad8013","head":{"label":"krakenjs:next","ref":"next","sha":"206295ab86d119b5877bbebfa1e955802bad8013","user":{"login":"krakenjs","id":7001600,"avatar_url":"https://avatars.githubusercontent.com/u/7001600?v=3","gravatar_id":"","url":"https://api.github.com/users/krakenjs","html_url":"https://github.com/krakenjs","followers_url":"https://api.github.com/users/krakenjs/followers","following_url":"https://api.github.com/users/krakenjs/following{/other_user}","gists_url":"https://api.github.com/users/krakenjs/gists{/gist_id}","starred_url":"https://api.github.com/users/krakenjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krakenjs/subscriptions","organizations_url":"https://api.github.com/users/krakenjs/orgs","repos_url":"https://api.github.com/users/krakenjs/repos","events_url":"https://api.github.com/users/krakenjs/events{/privacy}","received_events_url":"https://api.github.com/users/krakenjs/received_events","type":"Organization","site_admin":false},"repo":{"id":16780420,"name":"engine-munger","full_name":"krakenjs/engine-munger","owner":{"login":"krakenjs","id":7001600,"avatar_url":"https://avatars.githubusercontent.com/u/7001600?v=3","gravatar_id":"","url":"https://api.github.com/users/krakenjs","html_url":"https://github.com/krakenjs","followers_url":"https://api.github.com/users/krakenjs/followers","following_url":"https://api.github.com/users/krakenjs/following{/other_user}","gists_url":"https://api.github.com/users/krakenjs/gists{/gist_id}","starred_url":"https://api.github.com/users/krakenjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krakenjs/subscriptions","organizations_url":"https://api.github.com/users/krakenjs/orgs","repos_url":"https://api.github.com/users/krakenjs/repos","events_url":"https://api.github.com/users/krakenjs/events{/privacy}","received_events_url":"https://api.github.com/users/krakenjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/krakenjs/engine-munger","description":"A helper module to insert specialization and i18n in the render workflow","fork":false,"url":"https://api.github.com/repos/krakenjs/engine-munger","forks_url":"https://api.github.com/repos/krakenjs/engine-munger/forks","keys_url":"https://api.github.com/repos/krakenjs/engine-munger/keys{/key_id}","collaborators_url":"https://api.github.com/repos/krakenjs/engine-munger/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/krakenjs/engine-munger/teams","hooks_url":"https://api.github.com/repos/krakenjs/engine-munger/hooks","issue_events_url":"https://api.github.com/repos/krakenjs/engine-munger/issues/events{/number}","events_url":"https://api.github.com/repos/krakenjs/engine-munger/events","assignees_url":"https://api.github.com/repos/krakenjs/engine-munger/assignees{/user}","branches_url":"https://api.github.com/repos/krakenjs/engine-munger/branches{/branch}","tags_url":"https://api.github.com/repos/krakenjs/engine-munger/tags","blobs_url":"https://api.github.com/repos/krakenjs/engine-munger/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/krakenjs/engine-munger/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/krakenjs/engine-munger/git/refs{/sha}","trees_url":"https://api.github.com/repos/krakenjs/engine-munger/git/trees{/sha}","statuses_url":"https://api.github.com/repos/krakenjs/engine-munger/statuses/{sha}","languages_url":"https://api.github.com/repos/krakenjs/engine-munger/languages","stargazers_url":"https://api.github.com/repos/krakenjs/engine-munger/stargazers","contributors_url":"https://api.github.com/repos/krakenjs/engine-munger/contributors","subscribers_url":"https://api.github.com/repos/krakenjs/engine-munger/subscribers","subscription_url":"https://api.github.com/repos/krakenjs/engine-munger/subscription","commits_url":"https://api.github.com/repos/krakenjs/engine-munger/commits{/sha}","git_commits_url":"https://api.github.com/repos/krakenjs/engine-munger/git/commits{/sha}","comments_url":"https://api.github.com/repos/krakenjs/engine-munger/comments{/number}","issue_comment_url":"https://api.github.com/repos/krakenjs/engine-munger/issues/comments{/number}","contents_url":"https://api.github.com/repos/krakenjs/engine-munger/contents/{+path}","compare_url":"https://api.github.com/repos/krakenjs/engine-munger/compare/{base}...{head}","merges_url":"https://api.github.com/repos/krakenjs/engine-munger/merges","archive_url":"https://api.github.com/repos/krakenjs/engine-munger/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/krakenjs/engine-munger/downloads","issues_url":"https://api.github.com/repos/krakenjs/engine-munger/issues{/number}","pulls_url":"https://api.github.com/repos/krakenjs/engine-munger/pulls{/number}","milestones_url":"https://api.github.com/repos/krakenjs/engine-munger/milestones{/number}","notifications_url":"https://api.github.com/repos/krakenjs/engine-munger/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/krakenjs/engine-munger/labels{/name}","releases_url":"https://api.github.com/repos/krakenjs/engine-munger/releases{/id}","created_at":"2014-02-12T20:16:21Z","updated_at":"2015-04-27T18:38:05Z","pushed_at":"2015-06-01T19:31:44Z","git_url":"git://github.com/krakenjs/engine-munger.git","ssh_url":"git@github.com:krakenjs/engine-munger.git","clone_url":"https://github.com/krakenjs/engine-munger.git","svn_url":"https://github.com/krakenjs/engine-munger","homepage":null,"size":664,"stargazers_count":6,"watchers_count":6,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":1,"forks":9,"open_issues":1,"watchers":6,"default_branch":"master"}},"base":{"label":"krakenjs:v1.x","ref":"v1.x","sha":"7394cf8ebb6ac37f8a9dd9032db3931c6e47e624","user":{"login":"krakenjs","id":7001600,"avatar_url":"https://avatars.githubusercontent.com/u/7001600?v=3","gravatar_id":"","url":"https://api.github.com/users/krakenjs","html_url":"https://github.com/krakenjs","followers_url":"https://api.github.com/users/krakenjs/followers","following_url":"https://api.github.com/users/krakenjs/following{/other_user}","gists_url":"https://api.github.com/users/krakenjs/gists{/gist_id}","starred_url":"https://api.github.com/users/krakenjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krakenjs/subscriptions","organizations_url":"https://api.github.com/users/krakenjs/orgs","repos_url":"https://api.github.com/users/krakenjs/repos","events_url":"https://api.github.com/users/krakenjs/events{/privacy}","received_events_url":"https://api.github.com/users/krakenjs/received_events","type":"Organization","site_admin":false},"repo":{"id":16780420,"name":"engine-munger","full_name":"krakenjs/engine-munger","owner":{"login":"krakenjs","id":7001600,"avatar_url":"https://avatars.githubusercontent.com/u/7001600?v=3","gravatar_id":"","url":"https://api.github.com/users/krakenjs","html_url":"https://github.com/krakenjs","followers_url":"https://api.github.com/users/krakenjs/followers","following_url":"https://api.github.com/users/krakenjs/following{/other_user}","gists_url":"https://api.github.com/users/krakenjs/gists{/gist_id}","starred_url":"https://api.github.com/users/krakenjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krakenjs/subscriptions","organizations_url":"https://api.github.com/users/krakenjs/orgs","repos_url":"https://api.github.com/users/krakenjs/repos","events_url":"https://api.github.com/users/krakenjs/events{/privacy}","received_events_url":"https://api.github.com/users/krakenjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/krakenjs/engine-munger","description":"A helper module to insert specialization and i18n in the render workflow","fork":false,"url":"https://api.github.com/repos/krakenjs/engine-munger","forks_url":"https://api.github.com/repos/krakenjs/engine-munger/forks","keys_url":"https://api.github.com/repos/krakenjs/engine-munger/keys{/key_id}","collaborators_url":"https://api.github.com/repos/krakenjs/engine-munger/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/krakenjs/engine-munger/teams","hooks_url":"https://api.github.com/repos/krakenjs/engine-munger/hooks","issue_events_url":"https://api.github.com/repos/krakenjs/engine-munger/issues/events{/number}","events_url":"https://api.github.com/repos/krakenjs/engine-munger/events","assignees_url":"https://api.github.com/repos/krakenjs/engine-munger/assignees{/user}","branches_url":"https://api.github.com/repos/krakenjs/engine-munger/branches{/branch}","tags_url":"https://api.github.com/repos/krakenjs/engine-munger/tags","blobs_url":"https://api.github.com/repos/krakenjs/engine-munger/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/krakenjs/engine-munger/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/krakenjs/engine-munger/git/refs{/sha}","trees_url":"https://api.github.com/repos/krakenjs/engine-munger/git/trees{/sha}","statuses_url":"https://api.github.com/repos/krakenjs/engine-munger/statuses/{sha}","languages_url":"https://api.github.com/repos/krakenjs/engine-munger/languages","stargazers_url":"https://api.github.com/repos/krakenjs/engine-munger/stargazers","contributors_url":"https://api.github.com/repos/krakenjs/engine-munger/contributors","subscribers_url":"https://api.github.com/repos/krakenjs/engine-munger/subscribers","subscription_url":"https://api.github.com/repos/krakenjs/engine-munger/subscription","commits_url":"https://api.github.com/repos/krakenjs/engine-munger/commits{/sha}","git_commits_url":"https://api.github.com/repos/krakenjs/engine-munger/git/commits{/sha}","comments_url":"https://api.github.com/repos/krakenjs/engine-munger/comments{/number}","issue_comment_url":"https://api.github.com/repos/krakenjs/engine-munger/issues/comments{/number}","contents_url":"https://api.github.com/repos/krakenjs/engine-munger/contents/{+path}","compare_url":"https://api.github.com/repos/krakenjs/engine-munger/compare/{base}...{head}","merges_url":"https://api.github.com/repos/krakenjs/engine-munger/merges","archive_url":"https://api.github.com/repos/krakenjs/engine-munger/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/krakenjs/engine-munger/downloads","issues_url":"https://api.github.com/repos/krakenjs/engine-munger/issues{/number}","pulls_url":"https://api.github.com/repos/krakenjs/engine-munger/pulls{/number}","milestones_url":"https://api.github.com/repos/krakenjs/engine-munger/milestones{/number}","notifications_url":"https://api.github.com/repos/krakenjs/engine-munger/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/krakenjs/engine-munger/labels{/name}","releases_url":"https://api.github.com/repos/krakenjs/engine-munger/releases{/id}","created_at":"2014-02-12T20:16:21Z","updated_at":"2015-04-27T18:38:05Z","pushed_at":"2015-06-01T19:31:44Z","git_url":"git://github.com/krakenjs/engine-munger.git","ssh_url":"git@github.com:krakenjs/engine-munger.git","clone_url":"https://github.com/krakenjs/engine-munger.git","svn_url":"https://github.com/krakenjs/engine-munger","homepage":null,"size":664,"stargazers_count":6,"watchers_count":6,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":1,"forks":9,"open_issues":1,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/krakenjs/engine-munger/pulls/30"},"html":{"href":"https://github.com/krakenjs/engine-munger/pull/30"},"issue":{"href":"https://api.github.com/repos/krakenjs/engine-munger/issues/30"},"comments":{"href":"https://api.github.com/repos/krakenjs/engine-munger/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/krakenjs/engine-munger/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/krakenjs/engine-munger/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/krakenjs/engine-munger/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/krakenjs/engine-munger/statuses/206295ab86d119b5877bbebfa1e955802bad8013"}}}}