Module: Slideshow::BackgroundHelper

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

Instance Method Summary collapse

Instance Method Details

#background(*args) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/slideshow/helpers/background_helper.rb', line 85

def background( *args  )
  
 # make everyting optional; use it like: 
 #   background( code, opts={} )
  
  # check for optional hash for options
  opts = args.last.kind_of?(Hash) ? args.pop : {}

  # check for optional style rule code
  code = args.last.kind_of?(String) ? args.pop : '' 
    
  clazz = opts[:class] || ( 's9'+code.strip.gsub( /[(), ]/, '_' ).gsub( /_{2,}/, '_').gsub( /[^-\w]/, '' ) )
  
  # 1) add background rule to css 
  # e.g. .simple { background: -moz-linear-gradient(top, blue, white); }
  
  unless code.empty?
    puts "  Adding CSS for background style rule..."  
    content_for( :css, <<-EOS )
      .#{clazz} { background: #{code}; }
    EOS
  end
  
  # 2) add processing instruction to get style class added to slide 

  puts "  Adding HTML PI for background style class '#{clazz}'..."    
  "<!-- _S9STYLE_ #{clazz} -->\n"
end

#gradient(*args) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/slideshow/helpers/background_helper.rb', line 54

def gradient( *args )

  # check for optional hash for options
  opts = args.last.kind_of?(Hash) ? args.pop : {}

  colors = args

  clazz = opts[:class] || ( 's9_gradient_linear_'+colors.join('_').gsub( /[(), ]/, '_' ).gsub( /_{2,}/, '_').gsub( /[^-\w]/, '' ) )


  ## generate code
  
  buf  = "linear-gradient(top, #{colors.join(', ')} )"
 

  puts "  Adding CSS for background style rule..."  
  content_for( :css, <<-EOS )
    .#{clazz} { background-image: -webkit-#{buf};
                background-image: -moz-#{buf};
                background-image: -ms-#{buf};
                background-image: -o-#{buf};
                background-image: #{buf};
              }
  EOS

  # add processing instruction to get style class added to slide 

  puts "  Adding HTML PI for background style class '#{clazz}'..."    
  "<!-- _S9STYLE_ #{clazz} -->\n"
end

#gradient_from_headers(*args) ⇒ Object



4
5
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
# File 'lib/slideshow/helpers/background_helper.rb', line 4

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