gorilla

pez 2015-11-19T19:13:15.000004Z

I have this strange thing when trying to get Gorilla REPL to work for a project I’m involved in. It’s a leiningen project and I have added lein-gorilla “0.3.4” as a plugin. Starting the REPL I get the expected messages, including the URL at which to access the REPL. But when I do the page renders blank except the “hamburger” menu (which seems to work). And I get two JS errors in tne console:

ReferenceError: Can't find variable: exports: utils.js:13
ReferenceError: Can't find variable: makeHipNSName: main.js:78

pez 2015-11-19T19:14:06.000005Z

If I create a new project then Gorilla works wonderfully.

pez 2015-11-19T19:14:32.000006Z

Anyone have a clue?

2015-11-19T20:49:29.000011Z

@pez Sounds like Gorilla isn't serving up the files ... I wonder whether you're seeing the menu because of browser caching. Is there anything in the project which might interfere with Gorilla's server?

pez 2015-11-19T20:57:54.000012Z

@jonyepsilon: I don’t know what in the project that could interfere… Or even how it could interfere. But yes, since it works in a fresh project I am leaning towards that as well.

pez 2015-11-19T20:58:26.000013Z

As for caching, clearing the cache doesn’t make a difference. Running fresh in another browser gives the same errors and the same behaviour.

2015-11-19T20:59:21.000014Z

Huh. Would be interesting to look at http://127.0.0.1:8990/js/utils.js and see what returns (adjusting the port number to suit).

pez 2015-11-19T21:00:36.000015Z

'use strict';

/**
 * Get a deep value from an object by a string path
 * For example:
 * var foo = {'bar': {'lurker': 'someValue'}}
 * getValByPath(foo, 'bar.lurker') returns 'someValue'
 *
 * @param obj obj
 * @param str path
 * @return mixed
 */
exports.getValByPath = function(obj, path) {
	var p;

	if (typeof path === 'string') {
		path = path.split('.');
	}

	if (path.length > 1) {
		p = path.shift();

		if (typeof obj[p] === 'object') {
			return exports.getValByPath(obj[p], path);
		} else {
			return undefined;
		}

	} else {
		return obj[path[0]];
	}
};

2015-11-19T21:01:08.000016Z

That's very odd ... that's not Gorilla REPL code! Should be:

2015-11-19T21:01:12.000017Z

/*
 * This file is part of gorilla-repl. Copyright (C) 2014-, Jony Hudson.
 *
 * gorilla-repl is licenced to you under the MIT licence. See the file LICENCE.txt for full details.
 */

// takes a string and prefixes every line with ';; '
var makeClojureComment = function (code) {
    return code.split('\n').map(function (x) {
        return ";;; " + x;
    }).join("\n")
};

// the funny name indicates that it undoes what the above function does. It doesn't check whether the line is actually
// commented, so will break text that isn't in the format it expects.
var unmakeClojureComment = function (code) {
    if (code) {
        return code.split('\n').map(function (x) {
            return x.slice(4);
        }).join("\n");
    }
    else return null;
};


var makeHipNSName = function () {
    // The word lists are taken from Raymond Chan's MIT-licensed <https://github.com/raycchan/bazaar>
    var adj = ["affectionate", "amiable", "arrogant", "balmy", "barren", "benevolent", "billowing", "blessed", "breezy", "calm", "celestial", "charming", "combative", "composed", "condemned", "divine", "dry", "energized", "enigmatic", "exuberant", "flowing", "fluffy", "fluttering", "frightened", "fuscia", "gentle", "greasy", "grieving", "harmonious", "hollow", "homeless", "icy", "indigo", "inquisitive", "itchy", "joyful", "jubilant", "juicy", "khaki", "limitless", "lush", "mellow", "merciful", "merry", "mirthful", "moonlit", "mysterious", "natural", "outrageous", "pacific", "parched", "placid", "pleasant", "poised", "purring", "radioactive", "resilient", "scenic", "screeching", "sensitive", "serene", "snowy", "solitary", "spacial", "squealing", "stark", "stunning", "sunset", "talented", "tasteless", "teal", "thoughtless", "thriving", "tranquil", "tropical", "undisturbed", "unsightly", "unwavering", "uplifting", "voiceless", "wandering", "warm", "wealthy", "whispering", "withered", "wooden", "zealous"];
    var things = ["abyss", "atoll", "aurora", "autumn", "badlands", "beach", "briars", "brook", "canopy", "canyon", "cavern", "chasm", "cliff", "cove", "crater", "creek", "darkness", "dawn", "desert", "dew", "dove", "drylands", "dusk", "farm", "fern", "firefly", "flowers", "fog", "foliage", "forest", "galaxy", "garden", "geyser", "grove", "hurricane", "iceberg", "lagoon", "lake", "leaves", "marsh", "meadow", "mist", "moss", "mountain", "oasis", "ocean", "peak", "pebble", "pine", "plateau", "pond", "reef", "reserve", "resonance", "sanctuary", "sands", "shelter", "silence", "smokescreen", "snowflake", "spring", "storm", "stream", "summer", "summit", "sunrise", "sunset", "sunshine", "surf", "swamp", "temple", "thorns", "tsunami", "tundra", "valley", "volcano", "waterfall", "willow", "winds", "winter"];
    var adjI = Math.floor(Math.random() * adj.length);
    var thingsI = Math.floor(Math.random() * things.length);
    return adj[adjI] + "-" + things[thingsI];
};

pez 2015-11-19T21:02:05.000018Z

Looks very different from the same in the working project.

pez 2015-11-19T21:02:32.000019Z

Yes, that is what it looks like.

2015-11-19T21:02:39.000020Z

Wonder where that code is coming from ... don't find getValByPath(foo, 'bar.lurker') returns 'someValue' on Google anywhere.

2015-11-19T21:05:23.000021Z

Key will be figuring out where that comes from, I guess. Any plugins in your profiles.clj that could be messing with ring routes etc?

pez 2015-11-19T21:07:29.000022Z

I find it in my project actually.

pez 2015-11-19T21:08:08.000023Z

(lurker, that is)

2015-11-19T21:09:18.000024Z

Oh, I wonder ... Gorilla serves its files out of the jar's resources. If you're project has resources with the same path (that is resources\public\js\utils.js then this could happen. Never thought of that!

pez 2015-11-19T21:09:21.000025Z

resources/public/js … i guess that somehow overshadows whatever js/ path gorilla uses

2015-11-19T21:09:42.000026Z

Probably Gorilla should put it's resources somewhere with an unlikely name to avoid this sort of clash.

pez 2015-11-19T21:09:56.000027Z

ha, you figured it out even without looking in my project!

pez 2015-11-19T21:11:46.000028Z

Maybe Gorilla can just load from gorilla-repl/js/...

2015-11-19T21:12:06.000029Z

Yeah, that would work. Should be an easy fix. Was hoping to get a new version out soonish and will put it in that.

pez 2015-11-19T21:12:10.000032Z

Anyway, I can move stuff around and make this work. Many thanks!

2015-11-19T21:12:22.000033Z

Glad we got to the bottom of it :simple_smile:

pez 2015-11-19T21:13:18.000034Z

And we have an issue to track. 😃

pez 2015-11-19T21:14:19.000035Z

Your videos on how to get started are awesome by the way. Not to mention Gorilla itself.

2015-11-19T21:15:07.000036Z

Thanks :simple_smile: Glad you find them useful!