Method: Slideshow::BackgroundHelper#background

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

#background(*args) ⇒ Object



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

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, "      .\#{clazz} { background: \#{code}; }\n    EOS\n  end\n  \n  # 2) add processing instruction to get style class added to slide \n\n  puts \"  Adding HTML PI for background style class '\#{clazz}'...\"    \n  \"<!-- _S9STYLE_ \#{clazz} -->\\n\"\nend\n" )