Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imports Sanitize.js through NPM #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,8 @@ insert_final_newline = true
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false
indent_style = space
indent_size = 2

[*.css]
indent_style = space
indent_size = 2

[*.html]
indent_style = space
indent_size = 2

[*.{diff,md}]
trim_trailing_whitespace = false
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
},
extends: 'eslint:recommended',
env: {
browser: true
},
rules: {
}
};
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
Expand All @@ -13,5 +13,11 @@
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
npm-debug.log*
yarn-error.log
testem.log

# ember-try
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
32 changes: 0 additions & 32 deletions .jshintrc

This file was deleted.

7 changes: 6 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
.editorconfig
.ember-cli
.gitignore
.jshintrc
.eslintrc.js
.watchmanconfig
.travis.yml
bower.json
ember-cli-build.js
testem.js

# ember-try
.node_modules.ember-try/
bower.json.ember-try
package.json.ember-try
36 changes: 23 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
---
language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "4"

sudo: false
dist: trusty

addons:
chrome: stable

cache:
yarn: true
directories:
- node_modules
- $HOME/.npm

env:
- EMBER_TRY_SCENARIO=default
- EMBER_TRY_SCENARIO=ember-1.13
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
global:
# See https://git.io/vdao3 for details.
- JOBS=1
matrix:
# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- EMBER_TRY_SCENARIO=ember-lts-2.12
- EMBER_TRY_SCENARIO=ember-lts-2.16
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=ember-default

matrix:
fast_finish: true
Expand All @@ -23,14 +37,10 @@ matrix:

before_install:
- npm config set spin false
- npm install -g bower
- npm install phantomjs-prebuilt

install:
- npm install
- bower install
- npm install -g npm@4
- npm --version

script:
# Usually, it's ok to finish the test scenario without reverting
# to the addon's original dependency state, skipping "cleanup".
- ember try $EMBER_TRY_SCENARIO test --skip-cleanup
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016
Copyright (c) 2017

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:

Expand Down
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ An Ember CLI addon to sanitize user provided content using [sanitize.js](https:/
Install this addon via npm:

```
npm install --save-dev ember-sanitize
```

Then run the generator to install `sanitize.js`:

```
ember generate ember-sanitize
ember install ember-sanitize
```

### Usage
Expand Down Expand Up @@ -46,13 +40,29 @@ You can then use this configuration by passing it in as the second argument to t
{{sanitize-html someValue "strict"}}
```

If you want to include one of the [configurations that ship with `Sanitize.js`](https://github.com/gbirke/Sanitize.js/tree/master/lib/sanitize/config), you can configure the addon to import them:

```javascript
// ember-cli-build.js
...
let app = new EmberApp(defaults, {
...
'ember-sanitize': {
importConfig: [
'relaxed'
]
}
...
});
...
```

## Developing

### Installation

* `git clone` this repository
* `npm install`
* `bower install`
* `yarn install`

### Running

Expand All @@ -62,4 +72,4 @@ You can then use this configuration by passing it in as the second argument to t
### Running Tests

* `ember test`
* `ember test --server`
* `ember test --server`
14 changes: 2 additions & 12 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
import {
sanitize,
sanitizeElement
} from './utils/sanitize';

import SanitizeMixin from './mixins/sanitize';

export {
sanitize,
sanitizeElement,
SanitizeMixin
};
export { sanitize, sanitizeElement } from './utils/sanitize';
export { default as SanitizeMixin } from './mixins/sanitize';
12 changes: 7 additions & 5 deletions addon/mixins/sanitize.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import Ember from 'ember';
import { sanitize, sanitizeElement } from '../utils/sanitize';
import getOwner from 'ember-getowner-polyfill';

const { getOwner } = Ember;

function loadConfig(container, name) {
if (!name) { return; }
return container.lookup("sanitizer:"+name);
if (name) {
return container.lookup(`sanitizer:${name}`);
}
}

export default Ember.Mixin.create({
sanitizeElement: function(selector, configName) {
sanitizeElement(selector, configName) {
var element = this.$(selector)[0];
return sanitizeElement(element, loadConfig(this.container, configName));
},

sanitizeHTML: function(html, configName) {
sanitizeHTML(html, configName) {
return sanitize(html, loadConfig(getOwner(this), configName));
}
});
12 changes: 6 additions & 6 deletions app/helpers/sanitize-html.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { sanitize } from 'ember-sanitize/utils/sanitize';
import getOwner from 'ember-getowner-polyfill';
import Ember from 'ember';
import { sanitize } from 'ember-sanitize/utils/sanitize';

const { getOwner } = Ember;

export default Ember.Helper.extend({
compute(params) {
let config, configName = params[1];
compute([input, configName]) {
let config;
if (configName) {
//lookup the config
config = getOwner(this).lookup('sanitizer:' + configName);
}

let sanitized = sanitize(params[0], config);
let sanitized = sanitize(input, config);
return new Ember.String.htmlSafe(sanitized);
}
});
11 changes: 2 additions & 9 deletions app/initializers/setup-sanitizers.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import Ember from 'ember';

export default {
name: 'ember-sanitize-setup-sanitizers',

initialize: function(container) {
if (container.registerOptionsForType) {
container.registerOptionsForType('sanitizer', { instantiate: false });
} else {
// Ember < 2
container.optionsForType('sanitizer', { instantiate: false });
}
initialize(container) {
container.registerOptionsForType('sanitizer', { instantiate: false });
}
};
5 changes: 0 additions & 5 deletions blueprints/.jshintrc

This file was deleted.

10 changes: 0 additions & 10 deletions blueprints/ember-sanitize/index.js

This file was deleted.

10 changes: 0 additions & 10 deletions bower.json

This file was deleted.

Loading