Class: Caboose::AssetManager

Inherits:
Object
  • Object
show all
Defined in:
app/models/caboose/asset_manager.rb

Class Method Summary collapse

Class Method Details

.referenced_assets_in_caboose_viewsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/caboose/asset_manager.rb', line 27

def AssetManager.referenced_assets_in_caboose_views
  
  # Get anything that was referenced in the views
  spec = Gem::Specification.find_by_name('caboose-cms')            
  files = []
  
  # Stylesheets
  str = `grep -Rh stylesheet_link_tag #{spec.gem_dir}/app/views`      
  str.strip.split("\n").each do |line|
    file = self.replace_css_line(line)
    files << (file.ends_with?('.css') ? "#{file}" : "#{file}.css") if file                
  end

  # Javascript
  str = `grep -Rh javascript_include_tag #{spec.gem_dir}/app/views`      
  str.strip.split("\n").each do |line|
    file = self.replace_js_line(line)        
    files << (file.ends_with?('.js') ? "#{file}" : "#{file}.js") if file
  end
  
  #puts "--------------------------------------------------------------------"
  #puts files.uniq
  #puts "--------------------------------------------------------------------"      
  #return files.uniq
        
end

.referenced_assets_in_viewsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/caboose/asset_manager.rb', line 3

def AssetManager.referenced_assets_in_views
  
  files = []

  # Stylesheets
  str = `grep -Rh stylesheet_link_tag #{Rails.root}/app/views`
  str << `grep -Rh stylesheet_link_tag #{Rails.root}/sites/*/views`
  str.strip.split("\n").each do |line|
    file = self.replace_css_line(line)
    files << (file.ends_with?('.css') ? "#{file}" : "#{file}.css") if file
  end

  # Javascript
  str = `grep -Rh javascript_include_tag #{Rails.root}/app/views`      
  str << `grep -Rh javascript_include_tag #{Rails.root}/sites/*/views`
  str.strip.split("\n").each do |line|
    file = self.replace_js_line(line)
    files << (file.ends_with?('.js') ? "#{file}" : "#{file}.js") if file
  end
  
  return files.uniq
  
end

.replace_css_line(str) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/caboose/asset_manager.rb', line 54

def AssetManager.replace_css_line(str)
  return nil if str.include?('#{') || str.include?('@') || str.include?(".each do")      
  str = str
    .gsub('<%=','')
    .gsub('%>','')
    .gsub('gzip_stylesheet_link_tag','')
    .gsub('stylesheet_link_tag','')
    .gsub('(','')
    .gsub(')','')
    .gsub('"','')
    .gsub("'",'')
    .gsub(',','')
    .gsub(':media => "all"','')
    .strip.split(' ').first.strip
  return nil if str.length == 0 || str.starts_with?('#') || str.starts_with?('http') || str.starts_with?('//')
  return str
end

.replace_js_line(str) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/caboose/asset_manager.rb', line 72

def AssetManager.replace_js_line(str)
  return nil if str.include?('#{') || str.include?('@') || str.include?(".each do")
  str = str
    .gsub('<%=','')
    .gsub('<%','')
    .gsub('%>','')
    .gsub('gzip_javascript_include_tag','')
    .gsub('javascript_include_tag','')
    .gsub('(','')
    .gsub(')','')
    .gsub('"','')
    .gsub("'",'')
    .gsub(",",'')
    .strip.split(' ').first.strip              
  return nil if str.length == 0 || str.starts_with?('#') || str.starts_with?('http') || str.starts_with?('//')
  return str      
end