├── app
├── .gitkeep
├── utils
│ └── variable-formatter.js
├── components
│ ├── cloudinary-image.js
│ ├── cloudinary-video.js
│ └── cloudinary-resource-list.js
└── helpers
│ └── safe-cloudinary-url.js
├── addon
├── .gitkeep
├── components
│ ├── cloudinary-resource-list.hbs
│ ├── cloudinary-video.hbs
│ ├── cloudinary-image.hbs
│ ├── cloudinary-video.js
│ ├── cloudinary-image.js
│ └── cloudinary-resource-list.js
├── helpers
│ └── safe-cloudinary-url.js
└── utils
│ └── variable-formatter.js
├── tests
├── unit
│ ├── .gitkeep
│ ├── utils
│ │ └── variable-formatter-test.js
│ └── components
│ │ └── cloudinary-resource-list-test.js
├── integration
│ ├── .gitkeep
│ └── components
│ │ ├── cloudinary-video-test.js
│ │ ├── cloudinary-image-test.js
│ │ └── cloudinary-resource-list-test.js
├── dummy
│ ├── app
│ │ ├── helpers
│ │ │ └── .gitkeep
│ │ ├── models
│ │ │ └── .gitkeep
│ │ ├── routes
│ │ │ └── .gitkeep
│ │ ├── components
│ │ │ ├── .gitkeep
│ │ │ ├── test-component.js
│ │ │ └── test-component.hbs
│ │ ├── controllers
│ │ │ └── .gitkeep
│ │ ├── styles
│ │ │ └── app.css
│ │ ├── templates
│ │ │ └── application.hbs
│ │ ├── router.js
│ │ ├── index.html
│ │ ├── deprecation-workflow.js
│ │ └── app.js
│ ├── public
│ │ ├── robots.txt
│ │ └── crossdomain.xml
│ └── config
│ │ ├── optional-features.json
│ │ ├── targets.js
│ │ ├── ember-cli-update.json
│ │ ├── ember-try.js
│ │ └── environment.js
├── .eslintrc.js
├── test-helper.js
├── index.html
└── helpers
│ └── index.js
├── .watchmanconfig
├── .template-lintrc.js
├── index.js
├── .stylelintignore
├── .stylelintrc.js
├── .prettierignore
├── .ember-cli
├── .gitignore
├── .prettierrc.js
├── .editorconfig
├── .npmignore
├── testem.js
├── ember-cli-build.js
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── .github
└── workflows
│ └── ci.yml
├── eslint.config.mjs
└── package.json
/app/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/addon/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/unit/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/integration/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/helpers/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/models/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/routes/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/components/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/controllers/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {
2 | "ignore_dirs": ["dist"]
3 | }
4 |
--------------------------------------------------------------------------------
/addon/components/cloudinary-resource-list.hbs:
--------------------------------------------------------------------------------
1 | {{yield (hash items=this.items)}}
--------------------------------------------------------------------------------
/tests/dummy/public/robots.txt:
--------------------------------------------------------------------------------
1 | # http://www.robotstxt.org
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/.template-lintrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | extends: 'recommended',
5 | };
6 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | name: require('./package').name,
5 | };
6 |
--------------------------------------------------------------------------------
/.stylelintignore:
--------------------------------------------------------------------------------
1 | # unconventional files
2 | /blueprints/*/files/
3 |
4 | # compiled output
5 | /dist/
6 |
--------------------------------------------------------------------------------
/addon/components/cloudinary-video.hbs:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.stylelintrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | extends: ['stylelint-config-standard'],
5 | };
6 |
--------------------------------------------------------------------------------
/app/utils/variable-formatter.js:
--------------------------------------------------------------------------------
1 | export { default } from 'ember-cli-cloudinary-light/utils/variable-formatter';
2 |
--------------------------------------------------------------------------------
/app/components/cloudinary-image.js:
--------------------------------------------------------------------------------
1 | export { default } from 'ember-cli-cloudinary-light/components/cloudinary-image';
2 |
--------------------------------------------------------------------------------
/app/components/cloudinary-video.js:
--------------------------------------------------------------------------------
1 | export { default } from 'ember-cli-cloudinary-light/components/cloudinary-video';
2 |
--------------------------------------------------------------------------------
/app/components/cloudinary-resource-list.js:
--------------------------------------------------------------------------------
1 | export { default } from 'ember-cli-cloudinary-light/components/cloudinary-resource-list';
2 |
--------------------------------------------------------------------------------
/tests/.eslintrc.js:
--------------------------------------------------------------------------------
1 | /*eslint no-undef: "error"*/
2 | /*eslint-env node*/
3 | module.exports = {
4 | env: {
5 | embertest: true,
6 | },
7 | };
8 |
--------------------------------------------------------------------------------
/tests/dummy/app/styles/app.css:
--------------------------------------------------------------------------------
1 | /* Ember supports plain CSS out of the box. More info: https://cli.emberjs.com/release/advanced-use/stylesheets/ */
2 |
--------------------------------------------------------------------------------
/app/helpers/safe-cloudinary-url.js:
--------------------------------------------------------------------------------
1 | export {
2 | default,
3 | safeCloudinaryUrl,
4 | } from 'ember-cli-cloudinary-light/helpers/safe-cloudinary-url';
5 |
--------------------------------------------------------------------------------
/addon/components/cloudinary-image.hbs:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/tests/dummy/app/templates/application.hbs:
--------------------------------------------------------------------------------
1 | {{! The following component displays Ember's default welcome message. }}
2 | {{page-title "Dummy"}}
3 |
4 |
Welcome to Ember
5 |
6 | {{outlet}}
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | # unconventional js
2 | /blueprints/*/files/
3 |
4 | # compiled output
5 | /dist/
6 |
7 | # misc
8 | /coverage/
9 | !.*
10 | .*/
11 | /pnpm-lock.yaml
12 | ember-cli-update.json
13 | *.html
14 |
--------------------------------------------------------------------------------
/tests/dummy/config/optional-features.json:
--------------------------------------------------------------------------------
1 | {
2 | "application-template-wrapper": false,
3 | "default-async-observers": true,
4 | "jquery-integration": false,
5 | "template-only-glimmer-components": true
6 | }
7 |
--------------------------------------------------------------------------------
/tests/dummy/config/targets.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const browsers = [
4 | 'last 1 Chrome versions',
5 | 'last 1 Firefox versions',
6 | 'last 1 Safari versions',
7 | ];
8 |
9 | module.exports = {
10 | browsers,
11 | };
12 |
--------------------------------------------------------------------------------
/.ember-cli:
--------------------------------------------------------------------------------
1 | {
2 | /**
3 | Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
4 | rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
5 | */
6 | "isTypeScriptProject": false
7 | }
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # compiled output
2 | /dist/
3 | /declarations/
4 |
5 | # dependencies
6 | /node_modules/
7 |
8 | # misc
9 | /.env*
10 | /.pnp*
11 | /.eslintcache
12 | /coverage/
13 | /npm-debug.log*
14 | /testem.log
15 | /yarn-error.log
16 |
17 | # broccoli-debug
18 | /DEBUG/
19 |
--------------------------------------------------------------------------------
/tests/dummy/app/router.js:
--------------------------------------------------------------------------------
1 | import EmberRouter from '@ember/routing/router';
2 | import config from 'dummy/config/environment';
3 |
4 | export default class Router extends EmberRouter {
5 | location = config.locationType;
6 | rootURL = config.rootURL;
7 | }
8 |
9 | Router.map(function () {});
10 |
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | plugins: ['prettier-plugin-ember-template-tag'],
5 | overrides: [
6 | {
7 | files: '*.{js,gjs,ts,gts,mjs,mts,cjs,cts}',
8 | options: {
9 | singleQuote: true,
10 | templateSingleQuote: false,
11 | },
12 | },
13 | ],
14 | };
15 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 | end_of_line = lf
9 | charset = utf-8
10 | trim_trailing_whitespace = true
11 | insert_final_newline = true
12 | indent_style = space
13 | indent_size = 2
14 |
15 | [*.hbs]
16 | insert_final_newline = false
17 |
18 | [*.{diff,md}]
19 | trim_trailing_whitespace = false
20 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | # compiled output
2 | /dist/
3 | /tmp/
4 |
5 | # misc
6 | /.editorconfig
7 | /.ember-cli
8 | /.env*
9 | /.eslintcache
10 | /.git/
11 | /.github/
12 | /.gitignore
13 | /.prettierignore
14 | /.prettierrc.js
15 | /.stylelintignore
16 | /.stylelintrc.js
17 | /.template-lintrc.js
18 | /.watchmanconfig
19 | /CONTRIBUTING.md
20 | /ember-cli-build.js
21 | /eslint.config.mjs
22 | /testem.js
23 | /tests/
24 | /tsconfig.declarations.json
25 | /tsconfig.json
26 | /yarn-error.log
27 | /yarn.lock
28 | .gitkeep
29 |
--------------------------------------------------------------------------------
/tests/test-helper.js:
--------------------------------------------------------------------------------
1 | import Application from 'dummy/app';
2 | import config from 'dummy/config/environment';
3 | import * as QUnit from 'qunit';
4 | import { setApplication } from '@ember/test-helpers';
5 | import { setup } from 'qunit-dom';
6 | import { loadTests } from 'ember-qunit/test-loader';
7 | import { start, setupEmberOnerrorValidation } from 'ember-qunit';
8 |
9 | setApplication(Application.create(config.APP));
10 |
11 | setup(QUnit.assert);
12 | setupEmberOnerrorValidation();
13 | loadTests();
14 | start();
15 |
--------------------------------------------------------------------------------
/tests/dummy/app/components/test-component.js:
--------------------------------------------------------------------------------
1 | import Component from '@glimmer/component';
2 | import { action } from '@ember/object';
3 | import { tracked } from '@glimmer/tracking';
4 |
5 | export default class TimeInputComponent extends Component {
6 | picture = 'lady.jpg';
7 | @tracked width = 160;
8 | @tracked tag = 'logo';
9 |
10 | @action
11 | changeWidth(input) {
12 | this.width = input.target.value;
13 | }
14 |
15 | @action
16 | setResourceTag(input) {
17 | this.tag = input.target.value;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/tests/dummy/config/ember-cli-update.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": "1.0.0",
3 | "packages": [
4 | {
5 | "name": "ember-cli",
6 | "version": "6.4.0",
7 | "blueprints": [
8 | {
9 | "name": "addon",
10 | "outputRepo": "https://github.com/ember-cli/ember-addon-output",
11 | "codemodsSource": "ember-addon-codemods-manifest@1",
12 | "isBaseBlueprint": true,
13 | "options": [
14 | "--ci-provider=github"
15 | ]
16 | }
17 | ]
18 | }
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/tests/dummy/public/crossdomain.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/testem.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | test_page: 'tests/index.html?hidepassed',
5 | disable_watching: true,
6 | launch_in_ci: ['chromium'],
7 | launch_in_dev: ['chromium'],
8 | browser_start_timeout: 120,
9 | browser_args: {
10 | chromium: {
11 | ci: [
12 | // --no-sandbox is needed when running chromium inside a container
13 | process.env.CI ? '--no-sandbox' : null,
14 | '--headless',
15 | '--disable-dev-shm-usage',
16 | '--disable-software-rasterizer',
17 | '--mute-audio',
18 | '--remote-debugging-port=0',
19 | '--window-size=1440,900',
20 | ].filter(Boolean),
21 | },
22 | },
23 | };
24 |
--------------------------------------------------------------------------------
/tests/dummy/app/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Dummy
6 |
7 |
8 |
9 | {{content-for "head"}}
10 |
11 |
12 |
13 |
14 | {{content-for "head-footer"}}
15 |
16 |
17 | {{content-for "body"}}
18 |
19 |
20 |
21 |
22 | {{content-for "body-footer"}}
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ember-cli-build.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
4 |
5 | module.exports = function (defaults) {
6 | const app = new EmberAddon(defaults, {
7 | // Add options here
8 | });
9 |
10 | /*
11 | This build file specifies the options for the dummy test app of this
12 | addon, located in `/tests/dummy`
13 | This build file does *not* influence how the addon or the app using it
14 | behave. You most likely want to be modifying `./index.js` or app's build file
15 | */
16 |
17 | const { maybeEmbroider } = require('@embroider/test-setup');
18 | return maybeEmbroider(app, {
19 | skipBabel: [
20 | {
21 | package: 'qunit',
22 | },
23 | ],
24 | });
25 | };
26 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How To Contribute
2 |
3 | ## Installation
4 |
5 | - `git clone `
6 | - `cd ember-cli-cloudinary-light`
7 | - `npm install`
8 |
9 | ## Linting
10 |
11 | - `npm run lint`
12 | - `npm run lint:fix`
13 |
14 | ## Running tests
15 |
16 | - `npm run test` – Runs the test suite on the current Ember version
17 | - `npm run test:ember -- --server` – Runs the test suite in "watch mode"
18 | - `npm run test:ember-compatibility` – Runs the test suite against multiple Ember versions
19 |
20 | ## Running the dummy application
21 |
22 | - `npm run start`
23 | - Visit the dummy application at [http://localhost:4200](http://localhost:4200).
24 |
25 | For more information on using ember-cli, visit [https://cli.emberjs.com/release/](https://cli.emberjs.com/release/).
26 |
--------------------------------------------------------------------------------
/tests/dummy/app/deprecation-workflow.js:
--------------------------------------------------------------------------------
1 | import setupDeprecationWorkflow from 'ember-cli-deprecation-workflow';
2 |
3 | /**
4 | * Docs: https://github.com/ember-cli/ember-cli-deprecation-workflow
5 | */
6 | setupDeprecationWorkflow({
7 | /**
8 | false by default, but if a developer / team wants to be more aggressive about being proactive with
9 | handling their deprecations, this should be set to "true"
10 | */
11 | throwOnUnhandled: false,
12 | workflow: [
13 | /* ... handlers ... */
14 | /* to generate this list, run your app for a while (or run the test suite),
15 | * and then run in the browser console:
16 | *
17 | * deprecationWorkflow.flushDeprecations()
18 | *
19 | * And copy the handlers here
20 | */
21 | /* example: */
22 | /* { handler: 'silence', matchId: 'template-action' }, */
23 | ],
24 | });
25 |
--------------------------------------------------------------------------------
/tests/integration/components/cloudinary-video-test.js:
--------------------------------------------------------------------------------
1 | import { module, test } from 'qunit';
2 | import { setupRenderingTest } from '../../helpers';
3 | import { render } from '@ember/test-helpers';
4 | import { hbs } from 'ember-cli-htmlbars';
5 | import {
6 | squelchErrorHandlerFor,
7 | unsquelchAllErrorHandlers,
8 | } from 'ember-test-friendly-error-handler';
9 |
10 | module('Integration | Component | cloudinary video', function (hooks) {
11 | setupRenderingTest(hooks);
12 |
13 | hooks.afterEach(() => {
14 | unsquelchAllErrorHandlers();
15 | });
16 |
17 | test('it renders a video', async function (assert) {
18 | squelchErrorHandlerFor('Ember.onerror');
19 | await render(hbs``);
20 | assert
21 | .dom('source')
22 | .hasAttribute('src', 'https://res.cloudinary.com/demo/video/upload/dog');
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/tests/dummy/app/app.js:
--------------------------------------------------------------------------------
1 | import Application from '@ember/application';
2 | import Resolver from 'ember-resolver';
3 | import loadInitializers from 'ember-load-initializers';
4 | import config from 'dummy/config/environment';
5 | import Ember from 'ember';
6 | import buildErrorHandler from 'ember-test-friendly-error-handler';
7 | import { importSync, isDevelopingApp, macroCondition } from '@embroider/macros';
8 |
9 | if (macroCondition(isDevelopingApp())) {
10 | importSync('./deprecation-workflow');
11 | }
12 |
13 | export default class App extends Application {
14 | modulePrefix = config.modulePrefix;
15 | podModulePrefix = config.podModulePrefix;
16 | Resolver = Resolver;
17 | }
18 |
19 | Ember.onerror = buildErrorHandler('Ember.onerror', (reason) => {
20 | throw reason;
21 | // reportErrorToService(reason);
22 |
23 | // whatever else you might want here...
24 | });
25 |
26 | loadInitializers(App, config.modulePrefix);
27 |
--------------------------------------------------------------------------------
/tests/unit/utils/variable-formatter-test.js:
--------------------------------------------------------------------------------
1 | import variableFormatter from 'dummy/utils/variable-formatter';
2 | import { module, test } from 'qunit';
3 | import {
4 | squelchErrorHandlerFor,
5 | unsquelchAllErrorHandlers,
6 | } from 'ember-test-friendly-error-handler';
7 |
8 | module('Unit | Utility | variable formatter', function (hooks) {
9 | hooks.afterEach(() => {
10 | unsquelchAllErrorHandlers();
11 | });
12 |
13 | test('it works', function (assert) {
14 | squelchErrorHandlerFor('Ember.onerror');
15 | const options = { height: 200 };
16 | let result = variableFormatter(options);
17 | assert.strictEqual(result, '/h_200');
18 | });
19 |
20 | test('it works with more variables', function (assert) {
21 | squelchErrorHandlerFor('Ember.onerror');
22 | const options = { height: 200, crop: 'fit' };
23 | let result = variableFormatter(options);
24 | assert.strictEqual(result, '/h_200,c_fit');
25 | });
26 | });
27 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2020
4 |
5 | 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:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | 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.
10 |
--------------------------------------------------------------------------------
/addon/helpers/safe-cloudinary-url.js:
--------------------------------------------------------------------------------
1 | import Ember from 'ember'; //So far Ember.Handlebars.Utils.escapeExpression is not a Module, TODO: https://www.npmjs.com/package/sanitize-html#what-if-i-want-disallowed-tags-to-be-escaped-rather-than-discarded
2 | import Helper from '@ember/component/helper';
3 | import { getOwner } from '@ember/application';
4 | import { htmlSafe } from '@ember/template';
5 | import formatter from '../utils/variable-formatter';
6 |
7 | export default class safecloudinaryurl extends Helper {
8 | compute(params, hash) {
9 | const cloudName = Ember.Handlebars.Utils.escapeExpression(
10 | getOwner(this).resolveRegistration('config:environment').cloudinary
11 | .cloudName,
12 | );
13 | const publicId = Ember.Handlebars.Utils.escapeExpression(params[0]);
14 | const parameters = Ember.Handlebars.Utils.escapeExpression(formatter(hash));
15 |
16 | if (publicId) {
17 | return htmlSafe(
18 | "background-image: url('https://res.cloudinary.com/" +
19 | cloudName +
20 | '/image/upload' +
21 | parameters +
22 | '/' +
23 | publicId +
24 | "')",
25 | );
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/dummy/app/components/test-component.hbs:
--------------------------------------------------------------------------------
1 |
7 |
8 |
21 |
22 |
33 |
34 | Video:
35 |
42 |
43 | Resource list:
44 |
45 |
51 |
52 |
53 | {{#each resourceList.items as |item|}}
54 | {{item.public_id}}
55 |
56 | {{/each}}
57 |
--------------------------------------------------------------------------------
/addon/components/cloudinary-video.js:
--------------------------------------------------------------------------------
1 | import Ember from 'ember'; //So far Ember.Handlebars.Utils.escapeExpression is not a Module
2 | import Component from '@glimmer/component';
3 | import { getOwner } from '@ember/application';
4 | import { htmlSafe } from '@ember/template';
5 | import formatter from '../utils/variable-formatter';
6 |
7 | export default class CloudinaryVideoComponent extends Component {
8 | attributeBindings = ['src', 'width', 'height'];
9 |
10 | get width() {
11 | if (!this.args.options) {
12 | return 0;
13 | }
14 | return this.args.options.width;
15 | }
16 |
17 | get height() {
18 | if (!this.args.options) {
19 | return 0;
20 | }
21 | return this.args.options.height;
22 | }
23 |
24 | get src() {
25 | const cloudName = Ember.Handlebars.Utils.escapeExpression(
26 | getOwner(this).resolveRegistration('config:environment').cloudinary
27 | .cloudName,
28 | );
29 | const params = Ember.Handlebars.Utils.escapeExpression(
30 | formatter(this.args.options),
31 | );
32 | const publicId = Ember.Handlebars.Utils.escapeExpression(
33 | this.args.publicId,
34 | );
35 |
36 | const cloudinaryVideoTag = `https://res.cloudinary.com/${cloudName}/video/upload${params}/${publicId}`;
37 | return htmlSafe(cloudinaryVideoTag);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Dummy Tests
6 |
7 |
8 |
9 | {{content-for "head"}}
10 | {{content-for "test-head"}}
11 |
12 |
13 |
14 |
15 |
16 | {{content-for "head-footer"}}
17 | {{content-for "test-head-footer"}}
18 |
19 |
20 | {{content-for "body"}}
21 | {{content-for "test-body"}}
22 |
23 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | {{content-for "body-footer"}}
37 | {{content-for "test-body-footer"}}
38 |
39 |
40 |
--------------------------------------------------------------------------------
/tests/dummy/config/ember-try.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const getChannelURL = require('ember-source-channel-url');
4 | const { embroiderSafe } = require('@embroider/test-setup');
5 |
6 | module.exports = async function () {
7 | return {
8 | packageManager: 'npm',
9 | scenarios: [
10 | {
11 | name: 'ember-lts-5.8',
12 | npm: {
13 | devDependencies: {
14 | 'ember-source': '~5.8.0',
15 | },
16 | },
17 | },
18 | {
19 | name: 'ember-lts-5.12',
20 | npm: {
21 | devDependencies: {
22 | 'ember-source': '~5.12.0',
23 | },
24 | },
25 | },
26 | {
27 | name: 'ember-release',
28 | npm: {
29 | devDependencies: {
30 | 'ember-source': await getChannelURL('release'),
31 | },
32 | },
33 | },
34 | {
35 | name: 'ember-beta',
36 | npm: {
37 | devDependencies: {
38 | 'ember-source': await getChannelURL('beta'),
39 | },
40 | },
41 | },
42 | {
43 | name: 'ember-canary',
44 | npm: {
45 | devDependencies: {
46 | 'ember-source': await getChannelURL('canary'),
47 | },
48 | },
49 | },
50 | embroiderSafe(),
51 | // embroiderOptimized(),
52 | ],
53 | };
54 | };
55 |
--------------------------------------------------------------------------------
/tests/dummy/config/environment.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = function (environment) {
4 | const ENV = {
5 | modulePrefix: 'dummy',
6 | environment,
7 | rootURL: '/',
8 | locationType: 'history',
9 | EmberENV: {
10 | EXTEND_PROTOTYPES: false,
11 | FEATURES: {
12 | // Here you can enable experimental features on an ember canary build
13 | // e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true
14 | },
15 | },
16 |
17 | APP: {
18 | // Here you can pass flags/options to your application instance
19 | // when it is created
20 | },
21 | cloudinary: {
22 | cloudName: 'demo',
23 | },
24 | };
25 |
26 | if (environment === 'development') {
27 | // ENV.APP.LOG_RESOLVER = true;
28 | // ENV.APP.LOG_ACTIVE_GENERATION = true;
29 | // ENV.APP.LOG_TRANSITIONS = true;
30 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
31 | // ENV.APP.LOG_VIEW_LOOKUPS = true;
32 | ENV.cloudinary = {
33 | cloudName: 'demo',
34 | };
35 | }
36 |
37 | if (environment === 'test') {
38 | // Testem prefers this...
39 | ENV.locationType = 'none';
40 |
41 | // keep test console output quieter
42 | ENV.APP.LOG_ACTIVE_GENERATION = false;
43 | ENV.APP.LOG_VIEW_LOOKUPS = false;
44 |
45 | ENV.APP.rootElement = '#ember-testing';
46 | ENV.APP.autoboot = false;
47 | }
48 |
49 | if (environment === 'production') {
50 | // here you can enable a production-specific feature
51 | }
52 |
53 | return ENV;
54 | };
55 |
--------------------------------------------------------------------------------
/tests/helpers/index.js:
--------------------------------------------------------------------------------
1 | import {
2 | setupApplicationTest as upstreamSetupApplicationTest,
3 | setupRenderingTest as upstreamSetupRenderingTest,
4 | setupTest as upstreamSetupTest,
5 | } from 'ember-qunit';
6 | import Ember from 'ember';
7 |
8 | // This file exists to provide wrappers around ember-qunit's
9 | // test setup functions. This way, you can easily extend the setup that is
10 | // needed per test type.
11 |
12 | function setupApplicationTest(hooks, options) {
13 | upstreamSetupApplicationTest(hooks, options);
14 |
15 | // Additional setup for application tests can be done here.
16 | //
17 | // For example, if you need an authenticated session for each
18 | // application test, you could do:
19 | //
20 | // hooks.beforeEach(async function () {
21 | // await authenticateSession(); // ember-simple-auth
22 | // });
23 | //
24 | // This is also a good place to call test setup functions coming
25 | // from other addons:
26 | //
27 | // setupIntl(hooks, 'en-us'); // ember-intl
28 | // setupMirage(hooks); // ember-cli-mirage
29 |
30 | setupTest(hooks);
31 |
32 | hooks.beforeEach(function () {
33 | Ember.onerror = function (error) {
34 | throw error;
35 | };
36 | });
37 | }
38 |
39 | function setupRenderingTest(hooks, options) {
40 | upstreamSetupRenderingTest(hooks, options);
41 |
42 | // Additional setup for rendering tests can be done here.
43 | }
44 |
45 | function setupTest(hooks, options) {
46 | upstreamSetupTest(hooks, options);
47 |
48 | // Additional setup for unit tests can be done here.
49 | }
50 |
51 | export { setupApplicationTest, setupRenderingTest, setupTest };
52 |
--------------------------------------------------------------------------------
/addon/components/cloudinary-image.js:
--------------------------------------------------------------------------------
1 | import Ember from 'ember'; //So far Ember.Handlebars.Utils.escapeExpression is not a Module
2 | import Component from '@glimmer/component';
3 | import { getOwner } from '@ember/application';
4 | import { htmlSafe } from '@ember/template';
5 | import formatter from '../utils/variable-formatter';
6 | import { tracked } from '@glimmer/tracking';
7 |
8 | export default class CloudinaryImageComponent extends Component {
9 | @tracked options;
10 |
11 | get alt() {
12 | if (!this.args.options) {
13 | return '';
14 | }
15 |
16 | return this.args.options.alt;
17 | }
18 |
19 | get width() {
20 | if (!this.args.options) {
21 | return 0;
22 | }
23 | if (
24 | this.args.options.crop === 'limit' ||
25 | this.args.options.crop === 'fit' ||
26 | this.args.options.crop === 'lfill'
27 | ) {
28 | return null;
29 | }
30 | return this.args.options.width;
31 | }
32 |
33 | get height() {
34 | if (!this.args.options) {
35 | return 0;
36 | }
37 | if (
38 | this.args.options &&
39 | (this.args.options.crop === 'limit' ||
40 | this.args.options.crop === 'fit' ||
41 | this.args.options.crop === 'lfill')
42 | ) {
43 | return null;
44 | }
45 | return this.args.options.height;
46 | }
47 |
48 | get src() {
49 | const cloudName = Ember.Handlebars.Utils.escapeExpression(
50 | getOwner(this).resolveRegistration('config:environment').cloudinary
51 | .cloudName,
52 | );
53 | const params = Ember.Handlebars.Utils.escapeExpression(
54 | formatter(this.args.options),
55 | );
56 | const publicId = Ember.Handlebars.Utils.escapeExpression(
57 | this.args.publicId,
58 | );
59 |
60 | const image = `https://res.cloudinary.com/${cloudName}/image/upload${params}/${publicId}`;
61 | return htmlSafe(image);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/addon/utils/variable-formatter.js:
--------------------------------------------------------------------------------
1 | export default function variableFormatter(options) {
2 | let variables = [];
3 |
4 | if (!options) {
5 | return '';
6 | }
7 |
8 | if (options.height) {
9 | variables.push('h_' + options.height);
10 | }
11 | if (options.dpr) {
12 | variables.push('dpr_' + options.dpr);
13 | }
14 | if (options.width) {
15 | variables.push('w_' + options.width);
16 | }
17 | if (options.crop) {
18 | variables.push('c_' + options.crop);
19 | }
20 | if (options.fetch_format) {
21 | variables.push('f_' + options.fetch_format);
22 | }
23 | if (options.quality) {
24 | variables.push('q_' + options.quality);
25 | }
26 | if (options.radius) {
27 | variables.push('r_' + options.radius);
28 | }
29 | if (options.default_image) {
30 | variables.push('d_' + options.default_image);
31 | }
32 | if (options.aspect_ratio) {
33 | variables.push('ar_' + options.aspect_ratio);
34 | }
35 | if (options.gravity) {
36 | variables.push('g_' + options.gravity);
37 | }
38 | if (options.zoom) {
39 | variables.push('z_' + options.zoom);
40 | }
41 | if (options.x) {
42 | variables.push('x_' + options.x);
43 | }
44 | if (options.y) {
45 | variables.push('y_' + options.y);
46 | }
47 | if (options.angle) {
48 | variables.push('a_' + options.angle);
49 | }
50 | if (options.effect) {
51 | variables.push('e_' + options.effect);
52 | }
53 | if (options.opacity) {
54 | variables.push('o_' + options.opacity);
55 | }
56 | if (options.border) {
57 | variables.push('bo_' + options.border);
58 | }
59 | if (options.background) {
60 | variables.push('b_' + options.background);
61 | }
62 | if (options.overlay) {
63 | variables.push('l_' + options.overlay);
64 | }
65 | if (options.underlay) {
66 | variables.push('u_' + options.underlay);
67 | }
68 |
69 | return '/' + variables.join(',');
70 | }
71 |
--------------------------------------------------------------------------------
/tests/unit/components/cloudinary-resource-list-test.js:
--------------------------------------------------------------------------------
1 | ///* eslint-disable qunit/no-commented-tests */
2 | //TODO: Unit test for glimmer components is not supported. Also the URL and response is already tested in other tests.
3 |
4 | // import { A } from '@ember/array';
5 | // import { module, test } from 'qunit';
6 | // import { setupTest } from 'ember-qunit';
7 |
8 | // const cloudName = 'demo';
9 |
10 | // module('Unit | Component | cloudinary-resource-list', function (hooks) {
11 | // setupTest(hooks);
12 |
13 | // // Specify the other units that are required for this test.
14 | // // needs: []
15 | // hooks.beforeEach(function () {
16 | // this.owner.register('config:environment', {
17 | // cloudinary: { cloudName },
18 | // });
19 | // });
20 |
21 | // test('Cloudinary URL is composed correctly', function (assert) {
22 | // let component = this.owner
23 | // .factoryFor('component:cloudinary-resource-list')
24 | // .create();
25 |
26 | // let tag = 'test';
27 | // component.set('cloudinaryTag', tag);
28 |
29 | // let url = component.buildUrl();
30 | // assert.expect(
31 | // url,
32 | // `https://res.cloudinary.com/${cloudName}/image/list/${tag}.json`,
33 | // 'Url is OK'
34 | // );
35 | // });
36 |
37 | // test('Response is sorted correctly', function (assert) {
38 | // let component = this.owner
39 | // .factoryFor('component:cloudinary-resource-list')
40 | // .create();
41 |
42 | // let response = {
43 | // resources: A([
44 | // { publid_id: 1, context: { custom: { order: 3 } } },
45 | // { publid_id: 2, context: { custom: { order: 2 } } },
46 | // { publid_id: 3, context: { custom: { order: 1 } } },
47 | // ]),
48 | // };
49 |
50 | // let orderedItems = component.handleCloudinaryResponse(response);
51 | // assert.expect(orderedItems[0].publid_id, 3, 'Resource items order is OK');
52 | // });
53 | // });
54 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ember-cli-cloudinary-light
2 |
3 | [Short description of the addon.]
4 |
5 | ## Compatibility
6 |
7 | - Ember.js v5.8 or above
8 | - Ember CLI v5.8 or above
9 | - Node.js v18 or above
10 |
11 | ## Installation
12 |
13 | `ember install ember-cli-cloudinary-light`
14 |
15 | Add your cloud name to config/environment.js ENV:
16 |
17 | ```javascript
18 | cloudinary: {
19 | cloudName: 'some_cloud_name',
20 | },
21 | ```
22 |
23 | ## Components
24 |
25 | ### cloudinary-image
26 |
27 | ## Usage
28 |
29 | This component will render an `
` built from a cloudinary url and options.
30 |
31 | ```hbs
32 |
36 | ```
37 |
38 | Width and height attributes are set on the img tag as well as passed to cloudinary, allowing you to specify the resolution via the "dpr" attribute.
39 |
40 | ```hbs
41 |
45 | ```
46 |
47 | ### cloudinary-video
48 |
49 | This will render a `` for use in a `