Giter Site home page Giter Site logo

box_tag's Introduction

Rails 3!
========
In Rails 3, one can render a partial using a custom layout.  That is, you can do this:

<%= render :partial => "user", :layout => "administrator", :locals => { :user => administrator } %>

So you can skip this plugin and add the following helper and get the same functionality.  The only change
that needs to be made is to join the "top" and "bottom" partials together and put a "<%= yield %>" where they meet.

def box_tag(box = 'default', options = {}, &block)
  if box.is_a? Hash
    options = box.dup
    box = 'default'
  end
  render(:layout => "boxes/#{box}", :locals => { :options => options }) do
    capture(&block) if block_given?
  end
end

One upside to doing it this way is you can use HAML for your views.  This plugin won't work with HAML as HAML closes all if it's tags
and this plugin explicitly leaves some open.

See 'Rendering partials with layouts' at http://api.rubyonrails.org/classes/ActionView/Partials.html for more information.


BoxTag
======

Adds a 'box_tag' method which works similarly to 'content_tag', but instead of generating
an HTML tag, renders the named partials around the content passed in the block.


Example
=======

<% box_tag(:fancy) do -%>
  some fancy content here including standard ERB stuff
<% end %>

The above will render the partial 'boxes/_fancy_top.html.erb', then capture the block content,
then render the partial 'boxes/_fancy_bottom.html.erb'.

<% box_tag(:fancy, :id => 'domid') do -%>
  the partials can now access :id by referencing options[:id].
  this is true for any option passed.
<% end %>

<% box_tag(:class => 'foo') do -%>
  if you do not specify the box as the first argument it will assume you mean
  box_tag(:default, :class => 'foo').
<% end %>

Copyright (c) 2008 Philip Hallstrom <[email protected]>, released under the MIT license

box_tag's People

Contributors

phallstrom avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.