view_assets 1.0.4 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/lib/tasks/tool.rb +29 -0
  2. data/lib/view_assets/finder/directive.rb +26 -26
  3. data/lib/view_assets/finder/finder.rb +46 -15
  4. data/lib/view_assets/manager/manager.rb +6 -18
  5. data/lib/view_assets/manager/map.rb +110 -0
  6. data/lib/view_assets/manager/modifier.rb +214 -0
  7. data/lib/view_assets/packager/actions_map.rb +1 -9
  8. data/lib/view_assets/packager/packager.rb +34 -9
  9. data/lib/view_assets/path_info.rb +4 -0
  10. data/lib/view_assets/railtie.rb +1 -0
  11. data/lib/view_assets/version.rb +1 -1
  12. data/test/dummy/public/assets/javascripts_assets.yml +133 -0
  13. metadata +52 -61
  14. data/MIT-LICENSE +0 -20
  15. data/test/dummy/db/development.sqlite3 +0 -0
  16. data/test/dummy/db/production.sqlite3 +0 -0
  17. data/test/dummy/db/test.sqlite3 +0 -0
  18. data/test/dummy/log/development.log +0 -1842
  19. data/test/dummy/log/production.log +0 -591
  20. data/test/dummy/public/assets/javascripts/application-984fbe5ea1e3d5e4aaa99059a02281ef.js +0 -31
  21. data/test/dummy/public/assets/javascripts/application-e6c5fe847d07144f1b32520af2550e6f.js +0 -122202
  22. data/test/dummy/public/assets/javascripts/controller-e6c5fe847d07144f1b32520af2550e6f.js +0 -122202
  23. data/test/dummy/public/assets/javascripts/controller_action-e6c5fe847d07144f1b32520af2550e6f.js +0 -122202
  24. data/test/dummy/public/assets/javascripts/cutting_records-984fbe5ea1e3d5e4aaa99059a02281ef.js +0 -31
  25. data/test/dummy/public/assets/javascripts/cutting_records-e6c5fe847d07144f1b32520af2550e6f.js +0 -122202
  26. data/test/dummy/public/assets/javascripts/cutting_records_index-1edda21952a9f03edc5ecd1492947fbf.js +0 -122340
  27. data/test/dummy/public/assets/javascripts/material_attributes-984fbe5ea1e3d5e4aaa99059a02281ef.js +0 -31
  28. data/test/dummy/public/assets/javascripts/purchasing_orders-984fbe5ea1e3d5e4aaa99059a02281ef.js +0 -31
  29. data/test/dummy/public/assets/javascripts/sample_orders-984fbe5ea1e3d5e4aaa99059a02281ef.js +0 -31
  30. data/test/dummy/public/assets/javascripts/workshop_reports-984fbe5ea1e3d5e4aaa99059a02281ef.js +0 -31
  31. data/test/dummy/public/assets/stylesheets/application-084630668892a3d31830a3759745a582.css +0 -10478
  32. data/test/dummy/public/assets/stylesheets/application-9097e8fd786603bf9b4f22c0ad4aab7b.css +0 -6
  33. data/test/dummy/public/assets/stylesheets/controller-084630668892a3d31830a3759745a582.css +0 -10478
  34. data/test/dummy/public/assets/stylesheets/controller_action-084630668892a3d31830a3759745a582.css +0 -10478
  35. data/test/dummy/public/assets/stylesheets/cutting_records-084630668892a3d31830a3759745a582.css +0 -10478
  36. data/test/dummy/public/assets/stylesheets/cutting_records_index-084630668892a3d31830a3759745a582.css +0 -10478
  37. data/test/dummy/public/assets/stylesheets/homes-60aed35175c8508853f14087857e6224.css +0 -6
