Giter Site home page Giter Site logo

hjalmers / angular-exemplify Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 4.0 6.98 MB

A simple angular 2+ component for adding code examples and snippet based on actual code and markup!

Home Page: https://hjalmers.github.io/angular-exemplify/

License: Apache License 2.0

TypeScript 53.65% JavaScript 6.66% HTML 18.58% CSS 21.11%
angular prism markup example code-examples exemplify

angular-exemplify's Introduction

Angular Exemplify

Build Status Commitizen friendly semantic-release Renovate enabled

A simple angular component for adding code examples based on actual code and markup! Just add <exemplify></exemplify> together with [selector]="'html selector'" and/or [sources]="sourceList" to your code and you're done:D

View example

Dependencies

  • Prism - for highlighting
  • Bootstrap - for basic styling (optional)
  • Raw-loader - a loader for webpack that allows importing files as a String (optional)

Please note that you don't have to use bootstrap and/or raw-loader with angular exemplify although it's recommended.

Installation and usage

Install with:

npm install angular-exemplify --save

If you want to use together with bootstrap 4

Run:

npm install bootstrap --save

Usage in angular-cli project

Please note the instructions below are for projects based on angular-cli, you might need to set up things differently if you're using something else.

Include scripts and styles in build

If you want to use angular exemplify together with prism, make sure to add the prism script and the prism-exemplify.css or one of the prism theme css files to your .angular-cli.json config, bootstrap.css is optional but if you're not using bootstrap you should include exemplify.css to get the basic styling at least:

"styles": [
  "../node_modules/bootstrap/dist/css/bootstrap.css",
  "../node_modules/angular-exemplify/css/prism-exemplify.css",
  "../node_modules/angular-exemplify/css/exemplify.css", // <-- only add this line if you're not using bootstrap
  "styles.css"
],
"scripts": [
  "../node_modules/prismjs/prism.js"
],

If you're using sass, you could also import the corresponding sass files like this instead of adding the css files:

@import "~angular-exemplify/scss/prism-exemplify";
@import "~angular-exemplify/scss/exemplify"; // <-- only add this line if you're not using bootstrap
@import "~bootstrap/scss/bootstrap";

Import ExemplifyModule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ExemplifyModule } from "angular-exemplify";

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ExemplifyModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Basic usage

Add <exemplify [selector]="'.btn.btn-primary'"></exemplify> below your element like this:

<button class="btn btn-primary" (click)="doSomething()">Action</button>
<exemplify [selector]="'.btn.btn-primary'"></exemplify>

Where selector could be a any html selector.

View demo for live preview and more examples.

Options

Attribute Type Usage/description Default
show boolean should the example be shown or hidden by default false
sources array an array of objects specifying sources
escapeStrings array an array with strings that should be escaped (necessary for attribute strings that are written using camel case i.e. inputs, template variables etc.), see issue #1 for more info.
texts object override default texts by passing an object containing one or more of the following properties: sourceNotFound, markup, show, hide, copy, copySuccess, copyError

Using external sources

To keep the examples in sync with your code you should reference the source files. Here's an example based on a app published and deployed to github pages.

sources = [{
    "name":"app.module.ts",
    "src":"https://raw.githubusercontent.com/hjalmers/angular-markup-example/master/src/app/app.module.ts"
  },{
    "name":"app.component.ts",
    "src":"https://raw.githubusercontent.com/hjalmers/angular-markup-example/master/src/app/app.component.ts"
  },{
    "name":"app.component.css",
    "src":"https://raw.githubusercontent.com/hjalmers/angular-markup-example/master/src/app/app.component.css",
    "lang":"css"
  }]

If you want to use raw-loader to load project files

Install with:

npm install raw-loader --save-dev`

Then you need to add the following typings to your typings.d.ts file.

declare module '!raw-loader!*' {
    const contents: string;
    export = contents;
}

To avoid errors related to require when using raw-loader like this:

sorces = [{
    name: 'app.component.ts',
    src: require('!raw-loader!app/app.component.ts'),
    lang: 'markup'
  }]

Install types for node:

npm install @types/node --save-dev

And add node to your types in tsconfig.app.json`

{
  "compilerOptions": {
    ...
    "types": [
      "node" <-- Add this
    ]
  }
}

angular-exemplify's People

Contributors

hjalmers avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

angular-exemplify's Issues

Remove "dependency" to bootstrap

Although this component has nothing to do with bootstrap, additional styling is required unless bootstrap is added. This library should include minimum style for projects not using bootstrap.

inputs are converted to lower case

Angular inputs are by default converted to lower case strings which causes a problem when we want to show them in an example as just copying and pasting the code won't work without correcting inputs.

Example

<some-component [customInput]="'value'"></some-component>

will be displayed as:

<some-component [custominput]="'value'"></some-component>

which won't work as the input is defined as customInput and not custominput

Use inline with extra syntax

Hi @hjalmers

One question is it possible to use exemplify with some extra syntax, for example:

constructorSource: Array<any> = [ { name: 'Code', src: 'constructor (private http) { }', lang: 'javascript' } ];

In this case when I use the 'http' var name I get a console error and a 'src not found' in the highlighter

Dependency deprecation warning: travis-deploy-once (npm)

On registry https://registry.npmjs.org/, the "latest" version (v5.0.11) of dependency travis-deploy-once has the following deprecation notice:

We recommend to use Travis Build Stages instead

