├── .editorconfig ├── .ember-cli ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc.js ├── .stylelintignore ├── .stylelintrc.js ├── .template-lintrc.js ├── .watchmanconfig ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── addon └── services │ └── server-variables.js ├── app ├── .gitkeep └── services │ └── server-variables.js ├── blueprints └── ember-cli-server-variables │ └── index.js ├── ember-cli-build.js ├── index.js ├── lib └── content-for-helper.js ├── package-lock.json ├── package.json ├── testem.js └── tests ├── acceptance └── server-variables-test.js ├── dummy ├── app │ ├── app.js │ ├── components │ │ └── .gitkeep │ ├── controllers │ │ ├── .gitkeep │ │ └── index.js │ ├── helpers │ │ └── .gitkeep │ ├── index.html │ ├── models │ │ └── .gitkeep │ ├── router.js │ ├── routes │ │ └── .gitkeep │ ├── styles │ │ └── app.css │ └── templates │ │ └── application.hbs ├── config │ ├── ember-cli-update.json │ ├── ember-try.js │ ├── environment.js │ ├── optional-features.json │ └── targets.js └── public │ ├── crossdomain.xml │ └── robots.txt ├── helpers ├── head-tags.js └── index.js ├── index.html ├── test-helper.js └── unit ├── .gitkeep ├── content-for-helper-test-node.js └── services └── server-variables-test.js /.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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | 4 | # compiled output 5 | /declarations/ 6 | /dist/ 7 | 8 | # misc 9 | /coverage/ 10 | !.* 11 | .*/ 12 | 13 | # ember-try 14 | /.node_modules.ember-try/ 15 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | root: true, 5 | parser: '@babel/eslint-parser', 6 | parserOptions: { 7 | ecmaVersion: 'latest', 8 | sourceType: 'module', 9 | requireConfigFile: false, 10 | babelOptions: { 11 | plugins: [ 12 | ['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }], 13 | ], 14 | }, 15 | }, 16 | plugins: ['ember'], 17 | extends: [ 18 | 'eslint:recommended', 19 | 'plugin:ember/recommended', 20 | 'plugin:prettier/recommended', 21 | ], 22 | env: { 23 | browser: true, 24 | }, 25 | rules: {}, 26 | overrides: [ 27 | // node files 28 | { 29 | files: [ 30 | './.eslintrc.js', 31 | './.prettierrc.js', 32 | './.stylelintrc.js', 33 | './.template-lintrc.js', 34 | './ember-cli-build.js', 35 | './index.js', 36 | './testem.js', 37 | './blueprints/*/index.js', 38 | './config/**/*.js', 39 | './tests/dummy/config/**/*.js', 40 | './lib/**/*.js', 41 | ], 42 | parserOptions: { 43 | sourceType: 'script', 44 | }, 45 | env: { 46 | browser: false, 47 | node: true, 48 | }, 49 | extends: ['plugin:n/recommended'], 50 | }, 51 | { 52 | // test files 53 | files: ['tests/**/*-test.{js,ts}'], 54 | extends: ['plugin:qunit/recommended'], 55 | }, 56 | ], 57 | }; 58 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | pull_request: {} 9 | 10 | concurrency: 11 | group: ci-${{ github.head_ref || github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | test: 16 | name: "Tests" 17 | runs-on: ubuntu-latest 18 | timeout-minutes: 10 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: Install Node 23 | uses: actions/setup-node@v3 24 | with: 25 | node-version: 18 26 | cache: npm 27 | - name: Install Dependencies 28 | run: npm ci 29 | - name: Lint 30 | run: npm run lint 31 | - name: Run Tests 32 | run: npm run test:ember 33 | 34 | floating: 35 | name: "Floating Dependencies" 36 | runs-on: ubuntu-latest 37 | timeout-minutes: 10 38 | 39 | steps: 40 | - uses: actions/checkout@v3 41 | - uses: actions/setup-node@v3 42 | with: 43 | node-version: 18 44 | cache: npm 45 | - name: Install Dependencies 46 | run: npm install --no-shrinkwrap 47 | - name: Run Tests 48 | run: npm run test:ember 49 | 50 | try-scenarios: 51 | name: ${{ matrix.try-scenario }} 52 | runs-on: ubuntu-latest 53 | needs: "test" 54 | timeout-minutes: 10 55 | 56 | strategy: 57 | fail-fast: false 58 | matrix: 59 | try-scenario: 60 | - ember-lts-4.12 61 | - ember-lts-5.4 62 | - ember-release 63 | - ember-beta 64 | - ember-canary 65 | - embroider-safe 66 | - embroider-optimized 67 | 68 | steps: 69 | - uses: actions/checkout@v3 70 | - name: Install Node 71 | uses: actions/setup-node@v3 72 | with: 73 | node-version: 18 74 | cache: npm 75 | - name: Install Dependencies 76 | run: npm ci 77 | - name: Run Tests 78 | run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }} 79 | -------------------------------------------------------------------------------- /.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 | # ember-try 18 | /.node_modules.ember-try/ 19 | /npm-shrinkwrap.json.ember-try 20 | /package.json.ember-try 21 | /package-lock.json.ember-try 22 | /yarn.lock.ember-try 23 | 24 | # broccoli-debug 25 | /DEBUG/ 26 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist/ 3 | /tmp/ 4 | 5 | # misc 6 | /.editorconfig 7 | /.ember-cli 8 | /.env* 9 | /.eslintcache 10 | /.eslintignore 11 | /.eslintrc.js 12 | /.git/ 13 | /.github/ 14 | /.gitignore 15 | /.prettierignore 16 | /.prettierrc.js 17 | /.stylelintignore 18 | /.stylelintrc.js 19 | /.template-lintrc.js 20 | /.travis.yml 21 | /.watchmanconfig 22 | /CONTRIBUTING.md 23 | /ember-cli-build.js 24 | /testem.js 25 | /tests/ 26 | /tsconfig.declarations.json 27 | /tsconfig.json 28 | /yarn-error.log 29 | /yarn.lock 30 | .gitkeep 31 | 32 | # ember-try 33 | /.node_modules.ember-try/ 34 | /npm-shrinkwrap.json.ember-try 35 | /package.json.ember-try 36 | /package-lock.json.ember-try 37 | /yarn.lock.ember-try 38 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | 4 | # compiled output 5 | /dist/ 6 | 7 | # misc 8 | /coverage/ 9 | !.* 10 | .*/ 11 | 12 | # ember-try 13 | /.node_modules.ember-try/ 14 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | overrides: [ 5 | { 6 | files: '*.{js,ts}', 7 | options: { 8 | singleQuote: true, 9 | }, 10 | }, 11 | ], 12 | }; 13 | -------------------------------------------------------------------------------- /.stylelintignore: -------------------------------------------------------------------------------- 1 | # unconventional files 2 | /blueprints/*/files/ 3 | 4 | # compiled output 5 | /dist/ 6 | 7 | # addons 8 | /.node_modules.ember-try/ 9 | -------------------------------------------------------------------------------- /.stylelintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'], 5 | }; 6 | -------------------------------------------------------------------------------- /.template-lintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: 'recommended', 5 | }; 6 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["dist"] 3 | } 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [v4.0.0](https://github.com/blimmer/ember-cli-server-variables/tree/v4.0.0) 4 | 5 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/v3.0.0...v4.0.0) 6 | 7 | **Merged pull requests:** 8 | 9 | - \[breaking\] Update Ember to v5.12.0 [\#76](https://github.com/blimmer/ember-cli-server-variables/pull/76) ([jrjohnson](https://github.com/jrjohnson)) 10 | 11 | ## [v3.0.0](https://github.com/blimmer/ember-cli-server-variables/tree/v3.0.0) (2021-12-18) 12 | 13 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/v2.4.0...v3.0.0) 14 | 15 | **Merged pull requests:** 16 | 17 | - \[breaking\] Update ember cli to 3.28 [\#61](https://github.com/blimmer/ember-cli-server-variables/pull/61) ([jrjohnson](https://github.com/jrjohnson)) 18 | - Upgrade Ember [\#41](https://github.com/blimmer/ember-cli-server-variables/pull/41) ([blimmer](https://github.com/blimmer)) 19 | 20 | ## [v2.4.0](https://github.com/blimmer/ember-cli-server-variables/tree/v2.4.0) (2020-04-03) 21 | 22 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/v2.3.0...v2.4.0) 23 | 24 | **Closed issues:** 25 | 26 | - Upgrade ember-cli to latest version [\#39](https://github.com/blimmer/ember-cli-server-variables/issues/39) 27 | 28 | ## [v2.3.0](https://github.com/blimmer/ember-cli-server-variables/tree/v2.3.0) (2019-08-31) 29 | 30 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/v2.2.0...v2.3.0) 31 | 32 | **Implemented enhancements:** 33 | 34 | - Remove reliance on jQuery [\#23](https://github.com/blimmer/ember-cli-server-variables/issues/23) 35 | 36 | **Closed issues:** 37 | 38 | - Warning jquery with ember 3 [\#25](https://github.com/blimmer/ember-cli-server-variables/issues/25) 39 | 40 | **Merged pull requests:** 41 | 42 | - Bump lodash.defaultsdeep from 4.6.0 to 4.6.1 [\#37](https://github.com/blimmer/ember-cli-server-variables/pull/37) ([dependabot[bot]](https://github.com/apps/dependabot)) 43 | - Bump jquery from 3.3.1 to 3.4.1 [\#36](https://github.com/blimmer/ember-cli-server-variables/pull/36) ([dependabot[bot]](https://github.com/apps/dependabot)) 44 | - Bump js-yaml from 3.11.0 to 3.13.1 [\#35](https://github.com/blimmer/ember-cli-server-variables/pull/35) ([dependabot[bot]](https://github.com/apps/dependabot)) 45 | - Bump underscore.string from 3.3.4 to 3.3.5 [\#34](https://github.com/blimmer/ember-cli-server-variables/pull/34) ([dependabot[bot]](https://github.com/apps/dependabot)) 46 | - Bump morgan from 1.9.0 to 1.9.1 [\#33](https://github.com/blimmer/ember-cli-server-variables/pull/33) ([dependabot[bot]](https://github.com/apps/dependabot)) 47 | - Bump extend from 3.0.1 to 3.0.2 [\#32](https://github.com/blimmer/ember-cli-server-variables/pull/32) ([dependabot[bot]](https://github.com/apps/dependabot)) 48 | - Bump handlebars from 4.0.11 to 4.1.2 [\#31](https://github.com/blimmer/ember-cli-server-variables/pull/31) ([dependabot[bot]](https://github.com/apps/dependabot)) 49 | - Bump lodash.merge from 4.6.1 to 4.6.2 [\#30](https://github.com/blimmer/ember-cli-server-variables/pull/30) ([dependabot[bot]](https://github.com/apps/dependabot)) 50 | - Bump merge from 1.2.0 to 1.2.1 [\#29](https://github.com/blimmer/ember-cli-server-variables/pull/29) ([dependabot[bot]](https://github.com/apps/dependabot)) 51 | - Bump mixin-deep from 1.3.1 to 1.3.2 [\#28](https://github.com/blimmer/ember-cli-server-variables/pull/28) ([dependabot[bot]](https://github.com/apps/dependabot)) 52 | - Upgrade lodash required version [\#27](https://github.com/blimmer/ember-cli-server-variables/pull/27) ([blimmer](https://github.com/blimmer)) 53 | - Remove the need for jQuery [\#26](https://github.com/blimmer/ember-cli-server-variables/pull/26) ([jrjohnson](https://github.com/jrjohnson)) 54 | 55 | ## [v2.2.0](https://github.com/blimmer/ember-cli-server-variables/tree/v2.2.0) (2018-05-08) 56 | 57 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/2.1.0...v2.2.0) 58 | 59 | **Merged pull requests:** 60 | 61 | - Update \(all the\) Things [\#24](https://github.com/blimmer/ember-cli-server-variables/pull/24) ([jrjohnson](https://github.com/jrjohnson)) 62 | 63 | ## [2.1.0](https://github.com/blimmer/ember-cli-server-variables/tree/2.1.0) (2017-03-29) 64 | 65 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/2.0.2...2.1.0) 66 | 67 | **Merged pull requests:** 68 | 69 | - Update ember-cli. [\#22](https://github.com/blimmer/ember-cli-server-variables/pull/22) ([blimmer](https://github.com/blimmer)) 70 | 71 | ## [2.0.2](https://github.com/blimmer/ember-cli-server-variables/tree/2.0.2) (2016-08-30) 72 | 73 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/2.0.1...2.0.2) 74 | 75 | **Merged pull requests:** 76 | 77 | - Fixes a generator error [\#20](https://github.com/blimmer/ember-cli-server-variables/pull/20) ([xomaczar](https://github.com/xomaczar)) 78 | 79 | ## [2.0.1](https://github.com/blimmer/ember-cli-server-variables/tree/2.0.1) (2016-08-14) 80 | 81 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/2.0.0...2.0.1) 82 | 83 | **Merged pull requests:** 84 | 85 | - Add test for content-for helper. [\#18](https://github.com/blimmer/ember-cli-server-variables/pull/18) ([blimmer](https://github.com/blimmer)) 86 | - Upgrade Ember & Ember CLI. [\#17](https://github.com/blimmer/ember-cli-server-variables/pull/17) ([blimmer](https://github.com/blimmer)) 87 | 88 | ## [2.0.0](https://github.com/blimmer/ember-cli-server-variables/tree/2.0.0) (2016-05-28) 89 | 90 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/v1.0.0...2.0.0) 91 | 92 | **Implemented enhancements:** 93 | 94 | - Support parsing JSON from server tags. [\#16](https://github.com/blimmer/ember-cli-server-variables/pull/16) ([blimmer](https://github.com/blimmer)) 95 | 96 | **Closed issues:** 97 | 98 | - Support JSON as config value [\#15](https://github.com/blimmer/ember-cli-server-variables/issues/15) 99 | 100 | ## [v1.0.0](https://github.com/blimmer/ember-cli-server-variables/tree/v1.0.0) (2016-04-03) 101 | 102 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/v0.0.4...v1.0.0) 103 | 104 | **Closed issues:** 105 | 106 | - Introduce a generator [\#11](https://github.com/blimmer/ember-cli-server-variables/issues/11) 107 | - Upgrade lodash dependency to 4.x [\#10](https://github.com/blimmer/ember-cli-server-variables/issues/10) 108 | 109 | **Merged pull requests:** 110 | 111 | - Inject the content-for helper on install. [\#13](https://github.com/blimmer/ember-cli-server-variables/pull/13) ([blimmer](https://github.com/blimmer)) 112 | - Ember CLI Updates [\#12](https://github.com/blimmer/ember-cli-server-variables/pull/12) ([blimmer](https://github.com/blimmer)) 113 | 114 | ## [v0.0.4](https://github.com/blimmer/ember-cli-server-variables/tree/v0.0.4) (2015-08-02) 115 | 116 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/v0.0.3...v0.0.4) 117 | 118 | **Closed issues:** 119 | 120 | - Test lib/content-for-helper.js [\#4](https://github.com/blimmer/ember-cli-server-variables/issues/4) 121 | 122 | **Merged pull requests:** 123 | 124 | - Clean up formatting and text on Config Vars [\#9](https://github.com/blimmer/ember-cli-server-variables/pull/9) ([swr](https://github.com/swr)) 125 | 126 | ## [v0.0.3](https://github.com/blimmer/ember-cli-server-variables/tree/v0.0.3) (2015-06-07) 127 | 128 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/v0.0.2...v0.0.3) 129 | 130 | **Merged pull requests:** 131 | 132 | - Update ember-cli to 0.2.7. [\#8](https://github.com/blimmer/ember-cli-server-variables/pull/8) ([blimmer](https://github.com/blimmer)) 133 | 134 | ## [v0.0.2](https://github.com/blimmer/ember-cli-server-variables/tree/v0.0.2) (2015-05-24) 135 | 136 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/v0.0.1...v0.0.2) 137 | 138 | ## [v0.0.1](https://github.com/blimmer/ember-cli-server-variables/tree/v0.0.1) (2015-05-24) 139 | 140 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/0.0.1...v0.0.1) 141 | 142 | **Closed issues:** 143 | 144 | - Default modulePrefix tagPrefix returns undefined [\#7](https://github.com/blimmer/ember-cli-server-variables/issues/7) 145 | - Ember Meta SEO Solution? [\#5](https://github.com/blimmer/ember-cli-server-variables/issues/5) 146 | - Initial Add-On Work [\#1](https://github.com/blimmer/ember-cli-server-variables/issues/1) 147 | 148 | **Merged pull requests:** 149 | 150 | - Update README.md [\#6](https://github.com/blimmer/ember-cli-server-variables/pull/6) ([zeppelin](https://github.com/zeppelin)) 151 | 152 | ## [0.0.1](https://github.com/blimmer/ember-cli-server-variables/tree/0.0.1) (2015-03-29) 153 | 154 | [Full Changelog](https://github.com/blimmer/ember-cli-server-variables/compare/8a59bd6b333bb3354cce14cfe1a91c975da8ede2...0.0.1) 155 | 156 | \* _This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)_ 157 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How To Contribute 2 | 3 | ## Installation 4 | 5 | - `git clone ` 6 | - `cd ember-cli-server-variables` 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 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ember-cli-server-variables [![Build Status](https://travis-ci.org/blimmer/ember-cli-server-variables.svg?branch=master)](https://travis-ci.org/blimmer/ember-cli-server-variables) [![Ember Observer Score](http://emberobserver.com/badges/ember-cli-server-variables.svg)](http://emberobserver.com/addons/ember-cli-server-variables) [![Code Climate](https://codeclimate.com/github/blimmer/ember-cli-server-variables/badges/gpa.svg)](https://codeclimate.com/github/blimmer/ember-cli-server-variables) 2 | 3 | An [Ember CLI](http://www.ember-cli.com/) add-on to support adding variables 4 | to the generated index.html file's `head` tag. 5 | 6 | ```html 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | ``` 15 | 16 | This is handy when you need to dynamically insert variables from your application 17 | server, such as a session application token to communicate with your API or a user's 18 | location based on their request IP address. 19 | 20 | You can modify the blank `content` tags on your generated index.html file using 21 | a library like [Cheerio](https://github.com/cheeriojs/cheerio). 22 | 23 | ## Compatibility 24 | - Ember.js v4.12 or above 25 | - Ember CLI v4.12 or above 26 | - Node.js v18 or above 27 | 28 | ## Usage 29 | You need to install and configure this add-on for it to work properly. 30 | 31 | ### Installation 32 | 33 | ``` 34 | ember install ember-cli-server-variables 35 | ``` 36 | 37 | ### Configuration 38 | Add a `serverVariables` block your `environment.js` file. 39 | 40 | Configuration Variables: 41 | 42 | * vars (**required**): An array of your server variables. Convention is to use dasherized names. 43 | * tagPrefix: a prefix to append to every meta tag to avoid collision. Defaults to `ENV.modulePrefix`. 44 | * defaults: a POJO of default values for your server variables. **Note:** If 45 | you don't provide defaults, the fallback is a blank string. Most of the time 46 | you'll probably want to only provide defaults in development mode. 47 | 48 | ```javascript 49 | module.exports = function(environment) { 50 | var ENV = { 51 | serverVariables: { 52 | tagPrefix: 'your-app', 53 | vars: ['app-token', 'user-location', 'key'] 54 | } 55 | }; 56 | 57 | ... 58 | 59 | if (environment === 'development') { 60 | ENV.serverVariables.defaults = { 61 | 'app-token': 'dev-app-token', 62 | 'user-location': 'Denver' 63 | }; 64 | } 65 | }; 66 | ``` 67 | 68 | ### Usage 69 | This plugin provides a service to retrieve the server variables in your 70 | Ember app. You can use it like this: 71 | 72 | ```javascript 73 | export default Ember.Component.extend({ 74 | serverVariablesService: Ember.inject.service('serverVariables'), 75 | 76 | userLocation: Ember.computed.reads('serverVariablesService.userLocation') 77 | }); 78 | ``` 79 | 80 | ## Troubleshooting 81 | Some tips & tricks if something isn't working correctly. 82 | 83 | ### Check that the `{{content-for 'server-variables'}}` tag is present in your `app/index.html` file 84 | 85 | This is how we insert the meta tags into your app. We try to do this automatically 86 | when you `ember install` this addon, but there are potentially times where this 87 | operation could fail. Your `app/index.html` file should look something like this: 88 | 89 | ```html 90 | 91 | 92 | 93 | 94 | 95 | Dummy 96 | 97 | 98 | 99 | {{content-for 'head'}} 100 | 101 | 102 | 103 | 104 | 105 | {{content-for 'server-variables'}} 106 | 107 | 108 | {{content-for 'head-footer'}} 109 | 110 | 111 | {{content-for 'body'}} 112 | 113 | 114 | 115 | 116 | {{content-for 'body-footer'}} 117 | 118 | 119 | ``` 120 | 121 | ### Ensure you've defined a `vars` array in your `config/environment.js` file 122 | Make sure that you followed the [configuration instructions](#configuration) 123 | to get your vars defined. 124 | 125 | ## Contributing 126 | See the [Contributing](CONTRIBUTING.md) guide for details. 127 | 128 | ## License 129 | 130 | This project is licensed under the [MIT License](LICENSE.md). 131 | -------------------------------------------------------------------------------- /addon/services/server-variables.js: -------------------------------------------------------------------------------- 1 | import { isBlank } from '@ember/utils'; 2 | import { dasherize } from '@ember/string'; 3 | import Service from '@ember/service'; 4 | 5 | export default class ServerVariablesService extends Service { 6 | unknownProperty(serverVar) { 7 | var ENV = this.env; 8 | var prefix = ENV.serverVariables.tagPrefix || ENV.modulePrefix; 9 | var dasherizedVar = dasherize(serverVar); 10 | 11 | // ensure we don't die in fastboot by checking if document exists 12 | var tag = document 13 | ? document.querySelector(`head meta[name=${prefix}-${dasherizedVar}]`) 14 | : null; 15 | var content = tag ? tag.content : null; 16 | 17 | if (!isBlank(content)) { 18 | try { 19 | return JSON.parse(content); 20 | } catch (e) { 21 | // content was not JSON 22 | return content; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blimmer/ember-cli-server-variables/e392bd9a679864b0e91964ad841a2a11c6482762/app/.gitkeep -------------------------------------------------------------------------------- /app/services/server-variables.js: -------------------------------------------------------------------------------- 1 | import { computed } from '@ember/object'; 2 | import ServerVariablesService from 'ember-cli-server-variables/services/server-variables'; 3 | import ENV from '../config/environment'; 4 | 5 | export default ServerVariablesService.extend({ 6 | env: computed(function () { 7 | return ENV; 8 | }), 9 | }); 10 | -------------------------------------------------------------------------------- /blueprints/ember-cli-server-variables/index.js: -------------------------------------------------------------------------------- 1 | /*jshint node:true*/ 2 | module.exports = { 3 | normalizeEntityName: function () {}, 4 | 5 | afterInstall: function () { 6 | return this.insertIntoFile( 7 | 'app/index.html', 8 | ' {{content-for "server-variables"}}', 9 | { 10 | before: ' ', 11 | }, 12 | ); 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const contentForHelper = require('./lib/content-for-helper'); 3 | 4 | module.exports = { 5 | name: require('./package').name, 6 | 7 | contentFor: function (type, config) { 8 | if (type === 'server-variables') { 9 | return contentForHelper.generateServerVariableString(config); 10 | } 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /lib/content-for-helper.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* eslint no-console:0 */ 3 | 4 | var _forEach = require('lodash/forEach'); 5 | var _defaults = require('lodash/defaults'); 6 | 7 | module.exports = { 8 | generateServerVariableString: function (config) { 9 | var env = config.serverVariables; 10 | 11 | if (typeof env === 'undefined') { 12 | console.warn( 13 | "You provided a {{content for 'server-variables'}} but didn't configure it for this environment.", 14 | ); 15 | return; 16 | } 17 | 18 | var vars = env.vars; 19 | 20 | if (!Array.isArray(vars)) { 21 | console.warn( 22 | 'You must pass ENV.serverVariables.vars as an array of variables', 23 | ); 24 | return; 25 | } 26 | 27 | var varsConfig = {}; 28 | _forEach(vars, function (variable) { 29 | varsConfig[variable] = ''; 30 | }); 31 | 32 | if (typeof env.defaults !== 'undefined') { 33 | varsConfig = _defaults(env.defaults, varsConfig); 34 | } 35 | 36 | var modulePrefix = env.tagPrefix || config.modulePrefix; 37 | 38 | var metaString = ''; 39 | for (var key in varsConfig) { 40 | metaString = 41 | metaString + 42 | "\n"; 49 | } 50 | 51 | return metaString; 52 | }, 53 | }; 54 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-cli-server-variables", 3 | "version": "4.0.0", 4 | "description": "Insert meta tag server variables into ember-cli built Ember applications.", 5 | "keywords": [ 6 | "ember-addon", 7 | "server-driven-variables" 8 | ], 9 | "license": "MIT", 10 | "author": "Ben Limmer (http://benlimmer.com/)", 11 | "directories": { 12 | "doc": "doc", 13 | "test": "tests" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/blimmer/ember-cli-server-variables.git" 18 | }, 19 | "homepage": "https://github.com/blimmer/ember-cli-server-variables#readme", 20 | "bugs": { 21 | "url": "https://github.com/blimmer/ember-cli-server-variables/issues" 22 | }, 23 | "scripts": { 24 | "build": "ember build --environment=production", 25 | "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", 26 | "lint:css": "stylelint \"**/*.css\"", 27 | "lint:css:fix": "concurrently \"npm:lint:css -- --fix\"", 28 | "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"", 29 | "lint:hbs": "ember-template-lint .", 30 | "lint:hbs:fix": "ember-template-lint . --fix", 31 | "lint:js": "eslint . --cache", 32 | "lint:js:fix": "eslint . --fix", 33 | "start": "ember serve", 34 | "test": "concurrently \"npm:lint\" \"npm:test:*\" --names \"lint,test:\"", 35 | "test:ember": "ember test", 36 | "test:ember-compatibility": "ember try:each" 37 | }, 38 | "dependencies": { 39 | "@babel/core": "^7.25.2", 40 | "@ember/string": "^4.0.0", 41 | "ember-auto-import": "^2.8.1", 42 | "ember-cli-babel": "^8.2.0", 43 | "ember-cli-htmlbars": "^6.3.0", 44 | "lodash": "^4.17.13" 45 | }, 46 | "devDependencies": { 47 | "@babel/eslint-parser": "^7.25.1", 48 | "@babel/plugin-proposal-decorators": "^7.24.7", 49 | "@ember/optional-features": "^2.1.0", 50 | "@ember/test-helpers": "^3.3.1", 51 | "@embroider/test-setup": "^4.0.0", 52 | "@glimmer/component": "^1.1.2", 53 | "@glimmer/tracking": "^1.1.2", 54 | "broccoli-asset-rev": "^3.0.0", 55 | "chai": "^4.3.4", 56 | "concurrently": "^8.2.2", 57 | "ember-cli": "~5.12.0", 58 | "ember-cli-clean-css": "^3.0.0", 59 | "ember-cli-dependency-checker": "^3.3.2", 60 | "ember-cli-inject-live-reload": "^2.1.0", 61 | "ember-cli-sri": "^2.1.1", 62 | "ember-cli-terser": "^4.0.2", 63 | "ember-load-initializers": "^2.1.2", 64 | "ember-page-title": "^8.2.3", 65 | "ember-qunit": "^8.1.0", 66 | "ember-resolver": "^12.0.1", 67 | "ember-source": "~5.12.0", 68 | "ember-source-channel-url": "^3.0.0", 69 | "ember-template-lint": "^6.0.0", 70 | "ember-try": "^3.0.0", 71 | "eslint": "^8.57.1", 72 | "eslint-config-prettier": "^9.1.0", 73 | "eslint-plugin-ember": "^12.2.1", 74 | "eslint-plugin-n": "^16.6.2", 75 | "eslint-plugin-prettier": "^5.2.1", 76 | "eslint-plugin-qunit": "^8.1.2", 77 | "loader.js": "^4.7.0", 78 | "mocha": "^9.1.3", 79 | "prettier": "^3.3.3", 80 | "qunit": "^2.22.0", 81 | "qunit-dom": "^3.2.1", 82 | "stylelint": "^15.11.0", 83 | "stylelint-config-standard": "^34.0.0", 84 | "stylelint-prettier": "^4.1.0", 85 | "webpack": "^5.95.0" 86 | }, 87 | "peerDependencies": { 88 | "ember-source": ">= 4.0.0" 89 | }, 90 | "engines": { 91 | "node": ">= 18" 92 | }, 93 | "ember": { 94 | "edition": "octane" 95 | }, 96 | "ember-addon": { 97 | "configPath": "tests/dummy/config" 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | test_page: 'tests/index.html?hidepassed', 5 | disable_watching: true, 6 | launch_in_ci: ['Chrome'], 7 | launch_in_dev: ['Chrome'], 8 | browser_start_timeout: 120, 9 | browser_args: { 10 | Chrome: { 11 | ci: [ 12 | // --no-sandbox is needed when running Chrome 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/acceptance/server-variables-test.js: -------------------------------------------------------------------------------- 1 | import { visit } from '@ember/test-helpers'; 2 | import { module, test } from 'qunit'; 3 | import ENV from 'dummy/config/environment'; 4 | import { 5 | setPrefix, 6 | getAllServerVars, 7 | getServerVar, 8 | } from '../helpers/head-tags'; 9 | import { setupApplicationTest } from 'dummy/tests/helpers'; 10 | 11 | module('Acceptance: ServerVariables', function (hooks) { 12 | setupApplicationTest(hooks); 13 | hooks.beforeEach(function () { 14 | setPrefix(ENV.serverVariables.tagPrefix); 15 | }); 16 | 17 | test('it appends all the variables defined in the environment file', async function (assert) { 18 | await visit('/'); 19 | 20 | var tags = getAllServerVars(); 21 | assert.strictEqual(tags.length, 4); 22 | 23 | var tokenVar = getServerVar('token'); 24 | assert.strictEqual(tokenVar, 'example'); 25 | 26 | var locationVar = getServerVar('location'); 27 | assert.strictEqual(locationVar, 'Denver'); 28 | 29 | var fooVar = getServerVar('foo'); 30 | assert.strictEqual(fooVar, 'bar'); 31 | 32 | var fooBarBazVar = getServerVar('foo-bar-baz'); 33 | assert.strictEqual(fooBarBazVar, ''); 34 | }); 35 | 36 | test('it can read properties as a computed one-way', async function (assert) { 37 | await visit('/'); 38 | 39 | var indexController = this.owner.lookup('controller:index'); 40 | assert.strictEqual(indexController.get('token'), 'example'); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /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 | 6 | export default class App extends Application { 7 | modulePrefix = config.modulePrefix; 8 | podModulePrefix = config.podModulePrefix; 9 | Resolver = Resolver; 10 | } 11 | 12 | loadInitializers(App, config.modulePrefix); 13 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blimmer/ember-cli-server-variables/e392bd9a679864b0e91964ad841a2a11c6482762/tests/dummy/app/components/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blimmer/ember-cli-server-variables/e392bd9a679864b0e91964ad841a2a11c6482762/tests/dummy/app/controllers/.gitkeep -------------------------------------------------------------------------------- /tests/dummy/app/controllers/index.js: -------------------------------------------------------------------------------- 1 | import { inject as service } from '@ember/service'; 2 | import Controller from '@ember/controller'; 3 | 4 | export default class IndexController extends Controller { 5 | @service('serverVariables') 6 | serverVariablesService; 7 | 8 | get token() { 9 | return this.serverVariablesService.get('token'); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blimmer/ember-cli-server-variables/e392bd9a679864b0e91964ad841a2a11c6482762/tests/dummy/app/helpers/.gitkeep -------------------------------------------------------------------------------- /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 "server-variables"}} 15 | 16 | {{content-for "head-footer"}} 17 | 18 | 19 | {{content-for "body"}} 20 | 21 | 22 | 23 | 24 | {{content-for "body-footer"}} 25 | 26 | 27 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blimmer/ember-cli-server-variables/e392bd9a679864b0e91964ad841a2a11c6482762/tests/dummy/app/models/.gitkeep -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blimmer/ember-cli-server-variables/e392bd9a679864b0e91964ad841a2a11c6482762/tests/dummy/app/routes/.gitkeep -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 | {{page-title "Dummy"}} 2 | 3 |

