angular-component-factory

WebJar for angular-component-factory

License

License

MIT
Categories

Categories

Angular User Interface Web Frameworks
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

angular-component-factory
Last Version

Last Version

1.3.1
Release Date

Release Date

Type

Type

jar
Description

Description

angular-component-factory
WebJar for angular-component-factory
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/kennethlynne/angular-component-factory

Download angular-component-factory

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/angular-component-factory/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>angular-component-factory</artifactId>
    <version>1.3.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/angular-component-factory/
implementation 'org.webjars.bower:angular-component-factory:1.3.1'
// https://jarcasting.com/artifacts/org.webjars.bower/angular-component-factory/
implementation ("org.webjars.bower:angular-component-factory:1.3.1")
'org.webjars.bower:angular-component-factory:jar:1.3.1'
<dependency org="org.webjars.bower" name="angular-component-factory" rev="1.3.1">
  <artifact name="angular-component-factory" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='angular-component-factory', version='1.3.1')
)
libraryDependencies += "org.webjars.bower" % "angular-component-factory" % "1.3.1"
[org.webjars.bower/angular-component-factory "1.3.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.bower : angular jar [1.2.7,1.3)

Project Modules

There are no modules declared in this project.

angular-component-factory Build Status Code Climate Stories in Ready

A very opinionated AngularJS decorator and provider inspired by the web components proposal to simplify use of directives as reusable components.

See demo, and view source.

Usage

To install: bower install angular-component-factory

Then add componentFactory as a dependancy to your module or decorate module using angular.componentFactory.moduleDecorator(<your module>)

###Example:

var demo = angular.module('DemoApp', []);

angular.componentFactory.moduleDecorator(demo);

demo.component('unicornTest', function ($log) {
    $log.log('Demo component says hi!')

    return {
        link: function (scope) {
            scope.message = "I'm a unicorn component!";
        }
    }
});

views/components/unicorn-test/unicorn-test.html:

<p>{{message}}</p>
<unicorn-test-component></unicorn-test-component>

Will now expand into a directive that by convention loads a template from /views/components/unicorn-test/unicorn-test.html, replaces contents by default, and creates a new scope. The object that the constructor returns should be a directive definition object. This will then be decorated for convention over configuration.

One way you might use it:

demo.component('horsePartial');

This will try to fetch a template from /views/components/horse-partial/horse-partial.html and instantiate a directive with a isolate scope. Later on when you want to add some logic, just implement the factory function as you usually do for a directive.

Configuration

If you want to set the view path you may do something like this

demo.config(function (componentFactoryProvider) {
    componentFactoryProvider.setViewPath('some/custom/path/');
});

Views will then be loaded from some/custom/path/unicorn-test/unicorn-test.html

You can also provide setViewPath with a factory function to do more custom handling based on the components name:

componentFactoryProvider.setViewPath(function (componentSnakeCasedName, componentName) {
    return 'components/' + componentSnakeCasedName + '/some-path/views/' + componentName + '.html';
});

This function will be called on every registration to map the component name to a url. The above example will return 'components/example-name/some-path/views/exampleName.html'

The factory will be served with two parameters: the snake cased component name, and the original one, and is expected to return a string path.

The MIT License (MIT)

Copyright (c) 2014 Kenneth Lynne

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.

Analytics

Versions

Version
1.3.1