Module: Viewaide::Helpers::GridHelper
- Included in:
- Viewaide::Helpers
- Defined in:
- lib/viewaide/helpers/grid_helper.rb
Constant Summary collapse
- MULTIPLES =
{ :one_twentyfourth => (1/24.0), :one_twelfth => (1/12.0), :one_eigth => (1/8.0), :one_sixth => (1/6.0), :five_twentyfourths => (5/24.0), :one_fourth => (1/4.0), :seven_twentyfourths => (7/24.0), :one_third => (1/3.0), :three_eigths => (3/8.0), :five_twelfths => (5/12.0), :eleven_twentyfourths => (11/24.0), :one_half => (1/2.0), :half => (1/2.0), :thirteen_twentyfourths => (13/24.0), :seven_twelfths => (7/12.0), :five_eigths => (5/8.0), :two_thirds => (2/3.0), :seventeen_twentyfourths => (17/24.0), :three_fourths => (3/4.0), :nineteen_twentyfourths => (19/24.0), :five_sixths => (5/6.0), :seven_eigths => (7/8.0), :eleven_twelfths => (11/12.0), :twentythree_twentyfourths => (23/24.0), :full => (1.0) }.freeze
- MULTIPLE_FRACTIONS =
MULTIPLES.keys.map {|key| key.to_s }.freeze
Class Method Summary collapse
-
.blueprint_grid! ⇒ Object
force use of Blueprint-style classes (the default).
-
.easel_grid! ⇒ Object
force use of Easel-style classes.
Instance Method Summary collapse
- #clean_column(classes, &block) ⇒ Object
-
#column(*args, &block) ⇒ String
Returns a div with the correct width-calculated class.
-
#container(size = nil, *args, &block) ⇒ String
Wraps content in a container.
-
#last_column ⇒ String
Last column (based on Blueprint or Easel grid formats).
- #method_missing_with_viewaide_widths(call, *args) ⇒ Object
Class Method Details
.blueprint_grid! ⇒ Object
force use of Blueprint-style classes (the default)
40 41 42 43 |
# File 'lib/viewaide/helpers/grid_helper.rb', line 40 def self.blueprint_grid! @@last_column = "last" @@column_prefix = "span" end |
.easel_grid! ⇒ Object
force use of Easel-style classes
34 35 36 37 |
# File 'lib/viewaide/helpers/grid_helper.rb', line 34 def self.easel_grid! @@last_column = "col-last" @@column_prefix = "col" end |
Instance Method Details
#clean_column(classes, &block) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/viewaide/helpers/grid_helper.rb', line 104 def clean_column(classes, &block) size = classes.scan(/#{column_prefix}-(\d+)/).flatten.last executed_with_erb = block_given? && block_is_within_action_view?(block) if size.nil? html = capture(&block) executed_with_erb ? concat(html) : html else size = size.to_i increase_depth(size) html = capture(&block) if executed_with_erb concat(html) decrease_depth(size) else decrease_depth(size) html end end end |
#column(*args, &block) ⇒ String
Returns a div with the correct width-calculated class
80 81 82 83 |
# File 'lib/viewaide/helpers/grid_helper.rb', line 80 def column(*args, &block) @_viewaide_column_count ||= application_width col(*args, &block) end |
#container(size = nil, *args, &block) ⇒ String
Wraps content in a container
97 98 99 100 101 102 |
# File 'lib/viewaide/helpers/grid_helper.rb', line 97 def container(size=nil, *args, &block) opts = args. opts.merge!(:suppress_col => true) if size.nil? args = args.insert(0, :container) column(size, *([args, opts].flatten), &block) end |
#last_column ⇒ String
Returns last column (based on Blueprint or Easel grid formats).
48 49 50 |
# File 'lib/viewaide/helpers/grid_helper.rb', line 48 def last_column @@last_column end |
#method_missing_with_viewaide_widths(call, *args) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/viewaide/helpers/grid_helper.rb', line 127 def method_missing_with_viewaide_widths(call, *args) # filter out any initial helper calls found = false MULTIPLE_FRACTIONS.each do |fraction| found = true and break if call.to_s.include?(fraction) end method_missing_without_viewaide_widths(call, *args) and return unless found # one of the widths is somewhere in the helper call; let's find it call.to_s =~ /^((append|prepend|#{column_prefix})_)?(.+)$/ class_name = $2 || column_prefix class_width = $3 if MULTIPLES.keys.include?(class_width.to_sym) width = @_viewaide_column_count || application_width "#{class_name}-#{(width*MULTIPLES[class_width.to_sym]).to_i}" else method_missing_without_viewaide_widths(call, *args) end end |