mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
parent
d201b62f73
commit
d4f8fc89a3
6
ghost/sdk/layer2/.eslintrc.js
Normal file
6
ghost/sdk/layer2/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/node',
|
||||
]
|
||||
};
|
21
ghost/sdk/layer2/LICENSE
Normal file
21
ghost/sdk/layer2/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Ghost Foundation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
68
ghost/sdk/layer2/README.md
Normal file
68
ghost/sdk/layer2/README.md
Normal file
@ -0,0 +1,68 @@
|
||||
# Members Layer 2
|
||||
|
||||
## Install
|
||||
|
||||
`npm install @tryghost/members-layer2 --save`
|
||||
|
||||
or
|
||||
|
||||
`yarn add @tryghost/members-layer2`
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### As a drop in script:
|
||||
|
||||
This will attack a `Members` object to the window, with a `getToken` method.
|
||||
|
||||
It will automatically hide and show the elements with `data-members-signin` and `data-members-signout` attributes
|
||||
|
||||
```html
|
||||
<script src="members-layer2.dropin.js"></script>
|
||||
```
|
||||
|
||||
### As a library
|
||||
|
||||
```html
|
||||
<script src="members-layer2.lib.js"></script>
|
||||
<script>
|
||||
Members.init(); // Sets up binding the elements to the login/logout state
|
||||
|
||||
Members.getToken();
|
||||
</script>
|
||||
```
|
||||
|
||||
```javascript
|
||||
const Members = require('@tryghost/members-layer2');
|
||||
|
||||
Members.init(); // Sets up binding the elements to the login/logout state
|
||||
|
||||
Members.getToken();
|
||||
```
|
||||
|
||||
|
||||
## Develop
|
||||
|
||||
This is a mono repository, managed with [lerna](https://lernajs.io/).
|
||||
|
||||
Follow the instructions for the top-level repo.
|
||||
1. `git clone` this repo & `cd` into it as usual
|
||||
2. Run `yarn` to install top-level dependencies.
|
||||
|
||||
|
||||
## Run
|
||||
|
||||
- `yarn dev`
|
||||
|
||||
|
||||
## Test
|
||||
|
||||
- `yarn lint` run just eslint
|
||||
- `yarn test` run lint and tests
|
||||
|
||||
|
||||
|
||||
|
||||
# Copyright & License
|
||||
|
||||
Copyright (c) 2018 Ghost Foundation - Released under the [MIT license](LICENSE).
|
6
ghost/sdk/layer2/drop-in.js
Normal file
6
ghost/sdk/layer2/drop-in.js
Normal file
@ -0,0 +1,6 @@
|
||||
const Members = require('./');
|
||||
const ready = require('document-ready');
|
||||
|
||||
ready(Members.init);
|
||||
|
||||
module.exports = Members;
|
45
ghost/sdk/layer2/index.js
Normal file
45
ghost/sdk/layer2/index.js
Normal file
@ -0,0 +1,45 @@
|
||||
const Members = require('@tryghost/members-layer1');
|
||||
|
||||
const members = Members.create();
|
||||
|
||||
const show = el => el.style.display = 'block';
|
||||
const hide = el => el.style.display = 'none';
|
||||
|
||||
module.exports = {
|
||||
getToken() {
|
||||
return members.getToken();
|
||||
},
|
||||
init() {
|
||||
const signin = document.querySelector('[data-members-signin]');
|
||||
const signout = document.querySelector('[data-members-signout]');
|
||||
|
||||
const render = (signedIn) => {
|
||||
const promise = signedIn !== undefined ? Promise.resolve(signedIn) : members.getToken();
|
||||
return promise.then((token) => {
|
||||
if (token) {
|
||||
show(signout);
|
||||
hide(signin);
|
||||
} else {
|
||||
show(signin);
|
||||
hide(signout);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
signin.addEventListener('click', (event) => {
|
||||
event.preventDefault();
|
||||
members.login()
|
||||
.then(render);
|
||||
});
|
||||
|
||||
signout.addEventListener('click', (event) => {
|
||||
event.preventDefault();
|
||||
members.logout()
|
||||
.then((success) => {
|
||||
render(!success);
|
||||
});
|
||||
});
|
||||
|
||||
return render();
|
||||
}
|
||||
};
|
37
ghost/sdk/layer2/package.json
Normal file
37
ghost/sdk/layer2/package.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "@tryghost/members-layer2",
|
||||
"version": "0.0.0",
|
||||
"repository": "https://github.com/TryGhost/Ghost-SDKs/tree/master/packages/members/layer2",
|
||||
"author": "Ghost Foundation",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "echo \"Implement me!\"",
|
||||
"test": "NODE_ENV=testing mocha './test/**/*.test.js'",
|
||||
"lint": "eslint . --ext .js --cache",
|
||||
"build:lib": "browserify -t varify -t es6ify -s Members index.js > build/members-layer2.lib.js",
|
||||
"build:drop-in": "browserify -t varify -t es6ify -s Members drop-in.js > build/members-layer2.dropin.js",
|
||||
"prebuild": "rm -rf build && mkdir build",
|
||||
"build": "npm run build:lib && npm run build:drop-in",
|
||||
"posttest": "yarn lint"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^16.2.3",
|
||||
"es6ify": "^1.6.0",
|
||||
"eslint": "^5.9.0",
|
||||
"mocha": "5.2.0",
|
||||
"should": "13.2.3",
|
||||
"sinon": "7.1.1",
|
||||
"varify": "^0.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tryghost/members-layer1": "file:../layer1",
|
||||
"bluebird": "^3.5.3",
|
||||
"document-ready": "^2.0.1",
|
||||
"ghost-ignition": "^2.9.6",
|
||||
"lodash": "^4.17.11"
|
||||
}
|
||||
}
|
6
ghost/sdk/layer2/test/.eslintrc.js
Normal file
6
ghost/sdk/layer2/test/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/test',
|
||||
]
|
||||
};
|
10
ghost/sdk/layer2/test/hello.test.js
Normal file
10
ghost/sdk/layer2/test/hello.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
// Switch these lines once there are useful utils
|
||||
// const testUtils = require('./utils');
|
||||
require('./utils');
|
||||
|
||||
describe('Hello world', function () {
|
||||
it('Runs a test', function () {
|
||||
// TODO: Write me!
|
||||
'hello'.should.eql('hello');
|
||||
});
|
||||
});
|
11
ghost/sdk/layer2/test/utils/assertions.js
Normal file
11
ghost/sdk/layer2/test/utils/assertions.js
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Custom Should Assertions
|
||||
*
|
||||
* Add any custom assertions to this file.
|
||||
*/
|
||||
|
||||
// Example Assertion
|
||||
// should.Assertion.add('ExampleAssertion', function () {
|
||||
// this.params = {operator: 'to be a valid Example Assertion'};
|
||||
// this.obj.should.be.an.Object;
|
||||
// });
|
11
ghost/sdk/layer2/test/utils/index.js
Normal file
11
ghost/sdk/layer2/test/utils/index.js
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Test Utilities
|
||||
*
|
||||
* Shared utils for writing tests
|
||||
*/
|
||||
|
||||
// Require overrides - these add globals for tests
|
||||
require('./overrides');
|
||||
|
||||
// Require assertions - adds custom should assertions
|
||||
require('./assertions');
|
10
ghost/sdk/layer2/test/utils/overrides.js
Normal file
10
ghost/sdk/layer2/test/utils/overrides.js
Normal file
@ -0,0 +1,10 @@
|
||||
// This file is required before any test is run
|
||||
|
||||
// Taken from the should wiki, this is how to make should global
|
||||
// Should is a global in our eslint test config
|
||||
global.should = require('should').noConflict();
|
||||
should.extend();
|
||||
|
||||
// Sinon is a simple case
|
||||
// Sinon is a global in our eslint test config
|
||||
global.sinon = require('sinon');
|
Loading…
Reference in New Issue
Block a user