Skip to content

Commit 3ca9600

Browse files
author
pemrouz
committed
doc: add polymer shop demo
1 parent c1567cb commit 3ca9600

File tree

186 files changed

+1404
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+1404
-0
lines changed

shop/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

shop/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

shop/README.md

Lines changed: 89 additions & 0 deletions

shop/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Shop</title>
5+
<script src="/decouter.js"></script>
6+
<script src="/ripple.min.js" transports="websocket,polling"></script>
7+
</head>
8+
<body style="margin: 0; min-height: 100vh">
9+
<app-shop data="routes categories"></app-shop>
10+
</body>
11+
</html>

shop/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var app = require('express')()
2+
, compress = require('compression')()
3+
, server = app.use(compress).listen(4000)
4+
, ripple = require('rijs').default({ server })
5+
, serve = require('serve-static')
6+
, { router } = require('decouter')
7+
, { routes } = ripple('routes')
8+
, root = __dirname
9+
10+
app
11+
.use(serve(__dirname+'/public'))
12+
.use(router(routes))
13+
.get('/*', (req, res) => res.sendFile('index.html', { root }))

shop/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "shop",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "babel-node index.js --color"
8+
},
9+
"keywords": [],
10+
"author": "Pedram Emrouznejad (https://github.com/pemrouz)",
11+
"license": "pemrouz.mit-license.org",
12+
"dependencies": {
13+
"babel-preset-es2015": "^6.14.0",
14+
"compression": "^1.6.2",
15+
"decouter": "pemrouz/decouter",
16+
"express": "^4.14.0",
17+
"rijs": "^0.6.4",
18+
"serve-static": "^1.11.1"
19+
}
20+
}

