Class: ViewAssets::Manager::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/view_assets/manager/map.rb

Direct Known Subclasses

CssMap, JsMap

Instance Method Summary collapse

Instance Method Details

#app_pathObject



61
62
63
# File 'lib/view_assets/manager/map.rb', line 61

def app_path
  ::ViewAssets::APP_FOLDER
end

#drawObject



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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/view_assets/manager/map.rb', line 4

def draw
  map = { :vendor => {}, :lib => {}, :app => {} }

  # App
  # Application
  application_manifest = PathInfo.new("#{app_path}/#{asset_path}/application")
  app_covered_action = false
  if FileTest.exist?("#{application_manifest.abs}.#{ext}")
    map[:app][application_manifest.to_s] = finder.retrieve_manifest(application_manifest, { :shallow => true })
    app_covered_action = true
  end

  # Controllers and Actions
  actions = action_map.retrieve
  actions.each do |controller, actions|
    controller_manifest = PathInfo.new("#{app_path}/#{asset_path}/#{controller}/#{controller}")
    controller_convered_action = false
    if FileTest.exist?("#{controller_manifest.abs}.#{ext}")
      map[:app][controller_manifest.to_s] = finder.retrieve_manifest(controller_manifest, { :shallow => true, :controller => controller })

      controller_convered_action = true
    end

    actions.each do |action|
      action_manifest = "#{app_path}/#{asset_path}/#{controller}/#{action}"
      map[:app][action_manifest] = finder.retrieve(controller, action, { :shallow => true, :controller => controller, :action => action })

      if controller_convered_action || app_covered_action
        map[:app][action_manifest][0] = map[:app][action_manifest][0].basename
      end
    end
  end

  # Vendor
  Pathname.new("#{root}/#{vendor_path}/#{asset_path}").children.each do |entry|
    manifest = PathInfo.new(entry.to_s).rel

    map[:vendor][manifest.basename] = finder.retrieve_manifest(manifest.rel, { :shallow => true })
  end

  # Lib
  Pathname.new("#{root}/#{lib_path}/#{asset_path}").children.each do |entry|
    manifest = PathInfo.new(entry.to_s).rel

    map[:lib][manifest.basename] = finder.retrieve_manifest(manifest.rel, { :shallow => true })
  end

  FileUtils.mkdir_p("#{root}/assets")
  File.open("#{root}/assets/#{asset_path}_assets.yml", 'w') { |file| file << YAML.dump(map) }

  map
end

#lib_pathObject



69
70
71
# File 'lib/view_assets/manager/map.rb', line 69

def lib_path
  ::ViewAssets::LIB_FOLDER
end

#rootObject



57
58
59
# File 'lib/view_assets/manager/map.rb', line 57

def root
  Rails.public_path
end

#vendor_pathObject



65
66
67
# File 'lib/view_assets/manager/map.rb', line 65

def vendor_path
  ::ViewAssets::VENDOR_FOLDER
end