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

railway-bootstrap

v0.0.4

Published

Render Twitter Bootstrap HTML forms with RailwayJS models

Downloads

7

Readme

Railway Bootstrap Plugin

Railway Bootstrap is a RailwayJS plugin that will render forms for your models utilizing Twitter Bootstrap formatting and CSS classes.

Requirements:

Railway Bootstrap requires RailwayJS v2.6+. The plugin may work with earlier version of RailwayJS, but it untested.

Additionally, RailwayJS uses EJS for rendering view templates by default. While RailwayJS is capable of working with the Jade rendering engine, Railway Bootstrap has not yet been tested with Jade.

Installation:

Install the package via npm:

> npm install railway-bootstrap

Usage:

Assume that your application has a User model with properties username, email, avatar, and description in the following example. Also assume that user is an instance of the User model (generated via new User()).

<% bootstrapFormFor(user, function (form) { %>
    <%- form.input('username') %>
    <%- form.input('email', { label: 'Email Address' }) %>
    <%- form.file('avatar') %>
    <%- form.textarea('description') %>
<% }) %>

The bootstrapFormFor helper method can accept parameters in the following formats:

  1. bootstrapFormFor(resource, callback)
  2. bootstrapFormFor(resource, options, callback)

In the second format, the options parameter represent a basic JS object. Any key/value pairs included in the object will be converted to HTML attributes on the <form> DOM object. For example:

bootstrapFormFor(user, { action: '/users/new', method: 'put' }, function (form) { ... });

This will produce the following HTML:

<form class="form-horizontal" action="/users/new" method="post">
    <input type="hidden" name="authenticity_token" value="f46d9de27e45fef8dce10a36dcdc7be7fa8612af" />
    <input type="hidden" name="_method" value="PUT" />
    <!-- any other calls made on the form object will render here -->
</form>

For either format of bootstrapFormFor that is used, the callback parameter will be provided with form object. This object provides several methods used for rendering form fields. By default, each field is wrapped according to Twitter Bootstrap's horizontal form format with an accompanying label

The following methods are provided:

  • input (name, options): Creates an <input> element, where name is the name of the resource's property to render. If no options are provided, the input type defaults to "text".
  • textarea (name, options): Creates a <textarea> element, where name is the name of the resource's property to render.
  • file (name, options): Creates an <input type="file"> element, where name is the name of the resource's property to render.
  • submit (label, options): Creates a <button type="submit"> element, where label is the text to be rendered on the button.

Created By:

Matt Huggins

License:

Railway-Bootstrap is released under the MIT license.