Module: Labjs::TagHelper

Defined in:
lib/labjs-rails/tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#labjs_format(file, dir = DEFAULT_DIR) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/labjs-rails/tag_helper.rb', line 36

def labjs_format(file, dir=DEFAULT_DIR)
  unless file =~ /http:/
    file = "/#{dir}/#{file}" unless file =~ /\/?#{dir}/
    file.gsub!(/\/+/, '/')
    file = "#{file}.js" unless file =~ /\.js$/
    file = "/#{file}" unless file =~ /^\//
  end
  file
end

#labjs_include_tag(*sources) ⇒ Object



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/labjs-rails/tag_helper.rb', line 11

def labjs_include_tag(*sources)
  options = sources.extract_options!
  scripts = "<script type=\"text/javascript\">"
  scripts += "$LAB"
  options.each do |key, value|
    if key.to_s == "require"
      value.each do |file|
        script = labjs_format(file)
        scripts += ".script('#{script}').wait()"
      end
    end
  end
  options.each do |key, value|
    if key.to_s == "files"
      value.each do |file|
        script = labjs_format(file)
        scripts += ".script('#{script}')"
      end
    end
  end
  
  scripts += "</script>"
  scripts.html_safe
end

#labjs_load(file, dir = DEFAULT_DIR) ⇒ Object



6
7
8
9
# File 'lib/labjs-rails/tag_helper.rb', line 6

def labjs_load(file, dir=DEFAULT_DIR)
  file = labjs_format(file, dir)
  "<script type=\"text/javascript\" src=\"#{file}\"></script>".html_safe
end