View helpers and stylesheet defaults for Logical Reality Design projects
Ruby
Pull request Compare This branch is 1 commit behind LRDesign:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
Gemfile.lock
LICENSE.txt
README.rdoc
Rakefile
lrd_view_tools.gemspec

README.rdoc

LRD::ViewTools

Standard view helpers and stylesheet defaults for Logical Reality Design Projects.

Installing

Add to Gemfile:

gem 'lrd_view_tools'

and run 'bundle install'.

Simple labeled inputs for forms:

form.labeled_input(field)

Produces a <label> <input> pair for a text field in a standard form helper.
The default LRD stylesheet (forms.sass) in all LRD projects will format the
label as an 8-em wide float to the left of the input (or may have been modified
on a per-project basis).

Usage example:
  form_for(@user) do |f|
    = f.labeled_input(:name)
    = f.labeled_input(:email)
    = f.labeled_input(:country) do
      = f.select(:country, [ 'option 1', 'option 2'])
    = f.unlabeled_submit
  end

Options:
  The output defaults to <input type="text" name="#{field}"> for the
  but can be overridden in a number of ways:

  #Override the input element by passing a block:
  f.labeled_input(:boolean_field) do
    f.check_box(:boolean_field))

  #Alter label text:
  f.labeled_input(:fieldname, :text => "Other Text")

  #Force a blank label:
  f.labeled_input(:fieldname, :text => '' )

  #Set to required - appends class 'required' to both the div and the input:
  f.labeled_input(:fieldname, :required => 'true' )

  #Add a comment after the input:
  f.labeled_input(:password_confirmation, :comment => "Re-enter password")

  #Change the input type to a textarea:
  f.labeled_input(:description, :input_type => :text_area)    # or :textarea, both work

  #Create a telephone input:
  f.labeled_input(:description, :input_type => :tel)    # or :telephone, both work

Pass a block to partial:

block_to_partial(partial_name, options = {}, &block)

Usage example:
  block_to_partial('shared/my_partial') do
    <p>Paragraph to be yielded inside the partial.</p>
  end

The block will be available to the partial as 'body', and any options
will be passed through as locals.   In addition, options[:id] and
options[:class] will get converted to locals 'cssid' and 'cssclass'
to avoid name collisions.

A better debug()

lrd_debug(var) will output var, wrapped in <pre></pre>, but using a
recursive pp output to handle large objects.

Usage example (in HAML):
if ENV["RAILS_ENV"] == development
#debug
  %h2 Request environment:
  = lrd_debug(request.env)

Copyright © 2010-2011 Evan Dorn, released under the MIT license