Git Product home page Git Product logo

gridder's Introduction

Gridder

CSS Grid System for Rails 3. Generates stylesheets on the fly, similar to the ones generated by 960.gs. The main difference is that a namespace is added so that layouts can use multiple grids.

It is probably not a good idea to generate stylesheets on the fly in most cases, but I need it for a project (an editor that lets you design grid layouts).

You can also use this gem to output grids to a file if you do not need them to be generated on the fly. That way they can be used by rails’ asset system.

Dependencies

  • Rails 3.2.beta

Sorry I am not targeting earlier versions.

Usage

  • Add gem to Gemfile

  • bundle update

  • Mount engine in routes.rb

    mount Gridder::Engine => '/gridder'
    
  • Include helper in controllers that need it

    helper Gridder::GridsHelper
    
  • Link stylesheet(s)

    <%= stylesheet_link_tag grid_stylesheet(12, 60, 20) %>
  • Use helpers to design a grid

    <% with_grid 12, 60, 20 do |g| %>
      <div class="<%= g.container %>">
        <p class="<%= g.col 4 %>">Hello</p>
        <p class="<%= g.col 4 %>">Hello</p>
        <p class="<%= g.col 4 %>">Hello</p>
        <p class="<%= g.clear %>">&nbsp</p>
        <p class="<%= g.col 3 %>">Hello</p>
        <p class="<%= g.col 3 %>">Hello</p>
        <p class="<%= g.col 3 %>">Hello</p>
        <p class="<%= g.col 3 %>">Hello</p>
        <p class="<%= g.clear %>">&nbsp</p>
        <p class="<%= g.col 3 + ' ' + g.prefix 3 %>">Hello</p>
        <p class="<%= g.col 6 %>">Hello</p>
        <p class="<%= g.clear %>">&nbsp</p>
      </div>
    <% end %>

Designing grids

I’d suggest you check out 960.gs first because it works similarly.

  • Link all the stylesheets you are going to use:

    <%= stylesheet_link_tag grid_stylesheet(12, 60, 20) %>

    The 3 arguments are: number of columns, column width, and gutter.

  • Use the width_grid helper around a grid:

    <% with_grid 12, 60, 20 do |g| %>
    ...
    <% end %>

Now you can access the grid to output the namespaced CSS classnames.

  • Create columns:

    <p class="<%= g.col 4 %>">Hello</p>
    <p class="<%= g.col 4 %>">Hello</p>
    <p class="<%= g.col 4 %>">Hello</p>
  • After a row:

    <p class="<%= g.clear %>">&nbsp</p>

Check out 960.gs to learn about prefixes, suffixes, pushes, pulls, and nested columns.

In theory you should be able to nest different grids as well.

Output a grid to a file

Alternatively you can output a grid’s CSS to a file.

rake generate gridder::grid 10 80 20

This will create grid_10_80_20.css in app/assets/stylesheets.

Configuration

You can modify the following options in an initializer:

  • Maximum number of columns (default 64)

    Gridder::Engine.config.max_cols
    
  • Maximum width of a grid (default 2048)

    Gridder::Engine.config.max_width
    

If you attempt to load the stylesheet for a grid that doesn’t meet these requirements, it will return a :not_acceptable header.

Contributing to gridder

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2011 Stephan Florquin. See LICENSE.txt for further details.

gridder's People

Contributors

stephan83 avatar

Stargazers

 avatar

Watchers

 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.