Module: ApplicationConfig::ViewHelpers

Defined in:
lib/application_config/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#javascripts_from_config(options = {}) ⇒ 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
35
# File 'lib/application_config/view_helpers.rb', line 3

def javascripts_from_config(options = {})
  html = ""
  if defined?(AppConfig) and AppConfig.javascripts
    AppConfig.javascripts.each do |javascript|
      if javascript.is_a?(OpenStruct)
        javascript = javascript.marshal_dump
      end
      
      if javascript.is_a? Hash
        javascript.each do |key, val|
          args = [val].flatten
          if defined?(Merb)
            args << options.merge(:bundle => key.to_sym)
            html << js_include_tag(*args)
          elsif defined?(Rails)
            args << options.merge(:cache => key.to_s)
            html << javascript_include_tag(*args)
          end
          html << "\n"
        end
      else
        args = [javascript].flatten
        args << options
        if defined?(Merb)
          html << js_include_tag(*args)
        elsif defined?(Rails)
          html << javascript_include_tag(*args)
        end
      end
    end
  end
  return html
end

#stylesheets_from_config(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/application_config/view_helpers.rb', line 37

def stylesheets_from_config(options = {})
  html = ""
  if defined?(AppConfig) and AppConfig.stylesheets
    AppConfig.stylesheets.each do |stylesheet|
      if stylesheet.is_a?(OpenStruct)
        stylesheet = stylesheet.marshal_dump
      end
      
      if stylesheet.is_a? Hash
        stylesheet.each do |key, val|
          args = [val].flatten
          if defined?(Merb)
            args << options.merge(:bundle => key.to_sym)
            html << css_include_tag(*args)
          elsif defined?(Rails)
            args << options.merge(:cache => key.to_s)
            html << stylesheet_link_tag(*args)
          end
        end
      else
        args = [stylesheet].flatten
        args << options
        html << stylesheet_link_tag(*args)
      end
      html << "\n"
    end
  end
  return html
end