Module: ApplicationConfig::ViewHelpers

Defined in:
lib/application_config/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#javascriptsObject

Collects all javascripts found in the app_configs and outputs them as script tags



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
36
37
38
39
40
41
42
43
# File 'lib/application_config/view_helpers.rb', line 5

def javascripts
  asset_list = []
  if AppConfig.javascripts
    asset_list << AppConfig.javascripts.to_a
  end
  asset_list << AppConfigJavascripts.javascripts.to_a
  
  html = []
  asset_list.flatten.compact.each do |bundle_list|
    if bundle_list.is_a? String
      html << js_include_tag(bundle_list)
    else
      bundle_list = bundle_list.marshal_dump if bundle_list.is_a? OpenStruct
      bundle_list.each do |key, path_list|
        path_list = [path_list].flatten
      
        scripts = []
        path_list.each do |path|
          if path.to_s.include?("*")
            if Merb::Assets::JavascriptAssetBundler.cached_bundle?(key.to_sym)
              scripts << key.to_s
            else
              Dir["#{Merb.root}/public/javascripts/#{path}"].each do |item|
                scripts << item.gsub("#{Merb.root}/public/javascripts/", "")
              end
            end
          else
            scripts << path
          end
        end
        scripts << {:bundle => key.to_sym}
        html << js_include_tag(*scripts)
      end
    end
  end
  
  html << include_required_js
  html.join("\n")
end

#stylesheetsObject

Collects all stylesheets found in the app_configs and outputs them as link tags



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/application_config/view_helpers.rb', line 46

def stylesheets
  asset_list = []
  if AppConfig.stylesheets
    asset_list << AppConfig.stylesheets.to_a
  end
  asset_list << AppConfigStylesheets.stylesheets.to_a
  
  html = []
  asset_list.flatten.compact.each do |bundle_list|
    if bundle_list.is_a? String
      html << css_include_tag(bundle_list)
    else
      bundle_list = bundle_list.marshal_dump if bundle_list.is_a? OpenStruct
      bundle_list.each do |key, path_list|
        path_list = [path_list].flatten
      
        scripts = []
        path_list.each do |path|
          if path.to_s.include?("*")
            if Merb::Assets::StylesheetAssetBundler.cached_bundle?(key.to_sym)
              scripts << key.to_s
            else
              Dir["#{Merb.root}/public/stylesheets/#{path}"].each do |item|
                scripts << item.gsub("#{Merb.root}/public/stylesheets/", "")
              end
            end
          else
            scripts << path
          end
        end
        scripts << {:bundle => key.to_sym}
        html << css_include_tag(*scripts)
      end
    end
  end
  
  html << include_required_css
  html.join("\n")
end