shop/public/decouter.js

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2+
'use strict';
3+
4+
Object.defineProperty(exports, "__esModule", {
5+
value: true
6+
});
7+
exports.resolve = exports.router = undefined;
8+
9+
var _client = require('utilise/client');
10+
11+
var _client2 = _interopRequireDefault(_client);
12+
13+
var _keys = require('utilise/keys');
14+
15+
var _keys2 = _interopRequireDefault(_keys);
16+
17+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18+
19+
var log = require('utilise/log')('[router]');
20+
var go = function go(url) {
21+
return (window.event && window.event.preventDefault(), true), history.pushState({}, '', url), window.dispatchEvent(new CustomEvent('change')), url;
22+
};
23+
24+
var router = function router(routes) {
25+
return !_client2.default ? route : route({ url: location.pathname });
26+
27+
function route(req, res, next) {
28+
var from = req.url,
29+
resolved = resolve(routes)(req),
30+
to = resolved.url;
31+
32+
if (from !== to) log('router redirecting', from, to);
33+
if (_client2.default) location.params = resolved.params;
34+
35+
return _client2.default && from !== to ? (go(to), resolved) : !_client2.default && from !== to ? res.redirect(to) : !_client2.default ? next() : resolved;
36+
}
37+
};
38+
39+
var resolve = function resolve(root) {
40+
return function (req, from) {
41+
var params = {},
42+
url = from || req.url,
43+
to = root({ url: url, req: req, params: params, next: next(req, url, params) });
44+
45+
return to !== true ? resolve(root)(req, to) : { url: url, params: params };
46+
};
47+
};
48+
49+
var next = function next(req, url, params) {
50+
return function (handlers) {
51+
var _segment = segment(url);
52+
53+
var first = _segment.first;
54+
var last = _segment.last;
55+
var to = '';
56+
57+
return first in handlers ? handlers[first]({ req: req, next: next(req, last, params), params: params, current: first }) : (0, _keys2.default)(handlers).filter(function (k) {
58+
return k[0] == ':';
59+
}).some(function (k) {
60+
var pm = k.slice(1);
61+
if (to = handlers[k]({ req: req, next: next(req, last, params), params: params, current: first })) params[pm] = first;
62+
63+
return to;
64+
}) && to;
65+
};
66+
};
67+
68+
function segment(url) {
69+
var segments = url.split('/').filter(Boolean);
70+
return { first: segments.shift(), last: segments.join('/') };
71+
}
72+
73+
if (_client2.default) {
74+
window.go = go;
75+
window.router = router;
76+
window.addEventListener('popstate', function (e) {
77+
return window.dispatchEvent(new CustomEvent('change'));
78+
});
79+
window.addEventListener('change', function (e) {
80+
return e.target == window && (window.app || document).draw && (window.app || document).draw();
81+
});
82+
document.addEventListener('click', function (e) {
83+
var a = e.path ? e.path.shift() : e.target;
84+
if (!a.matches('a[href]:not([href^=javascript]):not(.bypass)')) return;
85+
if (a.origin != location.origin) return;
86+
// console.log("e", a.href)
87+
e.preventDefault();
88+
go(a.href);
89+
});
90+
}
91+
92+
exports.router = router;
93+
exports.resolve = resolve;
94+
},{"utilise/client":2,"utilise/keys":4,"utilise/log":5}],2:[function(require,module,exports){
95+
module.exports = typeof window != 'undefined'
96+
},{}],3:[function(require,module,exports){
97+
module.exports = is
98+
is.fn = isFunction
99+
is.str = isString
100+
is.num = isNumber
101+
is.obj = isObject
102+
is.lit = isLiteral
103+
is.bol = isBoolean
104+
is.truthy = isTruthy
105+
is.falsy = isFalsy
106+
is.arr = isArray
107+
is.null = isNull
108+
is.def = isDef
109+
is.in = isIn
110+
111+
function is(v){
112+
return function(d){
113+
return d == v
114+
}
115+
}
116+
117+
function isFunction(d) {
118+
return typeof d == 'function'
119+
}
120+
121+
function isBoolean(d) {
122+
return typeof d == 'boolean'
123+
}
124+
125+
function isString(d) {
126+
return typeof d == 'string'
127+
}
128+
129+
function isNumber(d) {
130+
return typeof d == 'number'
131+
}
132+
133+
function isObject(d) {
134+
return typeof d == 'object'
135+
}
136+
137+
function isLiteral(d) {
138+
return typeof d == 'object'
139+
&& !(d instanceof Array)
140+
}
141+
142+
function isTruthy(d) {
143+
return !!d == true
144+
}
145+
146+
function isFalsy(d) {
147+
return !!d == false
148+
}
149+
150+
function isArray(d) {
151+
return d instanceof Array
152+
}
153+
154+
function isNull(d) {
155+
return d === null
156+
}
157+
158+
function isDef(d) {
159+
return typeof d !== 'undefined'
160+
}
161+
162+
function isIn(set) {
163+
return function(d){
164+
return !set ? false
165+
: set.indexOf ? ~set.indexOf(d)
166+
: d in set
167+
}
168+
}
169+
},{}],4:[function(require,module,exports){
170+
module.exports = function keys(o) {
171+
return Object.keys(o || {})
172+
}
173+
},{}],5:[function(require,module,exports){
174+
var is = require('utilise/is')
175+
, to = require('utilise/to')
176+
, owner = require('utilise/owner')
177+
178+
module.exports = function log(prefix){
179+
return function(d){
180+
if (!owner.console || !console.log.apply) return d;
181+
is.arr(arguments[2]) && (arguments[2] = arguments[2].length)
182+
var args = to.arr(arguments)
183+
args.unshift(prefix.grey ? prefix.grey : prefix)
184+
return console.log.apply(console, args), d
185+
}
186+
}
187+
},{"utilise/is":3,"utilise/owner":6,"utilise/to":7}],6:[function(require,module,exports){
188+
(function (global){
189+
module.exports = require('utilise/client') ? /* istanbul ignore next */ window : global
190+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
191+
},{"utilise/client":2}],7:[function(require,module,exports){
192+
module.exports = {
193+
arr: toArray
194+
, obj: toObject
195+
}
196+
197+
function toArray(d){
198+
return Array.prototype.slice.call(d, 0)
199+
}
200+
201+
function toObject(d) {
202+
var by = 'id'
203+
, o = {}
204+
205+
return arguments.length == 1
206+
? (by = d, reduce)
207+
: reduce.apply(this, arguments)
208+
209+
function reduce(p,v,i){
210+
if (i === 0) p = {}
211+
p[v[by]] = v
212+
return p
213+
}
214+
}
215+
},{}]},{},[1]);

shop/public/images/10-11017A.jpg

57.2 KB

shop/public/images/10-11017B.jpg

15.1 KB

shop/public/images/10-11019A.jpg

52 KB

0 commit comments

Comments
 (0)