From 14dd1ae5097e2fbbb27e8664ece16f7307c9dbce Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Fri, 1 Jul 2016 20:46:02 -0700 Subject: [PATCH 01/26] Update github urls for recent name change --- README.md | 4 ++-- app/scripts/template/sidebar.htm | 6 +++--- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a6e9678..32da85a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ In the project root run It will install dependencies via npm and regenerate the static files into the `build` directory. -The [developer vm](https://github.com/CPAN-API/metacpan-developer) +The [developer vm](https://github.com/metacpan/metacpan-developer) has everything you need for this. To run it somewhere else you'll need to make sure you have @@ -25,7 +25,7 @@ To run it somewhere else you'll need to make sure you have ## Adding Examples -Login using the credentials from https://github.com/CPAN-API/metacpan-credentials/blob/master/github and go to https://gist.github.com/. +Login using the credentials from https://github.com/metacpan/metacpan-credentials/blob/master/github and go to https://gist.github.com/. Create a new **public** gist with the following file structure: * endpoint.txt diff --git a/app/scripts/template/sidebar.htm b/app/scripts/template/sidebar.htm index dacb147..59f0fc2 100644 --- a/app/scripts/template/sidebar.htm +++ b/app/scripts/template/sidebar.htm @@ -11,7 +11,7 @@ -
  • API Documentation
  • -
  • Report Issue
  • -
  • Fork Me
  • +
  • API Documentation
  • +
  • Report Issue
  • +
  • Fork Me
  • diff --git a/package.json b/package.json index ba6b8f6..3e86376 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "//": "Define repository to silence npm warning.", "repository": { "type": "git", - "url": "http://github.com/CPAN-API/metacpan-explorer" + "url": "http://github.com/metacpan/metacpan-explorer" }, "devDependencies": { "clean-css": ">=2.2", From e9acd3ca7b73c7e847f4fd40958c89d7a4c56d24 Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Fri, 1 Jul 2016 20:52:49 -0700 Subject: [PATCH 02/26] Get github token from external function --- app/index.html | 1 + app/scripts/model/request.js | 2 +- app/scripts/store/gist.js | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/index.html b/app/index.html index 68f2b42..47590fc 100644 --- a/app/index.html +++ b/app/index.html @@ -10,6 +10,7 @@ MetaCPAN Explorer + diff --git a/app/scripts/model/request.js b/app/scripts/model/request.js index e24fb05..af1a45a 100644 --- a/app/scripts/model/request.js +++ b/app/scripts/model/request.js @@ -12,7 +12,7 @@ define(["jquery", "underscore", "model", "store/gist"], function($, _, Model, St var curl = "curl " + (this.get("body") ? "-XPOST " : "") + "'api.metacpan.org" + this.get("endpoint") + "'"; if(this.get("body")){ - curl += " -d \"$(curl -Ls gist.github.com/metacpan/" + this.id + "/raw/body.json)\""; + curl += " -d \"$(curl -Ls gist.github.com/" + this.store.config.user + "/" + this.id + "/raw/body.json)\""; } return curl; }, diff --git a/app/scripts/store/gist.js b/app/scripts/store/gist.js index c6ee0bb..a213530 100644 --- a/app/scripts/store/gist.js +++ b/app/scripts/store/gist.js @@ -2,8 +2,12 @@ define(["jquery", "underscore", "backbone"], function($, _, Backbone) { var Storage = function() { return; }; _.extend(Storage.prototype, Backbone.Events, { + config: { + user: 'metacpan-user', + token: github_token() + }, request: function(options) { - options.url += "?access_token=62ac27f3962648d0e158992cbaa3cc3bd8562995"; + options.url += "?access_token=" + this.config.token; return $.ajax(options); }, find: function(model, options) { @@ -15,7 +19,7 @@ define(["jquery", "underscore", "backbone"], function($, _, Backbone) { }, findAll: function() { return $.ajax({ - url: "https://api.github.com/users/metacpan/gists", + url: "https://api.github.com/users/" + this.config.user + "/gists", context: this, dataType: "json" }); From 1251e5648b48553096ed743560f6b6cecbe016cd Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Fri, 1 Jul 2016 20:55:08 -0700 Subject: [PATCH 03/26] Generate github token for dev server --- README.md | 5 +++++ server.js | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32da85a..576ebb8 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,11 @@ has everything you need for this. To run it somewhere else you'll need to make sure you have [node.js](http://nodejs.org/) and [npm](http://npmjs.org/) installed. +## Running the development server + +You can run `node server.js` (or `npm start`) to launch a dev server. +See the comments in `server.js` for additional instructions. + ## Adding Examples Login using the credentials from https://github.com/metacpan/metacpan-credentials/blob/master/github and go to https://gist.github.com/. diff --git a/server.js b/server.js index 3435d9c..1b0ba45 100755 --- a/server.js +++ b/server.js @@ -1,5 +1,8 @@ #!/usr/bin/env node +// NOTE: You should get the github token from the private conf repo +// and export it as GITHUB_TOKEN before running this server. + var fs = require('fs'); var Static = require('node-static'); @@ -15,7 +18,13 @@ var startServer = function(dir, port) { require('http').createServer(function (request, response) { request.addListener('end', function () { - httpd.serve(request, response); + if (request.url === '/github.js') { + response.writeHead(200, {'Content-Type': 'text/javascript'}); + response.end('function github_token () { return ' + JSON.stringify(process.env.GITHUB_TOKEN || 'token') + '; }'); + } + else { + httpd.serve(request, response); + } }).resume(); }).listen(port); From f89799853398d15444b4df6d1a056b8623f4987b Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Fri, 1 Jul 2016 21:02:11 -0700 Subject: [PATCH 04/26] Use function vars instead of RegExp globals --- env-filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/env-filter.js b/env-filter.js index f1329e2..e4c1bbc 100644 --- a/env-filter.js +++ b/env-filter.js @@ -6,9 +6,9 @@ process.stdin.on("end", function(){ process.stdout.write( text .replace(/\{\{bust\}\}/g, bust) - .replace(/(?:)?/g, function(){ + .replace(/(?:)?/g, function(_, env, content){ // Enable the contents of the 'build' sections and remove the 'dev' sections. - return RegExp.$1 == 'build' ? RegExp.$2 : ''; + return env === 'build' ? content : ''; }) // Remove any remaining blank lines. .replace(/\n{2,}/g, "\n") From 283296eb98bceb8d7aa6ed20dcb5507d48f9405e Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Fri, 1 Jul 2016 21:02:48 -0700 Subject: [PATCH 05/26] Move build steps into npm scripts It's more consistent for the npm-initiated and allows skipping the install step. --- build.sh | 5 +---- package.json | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index ab9b5b4..8d7de0b 100755 --- a/build.sh +++ b/build.sh @@ -3,7 +3,4 @@ npm install export PATH=`npm bin || echo node_modules/.bin`:$PATH -r.js -o app.build.js -lessc --clean-css app/styles/main.less > build/styles.css - -node env-filter.js < app/index.html > build/index.html +npm run build diff --git a/package.json b/package.json index 3e86376..91c6da4 100644 --- a/package.json +++ b/package.json @@ -11,5 +11,11 @@ }, "optionalDependencies": { "node-static": "x" + }, + "scripts": { + "js": "r.js -o app.build.js", + "css": "lessc --clean-css app/styles/main.less > build/styles.css", + "html": "node env-filter.js < app/index.html > build/index.html", + "build": "npm run js && npm run css && npm run html" } } From 3c83255bc3c6329bfc7541303404dccc08a9a1ca Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Fri, 1 Jul 2016 21:04:39 -0700 Subject: [PATCH 06/26] Rebuild --- build/app.js | 2 +- build/index.html | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/build/app.js b/build/app.js index 87bcbeb..a99cf32 100644 --- a/build/app.js +++ b/build/app.js @@ -122,4 +122,4 @@ * limitations under the License. * ========================================================= */ -(function(){var requirejs,require,define;(function(e){function c(e,t){return f.call(e,t)}function h(e,t){var n,r,i,s,o,a,f,l,c,h,p=t&&t.split("/"),d=u.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(l=0;l0&&(e.splice(l-1,2),l-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(l=n.length;l>0;l-=1){r=n.slice(0,l).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=l;break}}}if(s)break;!a&&v&&v[r]&&(a=v[r],f=l)}!s&&a&&(s=a,o=f),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function p(t,r){return function(){return n.apply(e,l.call(arguments,0).concat([t,r]))}}function d(e){return function(t){return h(t,e)}}function v(e){return function(t){s[e]=t}}function m(n){if(c(o,n)){var r=o[n];delete o[n],a[n]=!0,t.apply(e,r)}if(!c(s,n)&&!c(a,n))throw new Error("No "+n);return s[n]}function g(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function y(e){return function(){return u&&u.config&&u.config[e]||{}}}var t,n,r,i,s={},o={},u={},a={},f=Object.prototype.hasOwnProperty,l=[].slice;r=function(e,t){var n,r=g(e),i=r[0];return e=r[1],i&&(i=h(i,t),n=m(i)),i?n&&n.normalize?e=n.normalize(e,d(t)):e=h(e,t):(e=h(e,t),r=g(e),i=r[0],e=r[1],i&&(n=m(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},i={require:function(e){return p(e)},exports:function(e){var t=s[e];return typeof t!="undefined"?t:s[e]={}},module:function(e){return{id:e,uri:"",exports:s[e],config:y(e)}}},t=function(t,n,u,f){var l,h,d,g,y,b=[],w;f=f||t;if(typeof u=="function"){n=!n.length&&u.length?["require","exports","module"]:n;for(y=0;y0&&t-1 in e)}function B(e){var t=H[e]={};return b.each(e.match(E)||[],function(e,n){t[n]=!0}),t}function I(e,n,r,i){if(b.acceptData(e)){var s,o,u=b.expando,a="string"==typeof n,f=e.nodeType,c=f?b.cache:e,h=f?e[u]:e[u]&&u;if(h&&c[h]&&(i||c[h].data)||!a||r!==t)return h||(f?e[u]=h=l.pop()||b.guid++:h=u),c[h]||(c[h]={},f||(c[h].toJSON=b.noop)),("object"==typeof n||"function"==typeof n)&&(i?c[h]=b.extend(c[h],n):c[h].data=b.extend(c[h].data,n)),s=c[h],i||(s.data||(s.data={}),s=s.data),r!==t&&(s[b.camelCase(n)]=r),a?(o=s[n],null==o&&(o=s[b.camelCase(n)])):o=s,o}}function q(e,t,n){if(b.acceptData(e)){var r,i,s,o=e.nodeType,u=o?b.cache:e,a=o?e[b.expando]:b.expando;if(u[a]){if(t&&(s=n?u[a]:u[a].data)){b.isArray(t)?t=t.concat(b.map(t,b.camelCase)):t in s?t=[t]:(t=b.camelCase(t),t=t in s?[t]:t.split(" "));for(r=0,i=t.length;i>r;r++)delete s[t[r]];if(!(n?U:b.isEmptyObject)(s))return}(n||(delete u[a].data,U(u[a])))&&(o?b.cleanData([e],!0):b.support.deleteExpando||u!=u.window?delete u[a]:u[a]=null)}}}function R(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(F,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:j.test(r)?b.parseJSON(r):r}catch(s){}b.data(e,n,r)}else r=t}return r}function U(e){var t;for(t in e)if(("data"!==t||!b.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}function it(){return!0}function st(){return!1}function ct(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}function ht(e,t,n){if(t=t||0,b.isFunction(t))return b.grep(e,function(e,r){var i=!!t.call(e,r,e);return i===n});if(t.nodeType)return b.grep(e,function(e){return e===t===n});if("string"==typeof t){var r=b.grep(e,function(e){return 1===e.nodeType});if(at.test(t))return b.filter(t,r,!n);t=b.filter(t,r)}return b.grep(e,function(e){return b.inArray(e,t)>=0===n})}function pt(e){var t=dt.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}function Mt(e,t){return e.getElementsByTagName(t)[0]||e.appendChild(e.ownerDocument.createElement(t))}function _t(e){var t=e.getAttributeNode("type");return e.type=(t&&t.specified)+"/"+e.type,e}function Dt(e){var t=Ct.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function Pt(e,t){var n,r=0;for(;null!=(n=e[r]);r++)b._data(n,"globalEval",!t||b._data(t[r],"globalEval"))}function Ht(e,t){if(1===t.nodeType&&b.hasData(e)){var n,r,i,s=b._data(e),o=b._data(t,s),u=s.events;if(u){delete o.handle,o.events={};for(n in u)for(r=0,i=u[n].length;i>r;r++)b.event.add(t,n,u[n][r])}o.data&&(o.data=b.extend({},o.data))}}function Bt(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!b.support.noCloneEvent&&t[b.expando]){i=b._data(t);for(r in i.events)b.removeEvent(t,r,i.handle);t.removeAttribute(b.expando)}"script"===n&&t.text!==e.text?(_t(t).text=e.text,Dt(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),b.support.html5Clone&&e.innerHTML&&!b.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&xt.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}function jt(e,n){var r,s,o=0,u=typeof e.getElementsByTagName!==i?e.getElementsByTagName(n||"*"):typeof e.querySelectorAll!==i?e.querySelectorAll(n||"*"):t;if(!u)for(u=[],r=e.childNodes||e;null!=(s=r[o]);o++)!n||b.nodeName(s,n)?u.push(s):b.merge(u,jt(s,n));return n===t||n&&b.nodeName(e,n)?b.merge([e],u):u}function Ft(e){xt.test(e.type)&&(e.defaultChecked=e.checked)}function tn(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=en.length;while(i--)if(t=en[i]+n,t in e)return t;return r}function nn(e,t){return e=t||e,"none"===b.css(e,"display")||!b.contains(e.ownerDocument,e)}function rn(e,t){var n,r,i,s=[],o=0,u=e.length;for(;u>o;o++)r=e[o],r.style&&(s[o]=b._data(r,"olddisplay"),n=r.style.display,t?(s[o]||"none"!==n||(r.style.display=""),""===r.style.display&&nn(r)&&(s[o]=b._data(r,"olddisplay",an(r.nodeName)))):s[o]||(i=nn(r),(n&&"none"!==n||!i)&&b._data(r,"olddisplay",i?n:b.css(r,"display"))));for(o=0;u>o;o++)r=e[o],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?s[o]||"":"none"));return e}function sn(e,t,n){var r=$t.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function on(e,t,n,r,i){var s=n===(r?"border":"content")?4:"width"===t?1:0,o=0;for(;4>s;s+=2)"margin"===n&&(o+=b.css(e,n+Zt[s],!0,i)),r?("content"===n&&(o-=b.css(e,"padding"+Zt[s],!0,i)),"margin"!==n&&(o-=b.css(e,"border"+Zt[s]+"Width",!0,i))):(o+=b.css(e,"padding"+Zt[s],!0,i),"padding"!==n&&(o+=b.css(e,"border"+Zt[s]+"Width",!0,i)));return o}function un(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,s=qt(e),o=b.support.boxSizing&&"border-box"===b.css(e,"boxSizing",!1,s);if(0>=i||null==i){if(i=Rt(e,t,s),(0>i||null==i)&&(i=e.style[t]),Jt.test(i))return i;r=o&&(b.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+on(e,t,n||(o?"border":"content"),r,s)+"px"}function an(e){var t=s,n=Qt[e];return n||(n=fn(e,t),"none"!==n&&n||(It=(It||b("