data/lib/tasks/tool.rb ADDED
@@ -0,0 +1,29 @@
1
+ namespace :va do
2
+ namespace :tool do
3
+ require 'view_assets/manager/manager'
4
+
5
+ desc "Change Manifest Name"
6
+ task :mv, [:type, :original, :new_name] do |t, args|
7
+ case args.type
8
+ when 'js'
9
+ ViewAssets::Manager::JsModifier.new.update(args.original, args.new_name, { :verbal => true })
10
+ when 'css'
11
+ ViewAssets::Manager::CssModifier.new.update(args.original, args.new_name, { :verbal => true })
12
+ else
13
+ puts "Unrecognized Type: #{args.type}"
14
+ end
15
+ end
16
+
17
+ desc "Remove Manifest"
18
+ task :rm, [:type, :manifest] do |t, args|
19
+ case args.type
20
+ when 'js'
21
+ ViewAssets::Manager::JsModifier.new.remove(args.manifest, { :verbal => true })
22
+ when 'css'
23
+ ViewAssets::Manager::CssModifier.new.remove(args.manifest, { :verbal => true })
24
+ else
25
+ puts "Unrecognized Type: #{args.type}"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -8,29 +8,29 @@ module ViewAssets
8
8
  if [JS_TYPE, CSS_TYPE].include?(asset_type)
9
9
  @asset_type = asset_type
10
10
  else
11
- raise ConfigurationError.new("asset type should be '#{JS_TYPE}' or '#{CSS_TYPE}'")
11
+ raise ConfigurationError.new("asset type should be '#{JS_TYPE}' or '#{CSS_TYPE}'")
12
12
  end
13
13
  end
14
-
15
- # TODO realize this method
16
- # remember to take different syntax into consideration
17
- def ending_directive?(primitive_params)
18
- # primitive_params.match
19
- end
20
-
14
+
15
+ # # TODO realize this method
16
+ # # remember to take different syntax into consideration
17
+ # def ending_directive?(primitive_params)
18
+ # # primitive_params.match
19
+ # end
20
+
21
21
  # TODO add docs
22
22
  def legal_directive?(primitive_params)
23
23
  [vendor_directive, lib_directive, app_directive].any? { |d| d =~ primitive_params }
24
24
  end
25
-
25
+
26
26
  # return root folder and all the path params that have been split
27
27
  # TODO this method bellow need refactor
28
28
  def parse(primitive_params)
29
29
  asset_root = ''
30
30
  path_param_str = ''
31
31
  path_params = []
32
- unknown_directive = false
33
-
32
+ # unknown_directive = false
33
+
34
34
  # TODO make sure path_param_str will return nil for non-matched result and array for matched result
35
35
  # rememer to write tests for this section of codes
36
36
  if vendor_directive =~ primitive_params
@@ -42,30 +42,30 @@ module ViewAssets
42
42
  elsif app_directive =~ primitive_params
43
43
  asset_root = 'app'
44
44
  path_param_str = primitive_params.match(app_directive)[:path_params]
45
- else
46
- # TODO remove UnknownDirectiveError or try to find another way to get thing done
47
- # raise UnknownDirectiveError.new "'#{primitive_params}' is not in legal directive format"
48
- unknown_directive = true
45
+ # else
46
+ # # TODO remove UnknownDirectiveError or try to find another way to get thing done
47
+ # # raise UnknownDirectiveError.new "'#{primitive_params}' is not in legal directive format"
48
+ # unknown_directive = true
49
49
  end
50
-
50
+
51
51
  # TODO refactor codes bellow after the above paragraph was refactored
52
52
  would_be_path_params = path_param_str.strip.split(/,\s?/)
53
53
  # would_be_path_params = [would_be_path_params] if would_be_path_params.kind_of?(String)
54
54
  path_params = would_be_path_params unless would_be_path_params.empty?
55
-
55
+
56
56
  # unknown_directive ? [nil, nil] : [asset_root, path_params.strip.split(/,\s?/)]
57
- # todo add rspec examples for returning a ['', []] when the primitive_params is illegal
57
+ # TODO: add rspec examples for returning a ['', []] when the primitive_params is illegal
58
58
  [asset_root, path_params]
59
59
  end
60
-
60
+
61
61
  # def all_directives
62
62
  # /#{tree_directive}|#{file_directive}/
63
63
  # end
64
-
64
+
65
65
  def vendor_directive
66
66
  @vendor_directive ||= generate_formula 'require_vendor'
