Class: Megatron::GridHelper::Grid

Inherits:
Helper
  • Object
show all
Defined in:
app/helpers/megatron/grid_helper.rb

Constant Summary collapse

DEFAULTS =
{
  tag: :div,
  match_gutters: false
}

Instance Method Summary collapse

Methods inherited from Helper

inherited

Constructor Details

#initialize(options = {}) ⇒ Grid

Returns a new instance of Grid.



10
11
12
# File 'app/helpers/megatron/grid_helper.rb', line 10

def initialize(options = {})
  @options = DEFAULTS.merge(options)
end

Instance Method Details

#add_media_classes(breakpoint, sizes) ⇒ Object



39
40
41
# File 'app/helpers/megatron/grid_helper.rb', line 39

def add_media_classes(breakpoint, sizes)
  sizes.empty? ? '' : width(*[breakpoint, *sizes])
end

#cell(*args, &block) ⇒ Object



18
19
20
21
22
# File 'app/helpers/megatron/grid_helper.rb', line 18

def cell(*args, &block)
  options = options_from_args(args)
  options[:tag] ||= :div
   options[:tag], class: cell_classes(args, options), &block
end

#cell_classes(args, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/megatron/grid_helper.rb', line 24

def cell_classes(args, options={})
  classes = ['grid-cell']
  if !args.empty? or !options.empty?
    classes << width(*args) if !args.empty?
    classes << options[:class] if options[:class]

    classes << add_media_classes(:xsmall, options[:xsmall]) if options[:xsmall]
    classes << add_media_classes(:small, options[:small]) if options[:small]
    classes << add_media_classes(:medium, options[:medium]) if options[:medium]
    classes << add_media_classes(:large, options[:large]) if options[:large]
    classes << add_media_classes(:xlarge, options[:xlarge]) if options[:xlarge]
  end
  classes
end

#display(body) ⇒ Object



14
15
16
# File 'app/helpers/megatron/grid_helper.rb', line 14

def display(body)
  (@options[:tag], class: grid_classes) { body }
end

#grid_classesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/megatron/grid_helper.rb', line 43

def grid_classes
  classes = ['grid']
  classes << "align-#{@options[:valign]}" if @options[:valign]
  classes << "align-#{@options[:align]}" if @options[:align]
  classes << 'match-gutters' if @options[:match_gutters]
  if @options[:gutters]
    if @options[:gutters].to_s == 'none'
      @options[:gutters] = 'no'
    end
    classes << "#{@options[:gutters]}-gutter" unless @options[:gutters].to_s == 'medium'
  end
  classes << @options[:class] if @options[:class]
  classes
end