Module: ScriptHelpers::ScriptAndCssHelper

Defined in:
app/helpers/script_helpers/script_and_css_helper.rb

Instance Method Summary collapse

Instance Method Details

#css(options = {}, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/script_helpers/script_and_css_helper.rb', line 35

def css(options = {}, &block)
  if options.include? :src
    @_script_helpers_css ||= {}

    unless @_script_helpers_css[options[:src]]
      @_script_helpers_css[options[:src]] = true
      content_for :css_tags, "\n"
      content_for :css_tags, stylesheet_link_tag(options[:src])
    end
  end

  if block
    content_for :css, "\n"
    content_for :css, capture(&block)
  end
end

#css_contentsObject



56
57
58
59
60
61
62
# File 'app/helpers/script_helpers/script_and_css_helper.rb', line 56

def css_contents
  contents = content_for :css

  if contents.present?
     :style, contents, :type => "text/css"
  end
end

#css_tag_contentsObject



52
53
54
# File 'app/helpers/script_helpers/script_and_css_helper.rb', line 52

def css_tag_contents
  content_for :css_tags
end

#script(options = {}, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/script_helpers/script_and_css_helper.rb', line 3

def script(options = {}, &block)
  if options.include? :src
    @_script_helpers_script ||= {}

    unless @_script_helpers_script[options[:src]]
      @_script_helpers_script[options[:src]] = true
      content_for :script_tags, "\n"
      content_for :script_tags, javascript_include_tag(options[:src])
    end
  end

  if block
    return javascript_tag &block if options[:inline]
    content_for :script, "\n"
    content_for :script, capture(&block)
  end

  nil
end

#script_contentsObject



27
28
29
30
31
32
33
# File 'app/helpers/script_helpers/script_and_css_helper.rb', line 27

def script_contents
  contents = content_for :script

  if contents.present?
    javascript_tag contents
  end
end

#script_tag_contentsObject



23
24
25
# File 'app/helpers/script_helpers/script_and_css_helper.rb', line 23

def script_tag_contents
  content_for :script_tags
end