67
67
  end
68
-
68
+
69
69
  def lib_directive
70
70
  @lib_directive ||= generate_formula 'require_lib'
71
71
  end
@@ -73,19 +73,19 @@ module ViewAssets
73
73
  def app_directive
74
74
  @app_directive ||= generate_formula
75
75
  end
76
-
76
+
77
77
  private
78
-
78
+
79
79
  ##
80
80
  # for javascript
81
81
  # double-slash syntax => "//= require_vendor xxx"
82
82
  # space-asterisk syntax => " *= require_vendor xxx"
83
83
  # slash-asterisk syntax => "/*= require_vendor xxx */"
84
- #
84
+ #
85
85
  # for stylesheets
86
86
  # space-asterisk syntax => " *= require_vendor xxx"
87
87
  # slash-asterisk syntax => "/*= require_vendor xxx */"
88
- #
88
+ #
89
89
  # TODO refactor: use reasonable and effective regular expression
90
90
  # TODO use "require_app" as app asset directive and make "require" as a relative directive
91
91
  # TODO BUG => rspec examples is unqualified on slash-asterisk syntax for css
@@ -107,7 +107,7 @@ module ViewAssets
107
107
  }x
108
108
  end
109
109
  end
110
-
110
+
111
111
  def javascript? type
112
112
  %w(js javascript javascripts).include? type
113
113
  end
@@ -32,17 +32,17 @@ module ViewAssets
32
32
  # :action => nil
33
33
  # :full => false
34
34
  # :tagged => false
35
+ # :tagged => false
36
+ # :shallow => false
35
37
  # TODO: need to retrive action-less assets
36
38
  def retrieve(controller = '', action = '', options = {})
37
- # raise ":controller and :action can't be nil" if @controller.nil?
39
+ options = { :full => false, :tagged => false, :shallow => false }.update(options)
38
40
 
39
- options[:full] ||= false
40
- options[:tagged] ||= false
41
-
42
- @assets = []
43
- @parsed_manifests = []
44
- @controller = controller
45
- @action = action
41
+ @assets = []
42
+ @parsed_manifests = []
43
+ @controller = controller
44
+ @action = action
45
+ @shallow_retrieval = options[:shallow]
46
46
 
47
47
  retrieve_controller_assets
48
48
  retrieve_action_assets if @action != ''
@@ -54,12 +54,32 @@ module ViewAssets
54
54
  @assets
55
55
  end
56
56
 
57
+ # manifest path should be a relative path
58
+ def retrieve_manifest(manifest, options = {})
59
+ options = { :full => false, :tagged => false, :shallow => false, :non_ext => true }.update(options)
60
+
61
+ @assets = []
62
+ @parsed_manifests = []
63
+ @controller = options[:controller]
64
+ @action = options[:action]
65
+ @shallow_retrieval = options[:shallow]
66
+
67
+ @assets = meta_retrieve(root, manifest)
68
+ @assets.uniq!
69
+
70
+ @assets.map! { |asset| PathInfo.new(asset).abs } if options[:full]
71
+ @assets.map! { |asset| tag("/#{asset.rel}") } if options[:tagged]
72
+
73
+ @assets
74
+ end
75
+
57
76
  private
58
77
 
59
78
  ##
60
79
  # Check out whether all assets is existed or not
61
80
  # It is better to be turned off in production
62
81
  # TODO: add Rspec Examples
82
+ # TODO: apply verify function
63
83
  def verify
64
84
  all_assets.each do |asset|
65
85
  raise AssetNotFound.new("File #{asset} DOEST EXIST") unless FileTest.exist?(asset.abs)
@@ -82,7 +102,10 @@ module ViewAssets
82
102
  manifest = controller_manifest if FileTest.exist?(controller_manifest)
83
103
 
84
104
  # TODO add rspec example
85
- return assets if manifest.nil?
105
+ return @assets if manifest.nil?
106
+
107
+ # TODO: test when application is not exist
108
+ return @assets.push(manifest.rel) if @shallow_retrieval
86
109
 
