Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

buttons

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buttons

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= Buttons

NOTE: This is a very early version of Buttons. Expect it to change rapidly.

Buttons is a Rack framework for working with JavaScript-heavy applications. It automatically creates Ajax endpoints for Ruby methods, and creates a set of JavaScript functions to access those endpoints.

== Example

Here's an example. The Ruby class below will automatically generate the JavaScript found beneath it. For now, we only generate code that relies on jQuery, but that's planned to change.

Ruby code:

class ProfileButton < Buttons::Button
  get :show
  post :login

  def login(username, password)
    # The variable's set just to show that it's being returned.      
    token = generate_login_token(username, password)
    token
  end
  
  def show(profile_id)
    Profile.find(profile_id)
  end
end

JavaScript code (found at /profile.js):

(function () {
  this.Profile = {};

  Profile.login = function (username, password, _ajaxOptions) {
    var data = { 'username': username, 'password': password };
    if (_ajaxOptions === undefined || typeof(_ajaxOptions) != "object") {
      _ajaxOptions = {};
    }
    _ajaxOptions['type'] = "POST";
    _ajaxOptions['url'] = "/profile/login";
    _ajaxOptions['data'] = data;

    if (_ajaxOptions['dataType'] === 'undefined') {
      _ajaxOptions['dataType'] = 'json';
    }

    return jQuery.ajax(_ajaxOptions);
  };

  Profile.show = function (profileId, _ajaxOptions) {
    var data = { 'profile_id': profileId };
    if (_ajaxOptions === undefined || typeof(_ajaxOptions) != "object") {
      _ajaxOptions = {};
    }
    _ajaxOptions['type'] = "GET";
    _ajaxOptions['url'] = "/profile/show";
    _ajaxOptions['data'] = data;

    if (_ajaxOptions['dataType'] === 'undefined') {
      _ajaxOptions['dataType'] = 'json';
    }

    return jQuery.ajax(_ajaxOptions);
  };
})();

== How to use this

Run buttons to create a new Buttons application in that directory. There's not any helpers or generators yet, but you can look at the generated application to figure it out for now.

FAQs

Package last updated on 13 Dec 2009

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc