css_grid 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- css_grid (1.0.0)
4
+ css_grid (2.0.0)
5
5
  hash_extend
6
6
  railties (>= 3.1.0)
7
7
 
@@ -26,7 +26,7 @@ GEM
26
26
  multi_json (~> 1.0)
27
27
  builder (3.0.3)
28
28
  erubis (2.7.0)
29
- hash_extend (1.0.1)
29
+ hash_extend (1.1.0)
30
30
  hike (1.2.1)
31
31
  i18n (0.6.1)
32
32
  journey (1.0.4)
data/README.md CHANGED
@@ -6,6 +6,10 @@ __Grid__ is a 12 column alignment system, based on 1140px width. That fit for 12
6
6
 
7
7
  __Helpers__ facilitate the use of the grid syntax, to produce correct html markdown. This allow you to pass collections and block, and map the result to insert it into correct html tags.
8
8
 
9
+ ## Version
10
+
11
+ Current Version is 2.0.0. This doc is about 1.0.0. Update will be realease soon
12
+
9
13
  ## Installation
10
14
 
11
15
  Add this line to your application's Gemfile:
data/css_grid.gemspec CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/css_grid/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Thomas Petrachi"]
6
6
  gem.email = ["thomas.petrachi@vodeclic.com"]
7
- gem.description = %q{Provide CSS grid stylesheet, plus several helpers}
7
+ gem.description = %q{Provide CSS grid stylesheet and CSS grid helpers}
8
8
  gem.summary = %q{grid.css and GridHelper module}
9
9
  gem.homepage = "https://github.com/petrachi/css_grid"
10
10
 
data/lib/.DS_Store CHANGED
Binary file
@@ -1,57 +1,96 @@
1
- @mixin span($width) { width: $width; margin: 0 1.74%; float: left; min-height: 1px; }
2
- @mixin offset($width) { margin-left: $width + 5.22%; }
1
+ @mixin span($full, $col_num) {
2
+ width: (($col_num / 12) * 100 - 1.74 * 2) / 100 * $full;
3
+ margin: 0 (1.74 / 100 * $full);
4
+ float: left; min-height: 1px;
5
+ }
3
6
 
7
+ @mixin prepend($full, $col_num) { margin-left: (($col_num / 12) * 100 - 1.74 * 2) / 100 * $full + (1.74 * 3 / 100 * $full); }
8
+ @mixin append($full, $col_num) { margin-right: (($col_num / 12) * 100 - 1.74 * 2) / 100 * $full + (1.74 * 3 / 100 * $full); }
4
9
 