87
110
  @assets.concat(retrieve_assets_from(manifest) << manifest.rel)
88
111
  end
@@ -115,9 +138,9 @@ module ViewAssets
115
138
  end
116
139
  end
117
140
 
118
- # start point of parsing dependent assets
141
+ # Start Point of Parsing Dependent Assets
119
142
  def retrieve_assets_from(manifest)
120
- # TODO rspec examples for non-existed files
143
+ # TODO: Rspec Examples for non-Existed Files
121
144
  return [] if @parsed_manifests.include?(manifest) || !FileTest.exist?(manifest)
122
145
  @parsed_manifests.push(manifest)
123
146
 
@@ -131,6 +154,7 @@ module ViewAssets
131
154
  required_assets.flatten
132
155
  end
133
156
 
157
+ # Support Multiple Path Params
134
158
  def analyze(asset_category, path_params)
135
159
  case asset_category
136
160
  when 'vendor'
@@ -150,20 +174,24 @@ module ViewAssets
150
174
  def retrieve_app_asset(required_asset)
151
175
  required_asset = PathInfo.new(required_asset)
152
176
 
153
- dir = "#{app_path}/#{required_asset.match(/^\//) ? '' : "#{@controller}/"}"
177
+ dir = "#{app_path}#{required_asset.match(/^\//) ? '' : "/#{@controller}/"}"
154
178
  asset = "#{required_asset}#{required_asset.with_ext? ? '' : ".#{asset_extension}"}"
155
179
  PathInfo.new(dir + asset).rel
156
180
  end
157
181
 
158
182
  def retrieve_vendor_assets(manifest)
183
+ return PathInfo.new("#{vendor_path}/#{manifest}").rel if @shallow_retrieval
184
+
159
185
  meta_retrieve(vendor_path, manifest)
160
186
  end
161
187
 
162
188
  def retrieve_lib_assets(manifest)
189
+ return PathInfo.new("#{lib_path}/#{manifest}").rel if @shallow_retrieval
190
+
163
191
  meta_retrieve(lib_path, manifest)
164
192
  end
165
193
 
166
- # for lib and vendor assets, finder will assume that it was stored in the
194
+ # For lib and vendor assets, finder will assume that it was stored in the
167
195
  # root of vendor|lib and the file itself is a manifest file at first. If
168
196
  # that isn't the case, finder will try to locate it in
169
197
  # vendor|lib/:lib_or_vendor_name and take index.js inside that folder as
@@ -174,7 +202,8 @@ module ViewAssets
174
202
  # todo BUG => can't retrieve assets with slash-asterisk(/*= xxx */) directive.
175
203
  # todo add specs for testing required folders without index
176
204
  def meta_retrieve(manifest_path, manifest)