Welcome to Ember

4 | 5 | {{outlet}} 6 | -------------------------------------------------------------------------------- /tests/dummy/config/ember-cli-update.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": "1.0.0", 3 | "packages": [ 4 | { 5 | "name": "ember-cli", 6 | "version": "5.12.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 | "--npm", 15 | "--no-welcome" 16 | ] 17 | } 18 | ] 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tests/dummy/config/ember-try.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const getChannelURL = require('ember-source-channel-url'); 4 | const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup'); 5 | 6 | module.exports = async function () { 7 | return { 8 | useYarn: true, 9 | scenarios: [ 10 | { 11 | name: 'ember-lts-4.12', 12 | npm: { 13 | devDependencies: { 14 | 'ember-source': '~4.12.0', 15 | }, 16 | }, 17 | }, 18 | { 19 | name: 'ember-lts-5.4', 20 | npm: { 21 | devDependencies: { 22 | 'ember-source': '~5.4.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 | serverVariables: { 22 | tagPrefix: 'prefix', 23 | vars: ['token', 'location', 'foo', 'foo-bar-baz'], 24 | defaults: { 25 | token: 'example', 26 | location: 'Denver', 27 | foo: 'bar', 28 | }, 29 | }, 30 | }; 31 | 32 | if (environment === 'development') { 33 | // ENV.APP.LOG_RESOLVER = true; 34 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 35 | // ENV.APP.LOG_TRANSITIONS = true; 36 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 37 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 38 | } 39 | 40 | if (environment === 'test') { 41 | // Testem prefers this... 42 | ENV.locationType = 'none'; 43 | 44 | // keep test console output quieter 45 | ENV.APP.LOG_ACTIVE_GENERATION = false; 46 | ENV.APP.LOG_VIEW_LOOKUPS = false; 47 | 48 | ENV.APP.rootElement = '#ember-testing'; 49 | ENV.APP.autoboot = false; 50 | } 51 | 52 | if (environment === 'production') { 53 | // here you can enable a production-specific feature 54 | } 55 | 56 | return ENV; 57 | }; 58 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/dummy/public/crossdomain.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /tests/helpers/head-tags.js: -------------------------------------------------------------------------------- 1 | var prefix = null; 2 | function setPrefix(definedPrefix) { 3 | prefix = definedPrefix; 4 | } 5 | 6 | function addHeadTag(name, content) { 7 | var meta = document.createElement('meta'); 8 | meta.name = `${prefix}-${name}`; 9 | meta.content = content; 10 | document.querySelector('head').append(meta); 11 | } 12 | 13 | function cleanupHeadTag(name) { 14 | document.querySelector(`head meta[name=${prefix}-${name}]`).remove(); 15 | } 16 | 17 | function getAllServerVars() { 18 | return document.querySelectorAll(`head meta[name^=${prefix}]`); 19 | } 20 | 21 | function getServerVar(name) { 22 | var tag = document.querySelector(`head meta[name^=${prefix}-${name}]`); 23 | if (tag) { 24 | return tag.content; 25 | } 26 | 27 | return null; 28 | } 29 | 30 | export { 31 | setPrefix, 32 | getAllServerVars, 33 | getServerVar, 34 | cleanupHeadTag, 35 | addHeadTag, 36 | }; 37 | -------------------------------------------------------------------------------- /tests/helpers/index.js: -------------------------------------------------------------------------------- 1 | import { 2 | setupApplicationTest as upstreamSetupApplicationTest, 3 | setupRenderingTest as upstreamSetupRenderingTest, 4 | setupTest as upstreamSetupTest, 5 | } from 'ember-qunit'; 6 | 7 | // This file exists to provide wrappers around ember-qunit's 8 | // test setup functions. This way, you can easily extend the setup that is 9 | // needed per test type. 10 | 11 | function setupApplicationTest(hooks, options) { 12 | upstreamSetupApplicationTest(hooks, options); 13 | 14 | // Additional setup for application tests can be done here. 15 | // 16 | // For example, if you need an authenticated session for each 17 | // application test, you could do: 18 | // 19 | // hooks.beforeEach(async function () { 20 | // await authenticateSession(); // ember-simple-auth 21 | // }); 22 | // 23 | // This is also a good place to call test setup functions coming 24 | // from other addons: 25 | // 26 | // setupIntl(hooks, 'en-us'); // ember-intl 27 | // setupMirage(hooks); // ember-cli-mirage 28 | } 29 | 30 | function setupRenderingTest(hooks, options) { 31 | upstreamSetupRenderingTest(hooks, options); 32 | 33 | // Additional setup for rendering tests can be done here. 34 | } 35 | 36 | function setupTest(hooks, options) { 37 | upstreamSetupTest(hooks, options); 38 | 39 | // Additional setup for unit tests can be done here. 40 | } 41 | 42 | export { setupApplicationTest, setupRenderingTest, setupTest }; 43 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Dummy Tests 6 | 7 | 8 | 9 | {{content-for "head"}} 10 | {{content-for "test-head"}} 11 | 12 | 17 | {{content-for 'server-variables'}} 18 | 19 | 20 | 21 | 22 | 23 | {{content-for "head-footer"}} 24 | {{content-for "test-head-footer"}} 25 | 26 | 27 | {{content-for "body"}} 28 | {{content-for "test-body"}} 29 | 30 |
31 |
32 |
33 |
34 |
35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | {{content-for "body-footer"}} 44 | {{content-for "test-body-footer"}} 45 | 46 | 47 | -------------------------------------------------------------------------------- /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 { start } from 'ember-qunit'; 7 | 8 | setApplication(Application.create(config.APP)); 9 | 10 | setup(QUnit.assert); 11 | 12 | start(); 13 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blimmer/ember-cli-server-variables/e392bd9a679864b0e91964ad841a2a11c6482762/tests/unit/.gitkeep -------------------------------------------------------------------------------- /tests/unit/content-for-helper-test-node.js: -------------------------------------------------------------------------------- 1 | /* eslint-env node */ 2 | 3 | import require from 'require'; 4 | var expect = require('chai').expect; 5 | var contentForHelper = require('../../lib/content-for-helper'); 6 | var describe = require('mocha').describe; 7 | var it = require('mocha').it; 8 | 9 | describe('content-for-helper', function () { 10 | describe('generateServerVariableString', function () { 11 | var generateServerVariableString = 12 | contentForHelper.generateServerVariableString; 13 | 14 | it("returns undefined if you don't pass a serverVariables config", function () { 15 | expect(generateServerVariableString({ modulePrefix: 'foo' })).to.be 16 | .undefined; 17 | }); 18 | 19 | it("returns undefined if you don't pass an array of server variables", function () { 20 | expect( 21 | generateServerVariableString({ 22 | serverVariables: { 23 | vars: { foo: 'foo' }, 24 | }, 25 | }), 26 | ).to.be.undefined; 27 | }); 28 | 29 | it('generates a string of server variable configs', function () { 30 | var res = generateServerVariableString({ 31 | serverVariables: { 32 | tagPrefix: 'my-app', 33 | vars: ['foo', 'bar'], 34 | }, 35 | }); 36 | 37 | expect(res).to.equal( 38 | "\n\n", 39 | ); 40 | }); 41 | 42 | it('uses modulePrefix if tagPrefix is not provided', function () { 43 | var res = generateServerVariableString({ 44 | modulePrefix: 'my-app', 45 | serverVariables: { 46 | vars: ['foo', 'bar'], 47 | }, 48 | }); 49 | 50 | expect(res).to.equal( 51 | "\n\n", 52 | ); 53 | }); 54 | 55 | it('tagPrefix overrides modulePrefix if provided', function () { 56 | var res = generateServerVariableString({ 57 | modulePrefix: 'other-prefix', 58 | serverVariables: { 59 | tagPrefix: 'my-app', 60 | vars: ['foo', 'bar'], 61 | }, 62 | }); 63 | 64 | expect(res).to.equal( 65 | "\n\n", 66 | ); 67 | }); 68 | }); 69 | }); 70 | -------------------------------------------------------------------------------- /tests/unit/services/server-variables-test.js: -------------------------------------------------------------------------------- 1 | import { module, test } from 'qunit'; 2 | import { setupTest } from 'dummy/tests/helpers'; 3 | import { setPrefix, addHeadTag, cleanupHeadTag } from '../../helpers/head-tags'; 4 | import ENV from 'dummy/config/environment'; 5 | 6 | module('service:server-variables', function (hooks) { 7 | setupTest(hooks); 8 | 9 | // Specify the other units that are required for this test. 10 | hooks.beforeEach(function () { 11 | setPrefix(ENV.serverVariables.tagPrefix); 12 | }); 13 | 14 | test('it returns the tag content when found', function (assert) { 15 | addHeadTag('service-test-location', 'Denver'); 16 | 17 | const service = this.owner.lookup('service:server-variables'); 18 | assert.strictEqual(service.get('serviceTestLocation'), 'Denver'); 19 | 20 | cleanupHeadTag('service-test-location'); 21 | }); 22 | 23 | test('it returns undefined when the content is not found', function (assert) { 24 | const service = this.owner.lookup('service:server-variables'); 25 | assert.strictEqual(service.get('nonExistant'), undefined); 26 | }); 27 | 28 | test('it returns undefined when content is not set', function (assert) { 29 | addHeadTag('service-test-foo', ''); 30 | 31 | const service = this.owner.lookup('service:server-variables'); 32 | assert.strictEqual(service.get('serviceTestFoo'), undefined); 33 | 34 | cleanupHeadTag('service-test-foo'); 35 | }); 36 | 37 | test('it accepts dasherized or camelcased', function (assert) { 38 | addHeadTag('service-test-foo', 'something'); 39 | 40 | const service = this.owner.lookup('service:server-variables'); 41 | assert.strictEqual(service.get('serviceTestFoo'), 'something'); 42 | assert.strictEqual(service.get('service-test-foo'), 'something'); 43 | 44 | cleanupHeadTag('service-test-foo'); 45 | }); 46 | 47 | test('it parses JSON tags', function (assert) { 48 | addHeadTag('service-test-json', JSON.stringify({ foo: 'foo', bar: 'bar' })); 49 | 50 | const service = this.owner.lookup('service:server-variables'); 51 | const res = service.get('service-test-json'); 52 | assert.deepEqual(res, { foo: 'foo', bar: 'bar' }); 53 | assert.strictEqual(typeof res, 'object'); 54 | assert.notEqual(typeof res, 'string'); 55 | }); 56 | }); 57 | --------------------------------------------------------------------------------