Marking the latest version of an npm package as deprecated results in the entire package being considered deprecated, so contact the package author you think this is a mistake.

Affected package file(s): package.json

If you don't care about this, you can close this issue and not be warned about travis-deploy-once's deprecation again. If you would like to completely disable all future deprecation warnings then add the following to your config:

"suppressNotifications": ["deprecationWarningIssues"]

Clicking on Markup does not open the source file

Hello,

We ran into an issue lately where sometimes, we click on the Markup button but nothing happens. After we click on the Show button, it opens the source file, and afterwards the Markup button works as well.
This happens sometimes, usually when the page first reloads.

We are using the latest version "angular-exemplify": "^3.1.4".
Do you know anything about this issue?

Thanks,

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency commitizen to v3.1.2
  • chore(deps): update dependency postcss-cli to v6.1.3
  • chore(deps): update dependency protractor to v5.4.4
  • chore(deps): update angular-cli monorepo (@angular-devkit/build-angular, @angular-devkit/build-ng-packagr, @angular/cli)
  • chore(deps): update dependency jasmine-core to v3.99.1
  • chore(deps): update dependency karma-coverage-istanbul-reporter to v2.1.1
  • chore(deps): update dependency ng-packagr to v5.7.1
  • chore(deps): update dependency replace to v1.2.2
  • chore(deps): update dependency rimraf to v2.7.1
  • chore(deps): update dependency tslib to v1.14.1
  • fix(deps): update dependency bootstrap to v4.6.2
  • chore(deps): update angular-cli monorepo to v17 (major) (@angular-devkit/build-angular, @angular/cli)
  • chore(deps): update commitlint monorepo to v19 (major) (@commitlint/cli, @commitlint/config-conventional)
  • chore(deps): update dependency @types/jasmine to v5
  • chore(deps): update dependency @types/node to v20
  • chore(deps): update dependency autoprefixer to v10
  • chore(deps): update dependency clean-css-cli to v5
  • chore(deps): update dependency codelyzer to v6
  • chore(deps): update dependency commitizen to v4
  • chore(deps): update dependency cz-conventional-changelog to v3
  • chore(deps): update dependency husky to v9
  • chore(deps): update dependency jasmine-core to v5
  • chore(deps): update dependency jasmine-spec-reporter to v7
  • chore(deps): update dependency karma to v6
  • chore(deps): update dependency karma-chrome-launcher to v3
  • chore(deps): update dependency karma-coverage-istanbul-reporter to v3
  • chore(deps): update dependency karma-jasmine to v5
  • chore(deps): update dependency karma-jasmine-html-reporter to v2
  • chore(deps): update dependency ng-packagr to v17
  • chore(deps): update dependency postcss-cli to v11
  • chore(deps): update dependency protractor to v7
  • chore(deps): update dependency raw-loader to v4
  • chore(deps): update dependency rimraf to v5
  • chore(deps): update dependency ts-node to v10
  • chore(deps): update dependency tslib to v2
  • chore(deps): update dependency tslint to v6
  • chore(deps): update dependency typescript to v5
  • fix(deps): update dependency bootstrap to v5
  • fix(deps): update dependency rxjs to v7
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @angular/common 7.2.12
  • @angular/compiler 7.2.12
  • @angular/core 7.2.12
  • @angular/forms 7.2.12
  • @angular/http 7.2.12
  • @angular/platform-browser 7.2.12
  • @angular/platform-browser-dynamic 7.2.12
  • @angular/router 7.2.12
  • bootstrap 4.3.1
  • core-js 2.6.5
  • rxjs 6.4.0
  • zone.js 0.8.29
  • @angular-devkit/build-angular 0.13.8
  • @angular-devkit/build-ng-packagr 0.13.8
  • @angular/cli 7.3.8
  • @angular/compiler-cli 7.2.12
  • @commitlint/cli 7.5.2
  • @commitlint/config-conventional 7.5.0
  • @types/jasmine 3.3.12
  • @types/node 8.10.45
  • autoprefixer 9.5.0
  • clean-css-cli 4.3.0
  • codelyzer 5.0.0
  • commitizen 3.1.1
  • copyfiles 2.1.0
  • cz-conventional-changelog 2.1.0
  • husky 1.3.1
  • jasmine-core 3.4.0
  • jasmine-spec-reporter 4.2.1
  • karma 4.1.0
  • karma-chrome-launcher 2.2.0
  • karma-coverage-istanbul-reporter 2.0.5
  • karma-jasmine 2.0.1
  • karma-jasmine-html-reporter 1.4.0
  • karma-mocha-reporter 2.2.5
  • ng-packagr 5.0.1
  • postcss-cli 6.1.2
  • prismjs 1.16.0
  • protractor 5.4.2
  • raw-loader 1.0.0
  • replace 1.1.0
  • rimraf 2.6.3
  • semantic-release 15.13.3
  • travis-deploy-once 5.0.11
  • ts-helpers 1.1.2
  • ts-node 8.0.3
  • tsickle 0.34.3
  • tslib 1.9.3
  • tslint 5.15.0
  • typescript 3.2.4
projects/exemplify/package.json
  • @angular/common ^6.0.0-rc.0 || ^6.0.0
  • @angular/core ^6.0.0-rc.0 || ^6.0.0
  • prismjs ^1.15.0

  • Check this box to trigger a request for Renovate to run again on this repository

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.