npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

html-directives

v0.1.2

Published

AngularJS 1.X. component for defining basic directives as HTML.

Downloads

22

Readme

html-directives

AngularJS 1.X. component for defining basic directives as HTML.

Installation

You can choose your preferred method of installation:

Usage

Include html-directives.min.js in your application.

<script src="node_modules/html-directives/html-directives.min.js"></script>

Add the module htmlDirectives as a dependency to your app module:

var myapp = angular.module('myapp', ['htmlDirectives']);

Add a html-directives root tag into your application

<div html-directives>
	<!-- [app logic goes here] -->
</div>

Add a template URL in your app config section

angular.module('myapp').config(['htmlDirectivesProvider', function(htmlDirectivesProvider) {
	htmlDirectivesProvider.addTemplateUrl('my-directives.html');
}]);

addTemplateUrl can be called multiple times, if you have many directive templates.

Basic usage

Add following contents to my-directives.html

<my-error error-text>
	<div class="alert alert-danger">
		<h4>This is an error</h4>
		<p>Got the following error: {{errorText}}</p>

		<button type="button">Close</button>
	</div>
</my-error>

and in your HTML file:

<my-error error-text="unknown error"/>
# or
<div my-error error-text="unknown error"/>

Which will then be translated into the HTML defined inside your HTML-directive.

Advanced usage

my-directives.html

<formy d-replace="true" d-transclude="true" l-label="@" is-visible="=">
		<div class="form-group" ng-show="isVisible">
				<label nf-ig="lLabel" class="col-sm-5 control-label">{{lLabel}}</label>

				<div class="col-sm-7" ng-class="{ 'sm-col-push-5': lLabel }">
						<div ng-transclude></div>
				</div>
		</div>
</formy>

and in your HTML file:

<form name="form" class="form-horizontal">
	<formy l-label="First Name" is-visible="allow_edit"><input type="text" ng-model="first_name" class="form-control"></formy>
	<formy l-label="Last Name"><input type="text" ng-model="last_name" class="form-control"></formy>
	<formy><input type="submit">Save form</input></formy>
</form>

And you will have a neatly formatted bootstrap horizontal form.

More samples

<my-dir scope="@" attr1 attr2="@" some-attribute="=" d-restrict="A">
	My-dir value: {{myDir}}<br>
	Attr1: {{attr1}}<br>
	Attr2: {{attr2 ? 'truthy' : 'falsy'}}<br>
	Attr3: {{someAttribute}}<br>
</my-dir>
<div my-dir="'this is mydir value'" attr1="attribute 1 value" attr2="a == 'b' || something == true" some-attribute="something"></div>

Attribute definitions

HTML directive can have freely defined attributes, which will be referenced in the inner scope. If attribute is defined without value ("<my-dir attr1>"), then attribute is referenced as value ("@"). Optionally, you can define value type (<my dir attr1="@">).

Special attributes

  • d-replace: defines directive 'replace' value
  • d-transclude: defines directive 'transclude' value
  • d-restrict: defines how directive can be applied, default is "AE" (= attribute, =eleement). So as <my-dir> or as
  • d-scope: directive scope type, e.g. if directive is defined as <my-dir scope="@">{{myDir}}</my-dir>, then it can be referenced as <div my-dir="value">

FAQ

  • Is it possible to attach link, compile, etc functions to directives?
    • Not at the moment. If you have a solution proposal, preferably with code, please make a pull request.

Ideas

  • Processing inline templates (no need to load external file). Or specifically tagged HTML elements?
<script type="text/ng-template" html-directives>
  <my-dir>
		something
	</my-dir>
</script>

<my-dir html-directive>
  something
</my-dir>

<html-directives>
	<my-dir>
		something
	</my-dir>

	<another-dir>
	</another-dir>
</html>

License

Released under the terms of MIT License:

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.