On 2/9/07, Bil Kleb <[EMAIL PROTECTED]> wrote:
Does anyone have a non-database-backed Camping app with tabs
they could share as an example?  (Or suggest an alternative
approach entirely.)

Leaving out the database is easy -- just don't inherit from Base
(a.k.a. ActiveRecord::Base) in your model classes. In fact, for your
model, it looks like you could basically have a single
(namelist-backed) model class, representing a 'tab' worth of data from
your namelist file. Presumably, you've written (or have ideas about
how to write) the namelist marshalling code, and some sort of handler
for the metadata files described in your Tadalist item.

As far as making it "tabbed", I would personally probably just make
each "tab" a separate page to render, defining a controller class that
took the tab as a URL parameter, and having it load the current 'tab'
worth of data. See the attached example app for some code that does
this (albeit using a minimal, ugly chunk of CSS).

Does that help at all?

-Lennon
require 'rubygems'
require 'camping'

Camping.goes :Tabbing

module Tabbing

module Models
    TAB_DATA = {
        :foo => {
            :one => 1,
            :two => 2
        },
        :bar => {
            :one => 2,
            :two => 1
        }
    }
end

module Controllers

class Tab < R '/(\w*)'
    def get(tab_name)
        @all_tabs = TAB_DATA
        @name = tab_name
        @tab = TAB_DATA[tab_name.to_sym]
        
        render :tab
    end
end

end

module Views
    def layout
        html do
            head do
                title 'Tabbing'
                style %q[
                a { text-decoration: none; }
                .links { border-bottom: 1px solid #369; }
                .onelink {
                    border-top: 1px solid #369; 
                    border-left: 1px solid #369; 
                    border-right: 1px solid #369;
                    margin-right: 4px;
                }
                .active {
                    background: #69c;
                }
                ]
            end
            
            body do
                self << yield
            end
        end
    end

    def tab
        h1 "Tabbing on [EMAIL PROTECTED]"
        
        p.links do 
            @all_tabs.keys.each do |k|
                span.onelink do
                    if k.to_s == @name
                        a.active(k.to_s, :href => R(Tab, k))
                    else
                        a(k.to_s, :href => R(Tab, k))
                    end
                end
            end
        end
        
        if @tab
            form :action => '#' do
                @tab.keys.each do |k|
                    label k.to_s, :for => k; br
                    input :type => :text, :value => @tab[k]; br
                end
            end
        else
            p 'No such tab. Shoot!'
        end
        
        p do
            small 'Thank you, come again!'
        end
    end
end

end
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to