github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

sporkmonger / instrument

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 0
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (3)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (3)
    • instrument-0.1.2
    • instrument-0.1.1
    • instrument-0.1.0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Instrument is a simple library for producing dynamically generated "controls" with various templating languages. — Read more

  cancel

http://instrument.rubyforge.org/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added inspect method. 
sporkmonger (author)
Mon Jun 01 08:17:53 -0700 2009
commit  5a3823959a0e1f1b7a58486d1001d01486853e88
tree    0f1c7e9398f100ccc833265f1007438a79630aba
parent  816dca0e8940b72c919489d0db01514a2e31461d
instrument /
name age
history
message
file .gitignore Loading commit data...
file CHANGELOG
file LICENSE
file README
file Rakefile
directory lib/
directory spec/
directory tasks/
directory website/
README
== Instrument

Homepage::  instrument.rubyforge.org[http://instrument.rubyforge.org/]
Author::    Bob Aman  (mailto:bob@sporkmonger.com)
Copyright:: Copyright © 2008 Day Automation Systems, Inc.
License::   MIT

== Description

Instrument is a simple library for producing dynamically generated "controls"
with various templating languages.

== Features

* Generate controls with Erb, Haml, Markaby, or XML Builder.  Instrument
  doesn't care what template language you prefer.
* Output XHTML, XML, or JSON.  Instrument doesn't care what your output
  format is.

== Example Usage

  select_control = SelectControl.new(:name => "base", :selections => [
    {:label => "One", :value => "1"},
    {:label => "Two", :value => "2"},
    {:label => "Three", :value => "3"},
    {:label => "Four", :value => "4"}
  ])
  xhtml_output = select_control.to_xhtml

or

  include Instrument::ControlBuilder
  
  select_control(:name => "base", :selections => [
    {:label => "One", :value => "1"},
    {:label => "Two", :value => "2"},
    {:label => "Three", :value => "3"},
    {:label => "Four", :value => "4"}
  ]).to_xhtml

select_control.rb:

  require "instrument"

  class SelectControl < Instrument::Control
    class Option
      def initialize(label, value)
        @label, @value = label, value
      end
  
      attr_accessor :label
      attr_accessor :value
    end

    def element_id
      return self.options[:id] || self.options[:name]
    end

    def element_name
      return self.options[:name]
    end

    def selections
      if !defined?(@selections) || @selections == nil
        @selections = []
        for selection in self.options[:selections]
          if selection.kind_of?(Hash)
            @selections << Option.new(selection[:label], selection[:value])
          else
            @selections << Option.new(selection, selection)
          end
        end
      end
      return @selections
    end
  end
  
select.xhtml.haml:
  
  %select{:id => element_id, :name => element_name}
    - for selection in selections
      %option{:value => selection.value}
        = selection.label

== Requirements

* Instrument has no explicit dependencies.  If you want to output Haml, you
  will need the Haml library installed.  Same goes for any of the other
  template languages.

== Install

* sudo gem install instrument
* sudo gem install haml (optional)
* sudo gem install erubis (optional)
* sudo gem install markaby (optional)
* sudo gem install builder (optional)
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server