Browse files

initial commit

  • Loading branch information...
0 parents commit 35482ac4f36ad455db6875953054232877ed69f6 Nico Hagenburger committed Nov 21, 2009
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Nico Hagenburger - www.hagenburger.net
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
149 README.md
@@ -0,0 +1,149 @@
+RedGreenGrid
+============
+
+***Early alpha version. Internet Explorer not finished yet.***
+
+A Compass plugin for all those who love typography.
+RedGreenGrid provides a cross browser baseline grid for Helvetica, Arial, Verdana and Lucida Grande.
+Other fonts can be easily added.
+
+There are two grids:
+
+- **Green**: The baseline grid for all text
+- **Red**: The grid for all other elements (design, photos, boxes, …)
+
+Why two grids?
+The answer is easy: I wouldn’t look good with only one.
+With a red and a greed grid, it’s very easy to create well-balanced layouts from the scratch.
+
+
+Example
+-------
+
+Add to your screen.sass:
+
+ // import basics
+ @import redgreengrid/redgreengrid.sass
+ // set font family
+ @import redgreengrid/typography/helvetica.sass
+ // add RedGreenGrid
+ +rgg
+ // add styles to show the baseline grid
+ +rgg-development
+
+Add to your layout/application.html.haml:
+
+ %body{ :class => browser_class }
+ = redgreengrid
+
+
+Font Sizes
+----------
+
+A RedGreenGrid based layout should have three font sizes: normal, big, huge.
+You can define which CSS selectors will get which size.
+Here’s the default.
+Be sure to place your changes on top of the @imports:
+
+ !rgg_normal = "p, li, dt, dd, td, th, h3, h4, h5, h6, address"
+ !rgg_big = "h2, legend"
+ !rgg_huge = "h1"
+
+ @import redgreengrid/redgreengrid.sass
+ @import redgreengrid/typography/helvetica.sass
+ +rgg
+
+
+
+
+Implementations Details
+=======================
+
+
+Mix-Ins
+-------
+
+Maybe you’ll ask, why font size selectors aren’t implemented as mix-in?
+That’s because it needs a lot of browser fixes which can’t be done easily with mix-ins and would generate a lot of duplicate code.
+Let’s stay DRY.
+
+
+Browser Fixes
+-------------
+
+To make happy all of you who hate * or _ hacks,
+to get standards compliant CSS files
+and to avoid separate IE files (we would need separate Safari, Firefox and Opera files)
+browser fixes are made with a browser super class:
+
+ .webkit h1
+ :fixes
+ .gecko p, .presto p
+ :fixes
+ .trident h2
+ :fixes
+
+This browser superclass should be placed in the `<body>` tag.
+RedGreenGrid provides a helper method `browser_class` for this task.
+
+The following classes will be created:
+
+* **.webkit** – Safari, Google Chrome
+* **.gecko** – Firefox, Mozilla
+* **.trident** – Windows Internet Explorer
+* **.presto** – Opera
+* **.other-browser**
+
+
+Baseline Adjustments
+--------------------
+
+Each font size must be adjusted to the baseline on each browser.
+I’ve did this by `position: relative`.
+There are two mix-ins which help you for this job:
+
+ +up(1px)
+ +down(2px)
+
+
+
+
+Extend RedGreenGrid
+===================
+
+
+Changes to Font Size and Line Height
+------------------------------------
+
+The default line height is 20px.
+If you want to change the font size or line height:
+
+1. copy the SASS file of your preferred font family
+2. change the sizes
+3. name the file `_<font-family>_<font-size>_<line-height>.sass`
+4. test it and fix it for “all” browsers
+5. make a pull request for RedGreenGrid to share it
+
+
+Add New Font Families
+---------------------
+
+Do it the same way like new font sizes/line heights.
+
+
+Bug Fixes
+---------
+
+Feel free to make a pull request.
+
+
+Suggestions, Ideas, Critics
+---------------------------
+
+I love to hear from you.
+Just drop me a mail to nico .. hagenburger .. net.
+Follow me on [Twitter](http://twitter.com/Hagenburger).
+
+
+
+Copyright (c) 2009 Nico Hagenburger <http://www.hagenburger.net>, released under the MIT license
23 Rakefile
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the redgreengrid plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the redgreengrid plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Redgreengrid'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
1 init.rb
@@ -0,0 +1 @@
+require File.dirname(__FILE__) + "/lib/redgreengrid"
14 lib/redgreengrid.rb
@@ -0,0 +1,14 @@
+# Redgreengrid
+
+require 'redgreengrid/helpers'
+
+ActionView::Base.class_eval do
+ include RedGreenGrid::Helpers
+end
+
+options = {
+ :stylesheets_directory => File.expand_path(File.join(File.dirname(__FILE__), '..', 'sass')),
+ :templates_directory => File.expand_path(File.join(File.dirname(__FILE__), '..', 'templates'))
+}
+
+Compass::Frameworks.register('redgreengrid', options)
22 lib/redgreengrid/helpers.rb
@@ -0,0 +1,22 @@
+module RedGreenGrid
+ module Helpers
+
+ def redgreengrid(count = 24)
+ div = '<div></div>'
+ "<div id=\"redgreengrid-red\">#{div * count}</div>" +
+ "<div id=\"redgreengrid-green\">#{div * count}</div>"
+ end
+
+ def browser_class
+ case request.user_agent
+ when /(webkit|khtml|presto|trident|gecko)/i
+ $~[1].downcase
+ when /msie/i
+ 'trident'
+ else
+ 'other-browser'
+ end
+ end
+
+ end
+end
50 sass/redgreengrid/_development.sass
@@ -0,0 +1,50 @@
+=rgg-development(!show_grid = true)
+ #redgreengrid-columns, #redgreengrid-red, #redgreengrid-green
+ :display none
+ @if !show_grid
+ #redgreengrid-columns, #redgreengrid-red, #redgreengrid-green
+ :display block
+
+ #redgreengrid-columns
+ :bottom 0
+ :display none
+ :padding-left = 1000px
+ :position fixed
+ :top 0
+ :z-index 999
+
+ div
+ :background #F33CE7
+ :float left
+ :height 100%
+ :margin-right = 0
+ :opacity 0.3
+ :width = 0
+
+
+ #redgreengrid-red
+ :bottom 0
+ :position absolute
+ :top 0
+ :z-index 999
+ :width 0
+
+ div
+ :border-bottom 1px #F33CE7 solid
+ :margin-top = !rgg_line_height - 1px
+ :opacity 0.1
+ :width = 1280px
+
+
+ #redgreengrid-green
+ :bottom 0
+ :position absolute
+ :top -6px
+ :z-index 999
+ :width 0
+
+ div
+ :border-bottom 1px #50C45E solid
+ :margin-top = !rgg_line_height - 1px
+ :opacity 0.2
+ :width = 1280px
3 sass/redgreengrid/_redgreengrid.sass
@@ -0,0 +1,3 @@
+@import reset.sass
+@import typography.sass
+@import development.sass
37 sass/redgreengrid/_reset.sass
@@ -0,0 +1,37 @@
+a, body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, form, fieldset, legend, p, pre, span, th, td
+ :background-repeat no-repeat
+ :margin 0
+ :padding 0
+
+table
+ :border-collapse collapse
+ :border-spacing 0
+
+fieldset, img
+ :border 0
+
+address, em, th
+ :font-style normal
+ :font-weight normal
+
+li
+ :list-style none
+
+th
+ :font-style normal
+ :text-align left
+
+h1, h2, h3, h4, h5, h6, small
+ :font-size 100%
+
+input, textarea, select
+ :font-family inherit
+ :font-size inherit
+ :font-weight inherit
+
+.msie
+ input, textarea, select
+ :font-size 100%
+
+header, section, article, aside, footer, time
+ :display block
68 sass/redgreengrid/_typography.sass
@@ -0,0 +1,68 @@
+!rgg_small ||= "small"
+!rgg_normal ||= "p, li, dt, dd, td, th, h3, h4, h5, h6, address"
+!rgg_big ||= "h2, legend"
+!rgg_huge ||= "h1"
+!rgg_bold ||= "h1, h2, h3, h4, h5, h6, strong, th"
+!rgg_inline_text ||= ""
+!rgg_inline_container ||= ""
+
+
+=up(!pixels)
+ :position relative
+ :bottom = !pixels
+
+
+=down(!pixels)
+ +up(-!pixels)
+
+
+=typography(!tag, !tag_font_size, !tag_line_height, !tag_position = false)
+ #{!tag}
+ :font-size = !tag_font_size
+ :line-height = !tag_line_height
+ :margin = 0 0 !rgg_line_height
+ @if !tag_position
+ :position relative
+ :bottom = !tag_position
+
+
+=float-left(!lines)
+ :height = !lines * !rgg_line_height
+ :float left
+ :margin = 0 !rgg_line_height !rgg_line_height 0
+
+
+=float-right(!lines)
+ :height = !lines * !rgg_line_height
+ :float right
+ :margin = 0 0 !rgg_line_height !rgg_line_height
+
+
+
+=rgg
+ .box
+ +float-left(2)
+ :width 40px
+ :background #ccc
+
+ ul.list li
+ :list-style circle
+ :margin-left = !rgg_line_height
+
+ ol.list li
+ :list-style decimal
+ :margin-left = !rgg_line_height
+
+ hr
+ :border none
+ :border-bottom 1px #ccc dotted
+ :margin = !rgg_line_height 1px !rgg_line_height - 1px 0
+ +up(1px)
+
+ .gecko hr
+ :margin-bottom = !rgg_line_height - 2px
+ +up(2px)
+
+ @if !rgg_inline_container != ""
+ #{!rgg_inline_container}
+ :bottom 0
23 sass/redgreengrid/typography/_arial_13_20.sass
@@ -0,0 +1,23 @@
+!rgg_font_size ||= 13px
+!rgg_line_height ||= 20px
+
+body
+ :font-family "Arial", "Helvetica", "sans-serif"
+
+#{!rgg_bold}
+ :font-weight bold
+
++typography(!rgg_huge, 37px, !rgg_line_height * 2, -1px)
++typography(!rgg_big, 16px, !rgg_line_height, 1px)
++typography(!rgg_normal, !rgg_font_size, !rgg_line_height, )
+
+.presto
+ #{!rgg_huge}
+ +down(2px)
+
+.gecko
+ #{!rgg_big}
+ +up(2px)
+
+ #{!rgg_normal}
+ +up(1px)
19 sass/redgreengrid/typography/_helvetica_13_20.sass
@@ -0,0 +1,19 @@
+!rgg_font_size ||= 13px
+!rgg_line_height ||= 20px
+
+body
+ :font-family "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", "Swiss 721 Light", "Helvetica", "Arial", "sans-serif"
+ :font-weight 200
+
+#{!rgg_bold}
+ :font-family "HelveticaNeue-Bold", "Helvetica Neue Bold", "Helvetica Neue", "Swiss 721 Bold", "Helvetica", "Arial", "sans-serif"
+ :font-weight bold
+
++typography(!rgg_huge, 37px, !rgg_line_height * 2 )
++typography(!rgg_big, 16px, !rgg_line_height, 2px)
++typography(!rgg_normal, !rgg_font_size, !rgg_line_height, 1px)
+
+.presto
+ #{!rgg_big}
+ +up(2px)
+
12 sass/redgreengrid/typography/_lucida_13_20.sass
@@ -0,0 +1,12 @@
+!rgg_font_size ||= 13px
+!rgg_line_height ||= 20px
+
+body
+ :font-family "Lucida Grande", "Tahoma", "Vera Sans", "Helvetica", "Arial", "sans-serif"
+
+#{!rgg_bold}
+ :font-weight bold
+
++typography(!rgg_huge, 36px, !rgg_line_height * 2 )
++typography(!rgg_big, 16px, !rgg_line_height, 2px)
++typography(!rgg_normal, !rgg_font_size, !rgg_line_height, 1px)
18 sass/redgreengrid/typography/_verdana_12_20.sass
@@ -0,0 +1,18 @@
+!rgg_font_size ||= 12px
+!rgg_line_height ||= 20px
+
+body
+ :font-family "Verdana", "Tahoma", "Vera Sans", "Helvetica", "Arial", "sans-serif"
+
+#{!rgg_bold}
+ :font-weight bold
+
++typography(!rgg_huge, 35px, !rgg_line_height * 2 )
++typography(!rgg_big, 16px, !rgg_line_height, 2px)
++typography(!rgg_normal, !rgg_font_size, !rgg_line_height )
+
+.gecko
+ #{!rgg_big}
+ +up(3px)
+ #{!rgg_normal}
+ +up(1px)
43 spec/redgreengrid/helpers_spec.rb
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe RedGreenGrid::Helpers do
+ include RedGreenGrid::Helpers
+
+ it "should render the grid" do
+ result = redgreengrid
+
+ result.should have_tag("#redgreengrid-red div", 24)
+ result.should have_tag("#redgreengrid-green div", 24)
+ end
+
+ it "should render the grid with own count" do
+ result = redgreengrid(50)
+
+ result.should have_tag("#redgreengrid-red div", 50)
+ result.should have_tag("#redgreengrid-green div", 50)
+ end
+
+ it "should generate the right browser class" do
+ [
+ ['Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6c', 'other-browser'],
+ ['Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)', 'trident'],
+ ['Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618)', 'trident'],
+ ['Mozilla/4.77 [en] (X11; I; IRIX;64 6.5 IP30)', 'other-browser'],
+ ['Mozilla/5.0 (compatible; Konqueror/3.2; Linux 2.6.2) (KHTML, like Gecko)', ''],
+ ['Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.8', 'webkit'],
+ ['Mozilla/5.0 (OS/2; U; Warp 4.5; de; rv:1.8.1.11) Gecko/20071129 PmWFx/2.0.0.11', 'gecko'],
+ ['Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13', 'webkit'],
+ ['Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10', 'gecko'],
+ ['Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.7.3) Gecko/20040924 Epiphany/1.4.4 (Ubuntu)', 'gecko'],
+ ['Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00', 'presto']
+ ].each do |user_agent, rendering_engine|
+ @user_agent = user_agent
+ browser_class.should =~ /#{rendering_engine}/
+ end
+ end
+
+ def request
+ mock('request', :user_agent => @user_agent)
+ end
+
+end
4 spec/spec.opts
@@ -0,0 +1,4 @@
+--colour
+--format s
+--loadby mtime
+--reverse
14 spec/spec_helper.rb
@@ -0,0 +1,14 @@
+ENV["RAILS_ENV"] ||= 'test'
+require File.dirname(__FILE__) + "/../../../../config/environment" unless defined?(RAILS_ROOT)
+require 'spec/autorun'
+require 'spec/rails'
+require 'action_controller'
+require 'action_controller/assertions/selector_assertions'
+
+include ActionController::Assertions::SelectorAssertions
+
+require File.dirname(__FILE__) + "/../lib/redgreengrid"
+
+Spec::Runner.configure do |config|
+
+end
13 tasks/redgreengrid_tasks.rake
@@ -0,0 +1,13 @@
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gemspec|
+ gemspec.name = "redgreengrid"
+ gemspec.summary = "Compass extention for creating baseline grid layouts"
+ gemspec.description = "RedGreenGred makes it easy for you to build cross-browser baseline grid layouts."
+ gemspec.email = "redgreengrid@hagenburger.net"
+ gemspec.homepage = "http://www.hagenburger.net"
+ gemspec.authors = ["Nico Hagenburger"]
+ end
+rescue LoadError
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
+end
10 templates/screen.sass
@@ -0,0 +1,10 @@
+@import redgreengrid/redgreengrid.sass
+
+// Choose your favorite font family, size and line height:
+@import redgreengrid/typography/helvetica_13_20.sass
+//@import redgreengrid/typography/lucida_13_20.sass
+//@import redgreengrid/typography/verdana_12_20.sass
+//@import redgreengrid/typography/arial_13_20.sass
+
++rgg
++rgg-development

0 comments on commit 35482ac

Please sign in to comment.