177
- single_file_lib = PathInfo.new("#{manifest_path}/#{manifest}.#{asset_extension}")
205
+ # TODO: add Tests for Manifest With File Extension
206
+ single_file_lib = PathInfo.new("#{manifest_path}/#{manifest}#{PathInfo.new(manifest).with_ext? ? '' : ".#{asset_extension}"}")
178
207
 
179
208
  manifest_dir = "#{manifest_path}/#{manifest}"
180
209
  indexing_lib = PathInfo.new("#{manifest_dir}/index.#{asset_extension}")
@@ -183,7 +212,7 @@ module ViewAssets
183
212
  real_manifest = nil
184
213
  if FileTest.exist?(single_file_lib)
185
214
  real_manifest = single_file_lib
186
- # TODO refactor => add for a hotfix loading required folders without index
215
+ # TODO: refactor => add for a hotfix loading required folders without index
187
216
 
188
217
  all_assets_in_manifest_dir = [real_manifest.rel]
189
218
  else FileTest.exist?(indexing_lib)
@@ -192,6 +221,8 @@ module ViewAssets
192
221
  all_assets_in_manifest_dir = Dir["#{manifest_dir}/**/*.#{asset_extension}"].map { |file| PathInfo.new(file).rel }
193
222
  end
194
223
 
224
+ # return all_assets_in_manifest_dir if @shallow_retrieval
225
+
195
226
  # TODO add specs for dependent assets sequence
196
227
  retrieve_assets_from(real_manifest).flatten
197
228
  .concat(all_assets_in_manifest_dir)
@@ -1,24 +1,12 @@
1
1
  module ViewAssets
2
2
  module Manager
3
+ require 'yaml'
4
+ require 'term/ansicolor'
5
+
3
6
  require 'view_assets'
4
7
  require 'view_assets/finder/core'
5
-
6
- class Manager
7
- def create(instruction)
8
-
9
- end
10
-
11
- def read(asset)
12
-
13
- end
14
-
15
- def update(old_asset, new_asset)
16
-
17
- end
18
-
19
- def remove(asset)
20
-
21
- end
22
- end
8
+ require 'view_assets/packager/actions_map'
9
+ require 'view_assets/manager/map'
10
+ require 'view_assets/manager/modifier'
23
11
  end
24
12
  end
@@ -0,0 +1,110 @@
1
+ module ViewAssets
2
+ module Manager
3
+ class Map
4
+ def draw
5
+ map = { :vendor => {}, :lib => {}, :app => {} }
6
+
7
+ # App
8
+ # Application
9
+ application_manifest = PathInfo.new("#{app_path}/#{asset_path}/application")
10
+ app_covered_action = false
11
+ if FileTest.exist?("#{application_manifest.abs}.#{ext}")
12
+ map[:app][application_manifest.to_s] = finder.retrieve_manifest(application_manifest, { :shallow => true })
13
+ app_covered_action = true
14
+ end
15
+
16
+ # Controllers and Actions
17
+ actions = action_map.retrieve
18
+ actions.each do |controller, actions|
19
+ controller_manifest = PathInfo.new("#{app_path}/#{asset_path}/#{controller}/#{controller}")
20
+ controller_convered_action = false
21
+ if FileTest.exist?("#{controller_manifest.abs}.#{ext}")
22
+ map[:app][controller_manifest.to_s] = finder.retrieve_manifest(controller_manifest, { :shallow => true, :controller => controller })
23
+
24
+ controller_convered_action = true
25
+ end
26
+
27
+ actions.each do |action|
28
+ action_manifest = "#{app_path}/#{asset_path}/#{controller}/#{action}"
29
+ map[:app][action_manifest] = finder.retrieve(controller, action, { :shallow => true, :controller => controller, :action => action })
30
+
31
+ if controller_convered_action || app_covered_action
32
+ map[:app][action_manifest][0] = map[:app][action_manifest][0].basename
33
+ end
34
+ end
35
+ end
36
+
37
+ # Vendor
38
+ Pathname.new("#{root}/#{vendor_path}/#{asset_path}").children.each do |entry|
39
+ manifest = PathInfo.new(entry.to_s).rel
40
+
41
+ map[:vendor][manifest.basename] = finder.retrieve_manifest(manifest.rel, { :shallow => true })
42
+ end
43
+
44
+ # Lib
45
+ Pathname.new("#{root}/#{lib_path}/#{asset_path}").children.each do |entry|
46
+ manifest = PathInfo.new(entry.to_s).rel
47
+
48
+ map[:lib][manifest.basename] = finder.retrieve_manifest(manifest.rel, { :shallow => true })
49
+ end
50
+
51
+ FileUtils.mkdir_p("#{root}/assets")
52
+ File.open("#{root}/assets/#{asset_path}_assets.yml", 'w') { |file| file << YAML.dump(map) }
53
+
54
+ map
55
+ end
56
+
57
+ def root
58
+ Rails.public_path
59
+ end
60
+
61
+ def app_path
62
+ ::ViewAssets::APP_FOLDER
63
+ end
64
+
65
+ def vendor_path
66
+ ::ViewAssets::VENDOR_FOLDER
67
+ end
68
+
69
+ def lib_path
70
+ ::ViewAssets::LIB_FOLDER
71
+ end
72
+ end
73
+
74
+ class JsMap < Map
75
+ def ext
76
+ JS_EXT
77
+ end
78
+
79
+ def asset_path
80
+ JS_PATH
81
+ end
82
+
83
+ def action_map
84
+ ::ViewAssets::Packager::JsActionsMap.new
85
+ end
86
+
87
+ def finder
88
+ ::ViewAssets::Finder::JsFinder.new
89
+ end
90
+ end
91
+
92
+ class CssMap < Map
93
+ def ext
94
+ CSS_EXT
95
+ end
96
+
97
+ def asset_path
98
+ CSS_PATH
99
+ end
100
+
101
+ def action_map
102
+ ::ViewAssets::Packager::CssActionsMap.new
103
+ end
104
+
105
+ def finder
106
+ ::ViewAssets::Finder::CssFinder.new
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,214 @@
1
+ module ViewAssets
2
+ module Manager
3
+ class Modifier
4
+ include Term::ANSIColor
5
+
6
+ def update(index, new_index, options = {})
7
+ options = { :verbal => false }.update(options)
8
+
9
+ type = retrieve_type(index)
10
+ validate_index = map[type].key?(index)
11
+
12
+ # unless validate_index
13
+ # map.each_value do |manifests|
14
+ # validate_index = manifests.select do |manifest, indexes|
15
+ # indexes.any? do |map_index|
16
+ # map_index.match(index)
17
+ # end
18
+ # end
19
+ #
20
+ # break if validate_index
21
+ # end
22
+ # end
23
+
24
+ raise Error.new(red("#{index} is not exist.")) unless validate_index
25
+
26
+ puts green("mv #{index}, #{new_index}") if options[:verbal]
27
+ update_index(index, new_index)
28
+ update_requirements(index, new_index, options)
29
+ end
30
+
31
+ def retrieve_type(index)
32
+ case
33
+ when /^vendor\/.+$/.match(index)
34
+ :vendor
35
+ when /^lib\/.+$/.match(index)
36
+ :lib
37
+ when /^app\/.+$/.match(index)
38
+ :app
39
+ end
40
+ end
41
+
42
+ def update_index(index, new_index)
43
+ path_to_index = PathInfo.new(index).abs
44
+ new_path_to_index = PathInfo.new(new_index).abs
45
+
46
+ if FileTest.exists?(path_to_index)
47
+ FileUtils.mv(path_to_index, new_path_to_index)
48
+ elsif FileTest.exists?("#{path_to_index}.#{ext}")
49
+ FileUtils.mv("#{path_to_index}.#{ext}", "#{new_path_to_index}.#{ext}")
50
+ else
51
+ raise Error.new(red("Manifest #{index} doesn't exist."))
52
+ end
53
+ end
54
+
55
+ def update_requirements(index, new_index, options = {})
56
+ options = { :verbal => false }.update(options)
57
+
58
+ map.each_value do |type|
59
+ type.each do |manifest, requirements|
60
+ if requirements.any? { |requirement| requirement == index }
61
+ puts ("Update #{green(manifest)}") if options[:verbal]
62
+
63
+ if new_index.empty?
64
+ requirements.delete(index)
65
+ else
66
+ requirements[requirements.index(index)] = new_index
67
+ end
68
+
69
+ modify(manifest, generate_requirements_block(manifest, requirements))
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ def generate_requirements_block(manifest, requirements)
76
+ if retrieve_type(manifest) == :app
77
+ # Remove 'app/:asset_path/application' or
78
+ # 'app/:asset_path/application.:ext'
79
+ requirements.delete("app/#{asset_path}/application")
80
+ requirements.delete("app/#{asset_path}/application.#{ext}")
81
+
82
+ # Remove 'app/:asset_path/controller/controller' or
83
+ # 'app/:asset_path/controller/controller.ext'
84
+ if manifest.count('/') > 2
85
+ controller_asset = manifest.gsub(
86
+ /(?<path>.+\/.+\/(?<controller>.+)\/).+/,
87
+ '\k<path>\k<controller>'
88
+ )
89
+
90
+ requirements.delete("#{controller_asset}")
91
+ requirements.delete("#{controller_asset}.#{ext}")
92
+ end
93
+ end
94
+
95
+ requirements.delete("#{manifest}.#{ext}")
96
+ requirements.reject! { |req| req.match(manifest + '/') }
97
+
98
+ requirements.each_with_object(["/**"]) do |requirement, block|
99
+ directive, prefix = case retrieve_type(requirement)
100
+ when :vendor
101
+ [' *= require_vendor ', "vendor/#{asset_path}/"]
102
+ when :lib
103
+ [' *= require_lib ', "lib/#{asset_path}/"]
104
+ when :app
105
+ [' *= require ', "app/#{asset_path}"]
106
+ end
107
+
108
+ block.push("#{directive}#{requirement.gsub(prefix, "")}")
109
+ end.push(' */').join("\n")+"\n"
110
+ end
111
+
112
+ def remove(index, options = {})
113
+ options = { :verbal => false }.update(options)
114
+
115
+ raise Error.new(red("#{index} is not exist.")) unless map[retrieve_type(index)].key?(index)
116
+
117
+ puts green("rm #{index}") if options[:verbal]
118
+ index_path = PathInfo.new(index).abs
119
+ if FileTest.exist?("#{index_path}.#{ext}")
120
+ FileUtils.rm_r("#{index_path}.#{ext}")
121
+ elsif FileTest.exist?(index_path)
122
+ FileUtils.rm_r("#{index_path}")
123
+ else
124
+ raise Error.new(red("#{index} Is Not Exist."))
125
+ end
126
+
127
+ update_requirements(index, '', options)
128
+ end
129
+
130
+ def modify(path, new_requirement_block)
131
+ path = PathInfo.new(path).abs
132
+ manifest = if FileTest.exists?("#{path}.#{ext}")
133
+ "#{path}.#{ext}"
134
+ elsif FileTest.exists?("#{path}/index.#{ext}")
135
+ "#{path}/index.#{ext}"
136
+ else
137
+ raise Error.new(red("Can't Load #{path.rel}"))
138
+ end
139
+
140
+ start_of_requirement_block = false
141
+ end_of_requirement_block = false
142
+ asset_content = ''
143
+
144
+ Pathname.new(manifest).each_line do |line|
145
+ legal_directive = analyize(*directive.parse(line))
146
+
147
+ start_of_requirement_block = true if legal_directive && !start_of_requirement_block
148
+ end_of_requirement_block = true if !legal_directive && start_of_requirement_block && !end_of_requirement_block
149
+
150
+ if !start_of_requirement_block || end_of_requirement_block
151
+ asset_content << line
152
+ end
153
+ end
154
+
155
+ File.open(manifest, 'w') do |file|
156
+ file << new_requirement_block
157
+ file << asset_content
158
+ end
159
+ end
160
+
161
+ def analyize(type, asset)
162
+ return type != '' || asset != []
163
+ end
164
+
165
+ def map
166
+ @map_value
167
+ end
168
+
169
+ def update_map
170
+ @map_value = @map.draw
171
+ end
172
+ end
173
+
174
+ class JsModifier < Modifier
175
+ def initialize
176
+ @map = ::ViewAssets::Manager::JsMap.new
177
+ @map_value = @map.draw
178
+ end
179
+
180
+ DIRECTIVE = ::ViewAssets::Finder::Directive.new(JS_TYPE)
181
+ def directive
182
+ DIRECTIVE
183
+ end
184
+
185
+ def ext
186
+ JS_EXT
187
+ end
188
+
189
+ def asset_path
190
+ ::ViewAssets::JS_PATH
191
+ end
192
+ end
193
+
194
+ class CssModifier < Modifier
195
+ def initialize
196
+ @map = ::ViewAssets::Manager::CssMap.new
197
+ @map_value = @map.draw
198
+ end
199
+
200
+ DIRECTIVE = ::ViewAssets::Finder::Directive.new(CSS_TYPE)
201
+ def directive
202
+ DIRECTIVE
203
+ end
204
+
205
+ def ext
206
+ CSS_EXT
207
+ end
208
+
209
+ def asset_path
210
+ ::ViewAssets::CSS_PATH
211
+ end
212
+ end
213
+ end
214
+ end