Coder Social home page Coder Social logo

sjdaily / ember-code-prettify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from willviles/ember-code-prettify

0.0 2.0 0.0 115 KB

Ember.js addon for using Google Code Prettify syntax highlighting.

License: MIT License

JavaScript 80.78% HTML 19.22%

ember-code-prettify's Introduction

Ember Code Prettify Download count all time npm

Ember Code Prettify exposes a service to fire Google Code Prettify syntax highlighting in Ember.js routes and components.

Installation

ember install ember-code-prettify

Configuration

With no configuration, Ember Code Prettify will use the default skin and languages. The following config imports the css & yaml languages extensions and uses the desert skin:

// config/environment.js
ENV['ember-code-prettify'] = {
  languages: ['css', 'yaml'],
  skin: 'desert'
};

Usage

Ember Code Prettify exposes a service codePrettify. It can be used to paint the syntax highlighting in routes and components.

Firstly ensure your code snippet is formatted like so:

<pre class="prettyprint lang-js">
  console.log('This will be painted');
</pre>

Then get prettify to render using:

get(this, 'codePrettify').prettify();

Routes

If code snippets are added statically to a route template, simply fire Ember Code Prettify in an afterRender hook.

import Route from '@ember/routing/route';
import { get } from '@ember/object';
import { scheduleOnce } from '@ember/runloop';
import { inject } from '@ember/service';

export default Route.extend({
  codePrettify: inject(),

  init() {
    scheduleOnce('afterRender', this, function() {
      get(this, 'codePrettify').prettify();
    });
  }
});

Components

For code snippets added to component templates, use the didRender hook. Be warned, this hook will fire on any subsequent render of the component.

import Component from '@ember/component';
import { get } from '@ember/object';
import { inject } from '@ember/service';

export default Component.extend({
  codePrettify: inject(),

  didRender() {
    get(this, 'codePrettify').prettify();
  }
});

Contributing

Installation

  • git clone <repository-url> this repository
  • cd ember-code-prettify
  • npm install

Test App

Tests

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

ember-code-prettify's People

Contributors

willviles avatar ember-tomster avatar

Watchers

James Cloos avatar Sarah Daily avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.