No description
  • JavaScript 84.6%
  • Handlebars 8.7%
  • HTML 6.6%
  • CSS 0.1%
Find a file
2020-02-04 11:11:31 +00:00
addon build: bump ember-cli from 3.9.0 to 3.10.1 2019-05-29 17:07:28 -04:00
app Move CodeMirror initialization into a service 2016-04-12 15:28:47 -04:00
config Upgrade to Ember CLI 3.8.1 2019-03-29 15:44:56 -04:00
tests Merge branch 'use-closure-actions' of git://github.com/DingoEatingFuzz/ivy-codemirror into DingoEatingFuzz-use-closure-actions 2019-03-29 18:37:52 -04:00
vendor Merge remote-tracking branch 'source/master' 2015-06-04 11:53:41 +08:00
.editorconfig Upgrade to Ember CLI 2.9.1 2016-11-09 13:37:52 -05:00
.ember-cli Convert to an ember addon. 2014-12-12 14:14:11 -05:00
.eslintignore Upgrade to Ember CLI 3.8.1 2019-03-29 15:44:56 -04:00
.eslintrc.js build: bump ember-cli from 3.9.0 to 3.10.1 2019-05-29 17:07:28 -04:00
.gitignore Upgrade to Ember CLI 3.8.1 2019-03-29 15:44:56 -04:00
.npmignore Upgrade to Ember CLI 3.8.1 2019-03-29 15:44:56 -04:00
.template-lintrc.js Upgrade to Ember CLI 3.8.1 2019-03-29 15:44:56 -04:00
.travis.yml build: bump ember-cli from 3.9.0 to 3.10.1 2019-05-29 17:07:28 -04:00
.watchmanconfig Upgrade ember-cli to 2.4.2 2016-03-24 17:50:40 -04:00
CHANGELOG.md Update CHANGELOG 2018-07-12 11:34:28 -04:00
CONTRIBUTING.md Upgrade to Ember CLI 3.8.1 2019-03-29 15:44:56 -04:00
ember-cli-build.js Merge branch 'upgrade-codemirror' of https://github.com/status200/ivy-codemirror into status200-upgrade-codemirror 2019-03-29 18:29:28 -04:00
index.js Upgrade to Ember CLI 3.8.1 2019-03-29 15:44:56 -04:00
LICENSE.md Upgrade to Ember CLI 3.8.1 2019-03-29 15:44:56 -04:00
package.json build(deps-dev): bump ember-source from 3.15.0 to 3.16.0 2020-01-21 10:34:51 +00:00
README.md Add Dependabot badge to README 2019-03-29 17:28:49 -04:00
testem.js Upgrade to Ember CLI 3.8.1 2019-03-29 15:44:56 -04:00
yarn.lock build(deps-dev): bump ember-source from 3.16.0 to 3.16.1 2020-02-04 11:02:15 +00:00

ivy-codemirror

Build Status Dependabot Status Ember Observer Score

An Ember component for the excellent CodeMirror editor.

Installation

ember install ivy-codemirror # install:addon for Ember CLI < 0.2.3

If you are using a version of Ember prior to 2.3, you will also need to install the ember-hash-helper-polyfill addon:

ember install ember-hash-helper-polyfill

Usage

This addon provides an ivy-codemirror component which wraps a CodeMirror editor. You can set its value property to the code that you want to be displayed:

{{ivy-codemirror value=myCode}}

Data Down, Actions Up

In the spirit of Data Down, Actions Up, the value will not be modified directly. Instead, when a CodeMirror change event occurs, a valueUpdated action will be sent, and will be given the new value as an argument. You might implement this action handler like so:

<!-- app/templates/index.hbs -->
{{ivy-codemirror value=myCode valueUpdated=(action "updateMyCode")}}
// app/controllers/index.js
import Ember from 'ember';

export default Ember.Controller.extend({
  actions: {
    updateMyCode(newCode) {
      this.set('myCode', newCode);
    }
  }
});

However, for this simple use case, Ember provides the built-in mut helper. You could use this helper in your template instead of writing the action handler yourself, like so:

<!-- app/templates/index.hbs -->
{{ivy-codemirror value=myCode valueUpdated=(action (mut myCode))}}

Options

ivy-codemirror also allows passing options to CodeMirror via the options property. The easiest way to do this is via Ember's built-in hash helper, like so:

{{ivy-codemirror options=(hash lineNumbers=true mode="javascript")}}

Themes

By default, only CodeMirror's default theme (found in codemirror.css) is included. Additional themes can be included by specifying them in your ember-cli-build.js file:

var app = new EmberApp({
  codemirror: {
    themes: ['solarized', 'twilight']
  }
});

The example above would include themes/solarized.css and themes/twilight.css into vendor.css.

Modes & Key Maps

In addition to themes, you can also include language modes and key maps via the modes and keyMaps options, respectively:

var app = new EmberApp({
  codemirror: {
    modes: ['javascript'],
    keyMaps: ['vim']
  }
});

The example above would include mode/javascript/javascript.js and keymap/vim.js into vendor.js.

Addons

In addition to the above, you can also include any CodeMirror addon files like so:

var app = new EmberApp({
  codemirror: {
    addonFiles: ['lint/lint.css', 'lint/lint.js']
  }
});

The above example would add lint/lint.css to vendor.css and lint/lint.js to vendor.js.

Contributing

Fork this repo, make a new branch, and send a pull request. Make sure your change is tested or it won't be merged.

To run tests:

git clone # <this repo>
yarn install
yarn test

Or, to start a test server that continually runs (for development):

ember test --server