Method: Slideshow::BackgroundHelper#gradient_from_headers

Defined in:
lib/slideshow/helpers/background_helper.rb

#gradient_from_headers(*args) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/slideshow/helpers/background_helper.rb', line 6

def gradient_from_headers( *args )

  return "" unless headers.has_gradient?   # do nothing if use hasn't set gradient headers (ignore defaults)

  # lets you use headers (gradient, gradient-theme, gradient-colors)
  #  to define gradient (see http://slideshow.rubyforge.org/themes.html for predefined themes)
  
  theme  = headers[ :gradient_theme ]
  colors = headers[ :gradient_colors ].split(' ')  # colors as space separated all-in-one string
  
  buf = ""
  
  if theme == 'diagonal'
    buf << "linear-gradient( top left, #{colors.join(', ')} )"
  elsif theme == 'top-bottom'
    buf << "linear-gradient( top, #{colors.join(', ')} )"
  elsif theme == 'left-right'
    buf << "linear-gradient( left, #{colors.join(', ')} )"
  elsif theme == 'repeat'
    buf << "repeating-linear-gradient( -60deg, #{colors.join(', ')} 10% )"
  elsif theme == 'radial'
    buf << "radial-gradient( #{colors.join(', ')} )"
  elsif theme == 'radial-off-center'
    buf << "radial-gradient( 70% 70%, ellipse, #{colors.join(', ')} )"
  elsif theme == 'radial-repeat'
    buf << "repeating-radial-gradient( 60% 60%, ellipse, #{colors.join(', ')} 10% )"
  else
    buf << "linear-gradient( #{colors.join(', ')} )"
    puts "warning: unknown gradient themes #{theme} - falling back to default"
  end

  puts "  Adding CSS for gradient background style rule using headers..."
  puts "    gradient-theme: #{theme}"
  puts "    gradient-colors: #{colors.join(' ')}"
  
  content_for( :css, <<-EOS )
     /****
       * generated by gradient_from_headers helper; using headers: 
       *   gradient-theme: #{theme}
       *   gradient-colors: #{colors.join(' ')}
       */
    .slide    { background-image: -webkit-#{buf};
                background-image: -moz-#{buf};
                background-image: -ms-#{buf};
                background-image: -o-#{buf};
                background-image: #{buf};
              }
  EOS
end