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

costa

v0.5.0

Published

Coffee classes for web application

Downloads

7

Readme

Costa

Built with CoffeeClasskit & FlowCoffee. Inspired by Rails. Is kept tiny to be fast as fire.

How can it look like

Controller

Post          = require '../models/post'
parse_params  = require '../lib/parse_params'

module.exports =
class PostsController extends require './application_controller'
  @extendsWithProto()

  @beforeFilter 'authenticate', only: ['new', 'create', 'edit', 'destroy']
  @beforeFilter 'findItem', only: ['show', 'edit', 'update', 'destroy']

  # actions
  indexAction: ->
    params = @searchParams()
    Post.search params, @handleErrors (err, {items, stats}) =>
      posts = for item in items
        if item then item.exportFor 'api' else item
      @render posts: posts, params: params

  newAction: ->
    @render post: new Post

  createAction: ->
    item = new Post @itemParams()
    item.account_id = @req.account.id
    item.save (err) =>
      if err
        if item.errors.hasAny
          @res.format
            json: -> @status(422).json item.exportFor 'api' # unprocessable_entity
            html: ->
              @flash 'error', item.errors.first()
              @redirect '/posts/new'
        else
          @next(err)
      else
        url = "/posts/#{item.id}"
        @res.format
          json: -> @status(201).set('Location', url).json item.exportFor 'api' # created
          html: ->
            @flash 'Post created'
            @redirect url

  showAction: ->
    @render post: @item.exportFor 'api'

  editAction: ->
    @render post: @item.exportFor 'api'

  updateAction: ->
    item = @item.update @itemParams(), (err) => setImmediate =>
      if err
        if item.errors.hasAny
          @res.format
            json: -> @status(422).json item.exportFor 'api' # unprocessable_entity
            html: ->
              @flash 'error', item.errors.first()
              @redirect "/posts/#{@req.params.id}/edit"
        else
          @next(err)
      else
        @res.format
          json: ->
            if @req.query._response? || @req.body._response?
              @json post: item.exportFor 'api'
            else
              @status(204).end() # no_content
          html: ->
            @flash 'notice', 'Post saved'
            @redirect "/posts/#{@req.params.id}/edit"

  destroyAction: ->
    @item.destroy @handleErrors =>
      @res.format
        json: -> @status(204).end() # no_content
        html: ->
          @flash 'Post deleted'
          @redirect '/posts'

  # filters
  findItem: (callback) ->
    Post.find @req.params.id, @handleErrors (err, item) =>
      @item = item
      callback()

  # strong params
  itemParams: ->
    result = @params Post.exportedAttrs()...
    result.image = image if image = @fileParam 'image'
    result

  searchParams: ->
    str: @req.query.str

And now just call PostsController.dispatch(action, req, res, next) the way you like with action one of index, new, create, show, edit, update, destroy.

Model

module.exports =
class Post extends require './base_record'
  @extendsWithProto()

  @include require './concerns/with_image'

  @exportAttrs 'author_id',
    'title'
    'content'
    'is_published'
    'tags'

  @validatesPresenceOf 'author_id', 'title', 'content'

  @beforeSave 'refreshTags'

  refreshTags: (callback) ->
    some_tag_parser.parse @content, (err, tags) =>
      return callback err if err
      @tags = tags
      callback()

More documentation in tests & source

License

MIT