5
- .container {
6
-
7
- .row {
8
- width: 100%; max-width: 1140px; min-width: 755px; margin: 0 auto; overflow: hidden;
9
-
10
- .one_span { @include span(4.85%); } /* 55px */
11
- .two_span { @include span(13.18%); } /* 150px */
12
- .three_span { @include span(21.51%); } /* 245px */
13
- .four_span { @include span(29.84%); } /* 340px */
14
- .five_span { @include span(38.17%); }
15
- .six_span { @include span(46.5%); } /* 530px */
16
- .seven_span { @include span(54.83%); }
17
- .eight_span { @include span(63.16%); }
18
- .nine_span { @include span(71.49%); }
19
- .ten_span { @include span(79.82%); }
20
- .eleven_span { @include span(88.15%); }
21
- .twelve_span { @include span(96.47%); }
22
-
23
- .offset_one { @include offset(4.85%); }
24
- .offset_two { @include offset(13.18%); }
25
- .offset_three { @include offset(21.51%); }
26
- .offset_four { @include offset(29.84%); }
27
- .offset_five { @include offset(38.17%); }
28
- .offset_six { @include offset(46.5%); }
29
- .offset_seven { @include offset(54.83%); }
30
- .offset_eight { @include offset(63.16%); }
31
- .offset_nine { @include offset(71.49%); }
32
- .offset_ten { @include offset(79.82%); }
33
- .offset_eleven { @include offset(88.15%); }
34
- .offset_twelve { @include offset(96.47%); }
10
+ @mixin nested($grid_width){ margin: 0 (-1.74 / 100 * $grid_width); min-width: 0; }
11
+
12
+ @mixin grid($grid_width){
13
+ .container {
14
+ .row {
15
+ width: $grid_width; margin: 0 auto; overflow: hidden;
16
+
17
+ &.nested{ margin: 0 (-1.74 / 100 * $grid_width); min-width: 0; width: auto; }
18
+
19
+ .one_span { @include span($grid_width, 1); } /* 55px */
20
+ .two_span { @include span($grid_width, 2); } /* 150px */
21
+ .three_span { @include span($grid_width, 3); } /* 245px */
22
+ .four_span { @include span($grid_width, 4); } /* 340px */
23
+ .five_span { @include span($grid_width, 5); }
24
+ .six_span { @include span($grid_width, 6); } /* 530px */
25
+ .seven_span { @include span($grid_width, 7); }
26
+ .eight_span { @include span($grid_width, 8); }
27
+ .nine_span { @include span($grid_width, 9); }
28
+ .ten_span { @include span($grid_width, 10); }
29
+ .eleven_span { @include span($grid_width, 11); }
30
+ .twelve_span { @include span($grid_width, 12); }
31
+
32
+ .prepend_one { @include prepend($grid_width, 1) }
33
+ .prepend_two { @include prepend($grid_width, 2) }
34
+ .prepend_three { @include prepend($grid_width, 3); }
35
+ .prepend_four { @include prepend($grid_width, 4); }
36
+ .prepend_five { @include prepend($grid_width, 5); }
37
+ .prepend_six { @include prepend($grid_width, 6); }
38
+ .prepend_seven { @include prepend($grid_width, 7); }
39
+ .prepend_eight { @include prepend($grid_width, 8); }
40
+ .prepend_nine { @include prepend($grid_width, 9); }
41
+ .prepend_ten { @include prepend($grid_width, 10); }
42
+ .prepend_eleven { @include prepend($grid_width, 11); }
43
+ .prepend_twelve { @include prepend($grid_width, 12); }
44
+
45
+ .append_one { @include append($grid_width, 1) }
46
+ .append_two { @include append($grid_width, 2) }
47
+ .append_three { @include append($grid_width, 3); }
48
+ .append_four { @include append($grid_width, 4); }
49
+ .append_five { @include append($grid_width, 5); }
50
+ .append_six { @include append($grid_width, 6); }
51
+ .append_seven { @include append($grid_width, 7); }
52
+ .append_eight { @include append($grid_width, 8); }
53
+ .append_nine { @include append($grid_width, 9); }
54
+ .append_ten { @include append($grid_width, 10); }
55
+ .append_eleven { @include append($grid_width, 11); }
56
+ .append_twelve { @include append($grid_width, 12); }
57
+ }
35
58
  }
59
+ }
60
+
61
+
62
+ @media all {
63
+ @include grid(1140px);
36
64
 
37
- img, object, embed { max-width: 100%; }
38
- img { height: auto; }
65
+ .container {
66
+ img, object, embed { max-width: 100%; }
67
+ img { height: auto; }
68
+ }
69
+ }
39
70
 
71
+
72
+ /* Screens 980px to 1140px */
73
+ @media only screen and (max-width: 1139px) {
74
+ @include grid(980px);
40
75
  }
41
76
 
42
77
 
43
- /* Smaller screens */
44
- @media only screen and (max-width: 1023px) {
78
+ /* Screens 768px to 979px */
79
+ @media only screen and (max-width: 979px) {
45
80
  body { font-size: 0.8em; line-height: 1.5em; }
81
+
82
+ @include grid(760px);
46
83
  }
47
84
 
48
85
 
49
- /* Mobile */
86
+ /* Mobile 0 to 767px */
50
87
  @media handheld, only screen and (max-width: 767px) {
51
88
  body { font-size: 16px; -webkit-text-size-adjust: none; }
52
89
 
53
90
  .container{
54
- .row { min-width: 0; padding: 0;
91
+ .row { width: 100%; padding: 0;
92
+ &.nested{ margin: 0 -20px; }
93
+
55
94
  .one_span, .two_span, .three_span, .four_span, .five_span, .six_span, .seven_span, .eight_span, .nine_span, .ten_span, .eleven_span, .twelve_span {
56
95
  width: auto; float: none; margin: 0; padding: 0 20px;
57
96
  }
@@ -1,3 +1,3 @@
1
1
  module CssGrid
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/css_grid.rb CHANGED
@@ -2,68 +2,123 @@ require "css_grid/version"
2
2
  require "css_grid/engine"
3
3
 
4
4
  module GridHelper
5
- TWELVE_STRING_INTS = {:one => 1, :two => 2, :three => 3, :four => 4, :five => 5, :six => 6, :seven => 7, :eight => 8, :nine => 9, :ten => 10, :evelen => 11, :twelve => 12}
6
-
7
- def grid element_class, options = Hash.new, &block
8
- html_id, html_class, offset = options.delete_many :id, :class, :offset
9
- offset = TWELVE_STRING_INTS.invert[offset] if offset.class == Fixnum
10
-
11
- content_tag(:div, nil, :id => html_id, :class => "#{ element_class } #{ html_class } #{ "offset_#{ offset }" if offset }" , &block)
5
+ TWELVE_STRING_INTS = { :one => 1, :two => 2, :three => 3, :four => 4, :five => 5, :six => 6,
6
+ :seven => 7, :eight => 8, :nine => 9, :ten => 10, :evelen => 11, :twelve => 12 }
7
+ TWELVE_STRING_INTS_INVERT = TWELVE_STRING_INTS.invert
8
+
9
+
10
+ GRID_CONFIG = { :classes => Hash.new{ |hash, key| hash[key] = key },
11
+ :elements => Hash.new(:div).merge(:container => :section) }
12
+
13
+ def initialize *args
14
+ @nested_stack = []
15
+ super
12
16
  end
13
-
14
- def col col_number, options = Hash.new, &block
15
- html_id, html_class, collection = options.delete_many :id, :class, :collection
16
- collection ||= [1]
17
-
18
- collection_length = TWELVE_STRING_INTS[col_number.to_sym]
19
- span_width = TWELVE_STRING_INTS.invert[ 12 / collection_length ]
20
-
21
- raise ArgumentError, "collection.size must be <= #{ collection_length }" if collection.size > collection_length
22
-
23
- cols = collection.map do |elt|
24
- eval %{
25
- #{ span_width }_span do
26
- capture(elt, &block)
27
- end }
28
- end
29
-
30
- row :id => html_id, :class => html_class do
31
- cols.inject(ActiveSupport::SafeBuffer.new){ |buffer, col| buffer.safe_concat(col) }
17
+
18
+ def grid tag, options = {}, &block
19
+ prepend = TWELVE_STRING_INTS_INVERT[options.delete :prepend]
20
+ append = TWELVE_STRING_INTS_INVERT[options.delete :append]
21
+
22
+ warn "WARNING : argument ':nested' is not supported for '#{ tag }'" if options[:nested].present? and tag != :row
23
+
24
+ if tag =~ /(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)_span$/
25
+ @nested_stack << $1
26
+
27
+ unstack = true
28
+ else
29
+ warn "WARNING : argument ':prepend' is not supported for '#{ tag }'" if prepend.present?
30
+ warn "WARNING : argument ':append' is not supported for '#{ tag }'" if append.present?
31
+
32
+ unstack = false
32
33
  end
34
+
35
+ content_class = [GRID_CONFIG[:classes][tag], options.delete(:class)]
36
+ content_class << "#{ GRID_CONFIG[:classes][:prepend] }_#{ prepend }" if prepend
37
+ content_class << "#{ GRID_CONFIG[:classes][:append] }_#{ append }" if append
38
+ content_class << GRID_CONFIG[:classes][:nested] if options.delete(:nested)
39
+
40
+ safe_buffer = content_tag(GRID_CONFIG[:elements][tag], nil, :id => options.delete(:id), :class => content_class.join(" ") , &block)
41
+
42
+ @nested_stack.pop if unstack
43
+ safe_buffer
33
44
  end
34
45
 
35
46
  def recollect size, collection
36
- recollected = Array.new
47
+ recollected = []
37
48
  0.step(collection.size - 1, size) do |i|
38
49
  recollected << collection[i..i + size - 1]
39
50
  end
40
51
  recollected
41
52
  end
42
-
43
- def rows col_number, options = Hash.new, &block
44
- html_id, html_class, collection = options.delete_many :id, :class, :collection
45
- collection ||= [1]
46
-
47
- recollection_size = TWELVE_STRING_INTS[col_number.to_sym]
48
-
49
- rows = recollect(recollection_size, collection).map do |collection_mini|
50
- col col_number, {:collection => collection_mini}, &block
53
+
54
+ def cols_container col_number, options = {}, &block
55
+ options[:rows] ||= {}
56
+ options[:spans] ||= {}
57
+
58
+ if @nested_stack.present?
59
+ options[:rows].merge!({:nested => true})
60
+ options[:nested_width] ||= TWELVE_STRING_INTS[@nested_stack.last.to_sym]
51
61
  end
62
+
63
+ disable = [*options.delete(:disable)]
64
+ nested = [*options.delete(:nested)]
65
+
66
+ options[:rows].merge!({:nested => true}) if nested.delete :container
67
+
68
+ collection_length = TWELVE_STRING_INTS[col_number]
69
+ span_width = @span_width || TWELVE_STRING_INTS_INVERT[(options.delete(:nested_width) || 12) / (collection_length + (options[:spans][:prepend] || 0) + (options[:spans][:append] || 0))]
70
+
71
+ rows = recollect(collection_length, options.delete(:collection) || [1]).map do |collection_mini|
72
+ cols = collection_mini.map do |elt|
52
73
 
53
- container :id => html_id, :class => html_class do
54
- rows.inject(ActiveSupport::SafeBuffer.new){ |buffer, col| buffer.safe_concat(col) }
74
+ if disable.include? :spans
75
+ capture(elt, &block)
76
+
77
+ else
78
+ grid("#{ span_width }_span".to_sym, options[:spans].clone) do
79
+ safe_buffer = capture(elt, &block)
80
+ safe_buffer = grid(:row, :nested=>true){ safe_buffer } if nested.include? :spans
81
+
82
+ safe_buffer
83
+ end
84
+ end
85
+ end
86
+
87
+ grid(:row, options[:rows].clone){ cols.reduce(:safe_concat) }
55
88
  end
89
+
90
+ safe_buffer = rows.reduce(:safe_concat)
91
+ safe_buffer = grid(:container, :id=>options.delete(:id), :class=>options.delete(:class)){ safe_buffer } unless disable.delete :container
92
+ safe_buffer
93
+ end
94
+
95
+ def spans_container span_width, options = {}, &block
96
+ if @nested_stack.present?
97
+ options[:nested_width] ||= TWELVE_STRING_INTS[@nested_stack.last.to_sym]
98
+ end
99
+
100
+ @span_width = span_width
101
+ col_number = TWELVE_STRING_INTS_INVERT[(options.delete(:nested_width) || 12) / TWELVE_STRING_INTS[span_width]]
102
+
103
+ safe_buffer = cols_container col_number, options, &block
104
+
105
+ @span_width = nil
106
+ safe_buffer
56
107
  end
57
108
 
58
109
 
110
+ def one_col_row options = {}, &block
111
+ cols_container :one, options.merge(:disable=>:container, :rows=>{:id=>options.delete(:id), :class=>options.delete(:class)}), &block
112
+ end
113
+
59
114
  def method_missing method_name, *args, &block
60
- case method_name.to_s
115
+ case method_name.to_sym
61
116
  when /^(container|row|(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)_span)$/
62
- self.grid($1, *args, &block)
63
- when /^(one|two|three|four|six|twelve)_col_row$/
64
- self.col($1, *args, &block)
65
- when /^(one|two|three|four|six|twelve)_col_container$/
66
- self.rows($1, *args, &block)
117
+ self.grid($1.to_sym, *args, &block)
118
+ when /^(one|two|three|four|six|twelve)_cols?_container$/
119
+ self.cols_container($1.to_sym, *args, &block)
120
+ when /^(one|two|three|four|six|twelve)_spans?_container$/
121
+ self.spans_container($1.to_sym, *args, &block)
67
122
  else super
68
123
  end
69
124
  end
@@ -71,10 +126,11 @@ module GridHelper
71
126
  def respond_to? method_name, include_private = false
72
127
  case method_name.to_s
73
128
  when /^(container|row|(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)_span)$/,
74
- /^(one|two|three|four|six|twelve)_col_row$/,
75
- /^(one|two|three|four|six|twelve)_col_container$/
129
+ /^(one|two|three|four|six|twelve)_cols?_container$/,
130
+ /^(one|two|three|four|six|twelve)_spans?_container$/
76
131
  true
77
132
  else super
78
133
  end
79
134
  end
135
+
80
136
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-01 00:00:00.000000000 Z
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -43,7 +43,7 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: Provide CSS grid stylesheet, plus several helpers
46
+ description: Provide CSS grid stylesheet and CSS grid helpers
47
47
  email:
48
48
  - thomas.petrachi@vodeclic.com
49
49
  executables: []
@@ -79,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: -3545808649529635569
82
+ hash: 828543185665201826
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  segments:
90
90
  - 0
91
- hash: -3545808649529635569
91
+ hash: 828543185665201826
92
92
  requirements: []
93
93
  rubyforge_project:
94
94
  rubygems_version: 1.8.24