Module: Zfben_libjs::Helpers
- Defined in:
- lib/zfben_libjs/helpers.rb
Constant Summary collapse
- Lib_version =
Time.now.strftime('?%s')
Instance Method Summary collapse
Instance Method Details
#asset_host ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/zfben_libjs/helpers.rb', line 44 def asset_host if defined? Rails if Rails.configuration.action_controller.has_key?(:asset_host) && !Rails.configuration.action_controller[:asset_host].nil? return Rails.configuration.action_controller[:asset_host] + (request.port == 80 ? '' : (':' << request.port.to_s)) end end '' end |
#lib(*opts) ⇒ Object
3 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 |
# File 'lib/zfben_libjs/helpers.rb', line 3 def lib *opts html = '' unless opts.blank? preload = [] lib_preload = [] opts.each do |name| name = name.to_s if name.end_with?('.css') || name.end_with?('.js') preload.push name else lib_preload.push name end end if preload.length > 0 preload.each do |url| if url.end_with?('.css') html << lib_css(url) else html << lib_js(url) end end end html << lib_js('lib.js') if lib_preload.length > 0 html << "<script>lib('#{lib_preload.join(' ')}')</script>" end end return html end |
#lib_css(url) ⇒ Object
40 41 42 |
# File 'lib/zfben_libjs/helpers.rb', line 40 def lib_css url return "<link rel='stylesheet' href='#{asset_host}/stylesheets/#{url}#{Lib_version}' />" end |
#lib_js(url) ⇒ Object
36 37 38 |
# File 'lib/zfben_libjs/helpers.rb', line 36 def lib_js url return "<script src='#{asset_host}/javascripts/#{url}#{Lib_version}'></script>" end |