public
Description: Merb More: The Full Stack. Take what you need; leave what you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-more.git
Added unpack/mirror abilities through module methods and corresponding 
rake tasks
fabien (author)
Sun May 25 07:28:56 -0700 2008
commit  966c97b4e7ea3d616ca6b128f49f7f2053511144
tree    57b03035e6a2abb296e8e3b76a91e72854d783e4
parent  6a7eaef09335ec991957fb6320f8be55a5c0b932
...
54
55
56
57
 
58
59
60
...
54
55
56
 
57
58
59
60
0
@@ -54,7 +54,7 @@ module FreezerMode
0
     create_freezer_dir(freezer_dir)
0
     action = update ? 'update' : 'install'
0
     puts "#{action} #{@component} and dependencies from rubygems"
0
- `#{sudo} gem #{action} #{@component} --no-rdoc --no-ri -i #{framework_component? ? 'framework' : 'gems'}`
0
+ `#{sudo} gem #{action} #{@component} --no-rdoc --no-ri -i #{freezer_dir}`
0
   end
0
 
0
   def create_freezer_dir(path)
...
270
271
272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
275
276
277
278
279
280
281
 
 
 
 
282
283
 
284
285
286
287
288
289
 
 
290
291
 
292
293
294
295
 
 
 
 
 
 
 
 
 
296
297
298
...
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
 
 
436
437
438
439
440
 
441
442
443
444
445
 
 
446
447
448
 
449
450
451
452
 
453
454
455
456
457
458
459
460
461
462
463
464
0
@@ -270,29 +270,195 @@ module Merb
0
           def remove_app_paths(*args)
0
             args.each { |arg| self.app_paths.delete(arg) }
0
           end
0
+
0
+ # Return all application path component types
0
+ #
0
+ # @return <Array[Symbol]> Component types.
0
+ def app_components
0
+ [:view, :model, :controller, :helper, :mailer, :part]
0
+ end
0
+
0
+ # Return all public path component types
0
+ #
0
+ # @return <Array[Symbol]> Component types.
0
+ def public_components
0
+ [:stylesheet, :javascript, :image]
0
+ end
0
         
0
+ # Return all path component types to mirror
0
+ #
0
+ # If config option :mirror is set return a subset, otherwise return all types.
0
+ #
0
+ # @return <Array[Symbol]> Component types.
0
+ def mirrored_components
0
+ all = slice_paths.keys
0
+ config[:mirror].is_a?(Array) ? config[:mirror] & all : all
0
+ end
0
+
0
+ # Return all application path component types to mirror
0
+ #
0
+ # @return <Array[Symbol]> Component types.
0
+ def mirrored_app_components
0
+ mirrored_components & app_components
0
+ end
0
+
0
+ # Return all public path component types to mirror
0
+ #
0
+ # @return <Array[Symbol]> Component types.
0
+ def mirrored_public_components
0
+ mirrored_components & public_components
0
+ end
0
+
0
+ # Unpack all files from the slice to their app-level location; this will
0
+ # also copy /lib, causing merb-slices to pick up the slice there.
0
+ #
0
+ # @return <Array[Array]>
0
+ # Array of two arrays, one for all copied files, the other for overrides
0
+ # that may have been preserved to resolve collisions.
0
+ def unpack_slice!
0
+ app_slice_root = app_dir_for(:root)
0
+ copied, duplicated = [], []
0
+ Dir.glob(self.root / "**/*").each do |source|
0
+ relative_path = source.relative_path_from(root)
0
+ mirror_file(source, app_slice_root / relative_path, copied, duplicated) if unpack_file?(relative_path)
0
+ end
0
+ public_copied, public_duplicated = mirror_public!
0
+ [copied + public_copied, duplicated + public_duplicated]
0
+ end
0
+
0
+ # Copies all files from mirrored_components to their app-level location
0
+ #
0
+ # This includes :application, :as well
0
+ #
0
+ # @return <Array[Array]>
0
+ # Array of two arrays, one for all copied files, the other for overrides
0
+ # that may have been preserved to resolve collisions.
0
+ def mirror_all!
0
+ mirror_files_for mirrored_components + mirrored_public_components
0
+ end
0
+
0
+ # Copies all application files from mirrored_components to their app-level location
0
+ #
0
+ # @return <Array[Array]>
0
+ # Array of two arrays, one for all copied files, the other for overrides
0
+ # that may have been preserved to resolve collisions.
0
+ def mirror_app!
0
+ mirror_files_for mirrored_app_components
0
+ end
0
+
0
+ # Copies all application files from mirrored_components to their app-level location
0
+ #
0
+ # @return <Array[Array]>
0
+ # Array of two arrays, one for all copied files, the other for overrides
0
+ # that may have been preserved to resolve collisions.
0
+ def mirror_public!
0
+ mirror_files_for mirrored_public_components
0
+ end
0
+
0
+ # Copies all view files to their app-level location - so you can easily modify them
0
+ #
0
+ # @return <Array[Array]>
0
+ # Array of two arrays, one for all copied files, the other for overrides
0
+ # that may have been preserved to resolve collisions.
0
+ def mirror_views!
0
+ mirror_files_for :view
0
+ end
0
+
0
+ # Copy files from specified component path types to their app-level location
0
+ #
0
+ # App-level overrides are preserved by creating duplicates before writing gem-level files.
0
+ # Because of their _override postfix they will load after their original implementation.
0
+ # In the case of views, this won't work, but the user override is preserved nonetheless.
0
+ #
0
+ # @return <Array[Array]>
0
+ # Array of two arrays, one for all copied files, the other for overrides
0
+ # that may have been preserved to resolve collisions.
0
+ def mirror_files_for(*types)
0
+ seen, copied, duplicated = [], [], [] # keep track of files we copied
0
+ types.flatten.each do |type|
0
+ if File.directory?(src_path = dir_for(type)) && (dst_path = app_dir_for(type))
0
+ glob = ((type == :view) ? "**/*.{#{Merb::Template.template_extensions.join(',')}}" : glob_for(type) || "**/*")
0
+ Dir[src_path / glob].each do |src|
0
+ next if seen.include?(src)
0
+ mirror_file(src, dst_path / src.relative_path_from(src_path), copied, duplicated)
0
+ seen << src
0
+ end
0
+ end
0
+ end
0
+ [copied, duplicated]
0
+ end
0
+
0
+ # Helper method to copy a source file to destination while resolving any conflicts.
0
+ #
0
+ # @param source<String> The source path.
0
+ # @param dest<String> The destination path.
0
+ # @param copied<Array> Keep track of all copied files - relative paths.
0
+ # @param duplicated<Array> Keep track of all duplicated files - relative paths.
0
+ # @param postfix<String> The postfix to use for resolving conflicting filenames.
0
+ def mirror_file(source, dest, copied = [], duplicated = [], postfix = '_override')
0
+ base, rest = split_name(source)
0
+ dst_dir = File.dirname(dest)
0
+ dup_path = dst_dir / "#{base}#{postfix}.#{rest}"
0
+ if File.file?(source)
0
+ mkdir_p(dst_dir) unless File.directory?(dst_dir)
0
+ if File.exists?(dest) && !File.exists?(dup_path) && !FileUtils.identical?(source, dest)
0
+ # copy app-level override to *_override.ext
0
+ copy_entry(dest, dup_path, false, false, true)
0
+ duplicated << dup_path.relative_path_from(Merb.root)
0
+ end
0
+ # copy gem-level original to location
0
+ if !File.exists?(dest) || (File.exists?(dest) && !FileUtils.identical?(source, dest))
0
+ copy_entry(source, dest, false, false, true)
0
+ copied << dest.relative_path_from(Merb.root)
0
+ end
0
+ end
0
+ end
0
+
0
+ # Predicate method to check if a file should be taken into account when unpacking files
0
+ #
0
+ # @param file<String> The relative path to test.
0
+ # @return <TrueClass,FalseClass> True if the file may be mirrored.
0
+ def unpack_file?(file)
0
+ @mirror_exceptions_regexp ||= begin
0
+ skip_paths = mirrored_public_components.map { |type| dir_for(type).relative_path_from(self.root) }
0
+ skip_paths += config[:skip_files] if config[:skip_files].is_a?(Array)
0
+ Regexp.new("^(#{skip_paths.join('|')})")
0
+ end
0
+ not file.match(@mirror_exceptions_regexp)
0
+ end
0
+
0
           # This sets up the default slice-level and app-level structure.
0
           #
0
           # You can create your own structure by implementing setup_structure and
0
           # using the push_path and push_app_paths. By default this setup matches
0
           # what the merb-gen slice generator creates.
0
           def setup_default_structure!
0
- self.push_path(:application, self.root / 'app')
0
- self.push_app_path(:application, Merb.root / 'slices' / self.identifier / 'app')
0
+ self.push_app_path(:root, Merb.root / 'slices' / self.identifier)
0
+
0
+ self.push_path(:application, root_path('app'))
0
+ self.push_app_path(:application, app_dir_for(:root) / 'app')
0
           
0
- [:view, :model, :controller, :helper, :mailer, :part].each do |component|
0
+ app_components.each do |component|
0
               self.push_path(component, dir_for(:application) / "#{component}s")
0
               self.push_app_path(component, app_dir_for(:application) / "#{component}s")
0
             end
0
           
0
- self.push_path(:public, self.root / 'public', nil)
0
- self.push_app_path(:public, Merb.root / 'public' / 'slices' / self.identifier, nil)
0
+ self.push_path(:public, root_path('public'), nil)
0
+ self.push_app_path(:public, Merb.dir_for(:public) / 'slices' / self.identifier, nil)
0
           
0
- [:stylesheet, :javascript, :image].each do |component|
0
+ public_components.each do |component|
0
               self.push_path(component, dir_for(:public) / "#{component}s", nil)
0
               self.push_app_path(component, app_dir_for(:public) / "#{component}s", nil)
0
             end
0
- end
0
+ end
0
+
0
+ private
0
+
0
+ def split_name(name)
0
+ file_name = File.basename(name)
0
+ mres = /^([^\/\.]+)\.(.+)$/i.match(file_name)
0
+ mres.nil? ? [file_name, ''] : [mres[1], mres[2]]
0
+ end
0
         
0
         end
0
         mod
...
7
8
9
10
 
 
 
 
 
 
11
12
13
...
7
8
9
 
10
11
12
13
14
15
16
17
18
0
@@ -7,7 +7,12 @@ if defined?(Merb::Plugins)
0
   Merb::Slices::register(__FILE__)
0
   
0
   # Slice configuration - set this in a before_app_loads callback.
0
- # By default a Slice uses its own layout.
0
+ # By default a Slice uses its own layout, so you can swicht to
0
+ # the main application layout or no layout at all if needed.
0
+ #
0
+ # Configuration options:
0
+ # :layout - the layout to use; defaults to :<%= underscored_name %>
0
+ # :mirror - which path component types to use on copy operations; defaults to all
0
   Merb::Slices::config[:<%= underscored_name %>] = { :layout => :<%= underscored_name %> }
0
   
0
   # All Slice code is expected to be namespaced inside a module
...
15
16
17
18
 
19
20
21
...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
 
 
 
 
42
43
44
...
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
...
15
16
17
 
18
19
20
21
...
28
29
30
 
 
 
 
 
 
 
 
 
 
 
31
32
33
34
35
36
37
38
...
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
0
@@ -15,7 +15,7 @@ namespace :slices do
0
     desc "Setup directories"
0
     task :setup_directories do
0
       puts "Creating directories for host application"
0
- [:application, :view, :model, :controller, :helper, :mailer, :part, :public].each do |type|
0
+ <%= module_name %>.mirrored_components.each do |type|
0
         if File.directory?(<%= module_name %>.dir_for(type))
0
           if !File.directory?(dst_path = <%= module_name %>.app_dir_for(type))
0
             relative_path = dst_path.relative_path_from(Merb.root)
0
@@ -28,17 +28,11 @@ namespace :slices do
0
   
0
     desc "Copy public assets to host application"
0
     task :copy_assets do
0
- puts "Copying assets for <%= module_name %> - do not edit these as the will be overwritten!"
0
- [:image, :javascript, :stylesheet].each do |type|
0
- src_path = <%= module_name %>.dir_for(type)
0
- dst_path = <%= module_name %>.app_dir_for(type)
0
- Dir[src_path / '**/*'].each do |file|
0
- relative_path = file.relative_path_from(src_path)
0
- puts "- installing :#{type} #{relative_path}"
0
- mkdir_p(dst_path / File.dirname(relative_path))
0
- copy_entry(file, dst_path / relative_path, false, false, true)
0
- end
0
- end
0
+ puts "Copying assets for <%= module_name %> - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.mirror_public!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
     end
0
     
0
     desc "Migrate the database"
0
@@ -46,6 +40,52 @@ namespace :slices do
0
       # implement this to perform any database related setup steps
0
     end
0
     
0
+ desc "Freeze <%= module_name %> into your app (only <%= base_name %>/app)"
0
+ task :freeze => [ "freeze:app" ]
0
+
0
+ namespace :freeze do
0
+
0
+ desc "Freezes <%= module_name %> by installing the gem into application/gems using merb-freezer"
0
+ task :gem do
0
+ begin
0
+ Object.const_get(:Freezer).freeze(ENV["GEM"] || "<%= base_name %>", ENV["UPDATE"], ENV["MODE"] || 'rubygems')
0
+ rescue NameError
0
+ puts "! dependency 'merb-freezer' missing"
0
+ end
0
+ end
0
+
0
+ desc "Freezes <%= module_name %> by copying all files from <%= base_name %>/app to your application"
0
+ task :app do
0
+ puts "Copying all <%= base_name %>/app files to your application - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.mirror_app!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
+ end
0
+
0
+ desc "Freeze all views into your application for easy modification"
0
+ task :views do
0
+ puts "Copying all view templates to your application - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.mirror_views!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
+ end
0
+
0
+ desc "Freezes <%= module_name %> as a gem and copies over <%= base_name %>/app"
0
+ task :app_with_gem => [:gem, :app]
0
+
0
+ desc "Freezes <%= module_name %> by unpacking all files into your application"
0
+ task :unpack do
0
+ puts "Unpacking <%= module_name %> files to your application - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.unpack_slice!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
+ end
0
+
0
+ end
0
+
0
     desc "Run slice specs within the host application context"
0
     task :spec => [ "spec:explain", "spec:default" ]
0
     
...
51
52
53
 
 
54
55
 
56
57
58
...
71
72
73
 
 
 
 
74
75
...
51
52
53
54
55
56
 
57
58
59
60
...
73
74
75
76
77
78
79
80
81
0
@@ -51,8 +51,10 @@ describe "<%= module_name %> (module)" do
0
   end
0
   
0
   it "should have a app_dir_for method" do
0
+ root_path = <%= module_name %>.app_dir_for(:root)
0
+ root_path.should == Merb.root / 'slices' / '<%= base_name %>'
0
     app_path = <%= module_name %>.app_dir_for(:application)
0
- app_path.should == Merb.root / 'slices' / '<%= base_name %>' / 'app'
0
+ app_path.should == root_path / 'app'
0
     [:view, :model, :controller, :helper, :mailer, :part].each do |type|
0
       <%= module_name %>.app_dir_for(type).should == app_path / "#{type}s"
0
     end
0
@@ -71,4 +73,8 @@ describe "<%= module_name %> (module)" do
0
     end
0
   end
0
   
0
+ it "should keep a list of path component types to use when copying files" do
0
+ (<%= module_name %>.mirrored_components & <%= module_name %>.slice_paths.keys).length.should == <%= module_name %>.mirrored_components.length
0
+ end
0
+
0
 end
0
\ No newline at end of file
...
41
42
43
44
45
 
 
 
 
46
47
48
49
50
 
51
52
53
...
41
42
43
 
 
44
45
46
47
48
49
50
51
 
52
53
54
55
0
@@ -41,13 +41,15 @@ if defined?(Merb::Plugins)
0
     
0
     # This sets up a thin slice's structure.
0
     def self.setup_default_structure!
0
- self.push_path(:application, self.root, 'application.rb')
0
- self.push_app_path(:application, Merb.root / 'slices' / self.identifier, 'application.rb')
0
+ self.push_app_path(:root, Merb.root / 'slices' / self.identifier)
0
+
0
+ self.push_path(:application, root, 'application.rb')
0
+ self.push_app_path(:application, app_dir_for(:root), 'application.rb')
0
       
0
       self.push_path(:view, dir_for(:application) / "views")
0
       self.push_app_path(:view, app_dir_for(:application) / "views")
0
       
0
- self.push_path(:public, self.root / 'public', nil)
0
+ self.push_path(:public, root_path('public'), nil)
0
       self.push_app_path(:public, Merb.root / 'public' / 'slices' / self.identifier, nil)
0
       
0
       [:stylesheet, :javascript, :image].each do |component|
...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
 
 
 
 
42
43
44
...
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
...
28
29
30
 
 
 
 
 
 
 
 
 
 
 
31
32
33
34
35
36
37
38
...
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
0
@@ -28,17 +28,11 @@ namespace :slices do
0
     
0
     desc "Copy public assets to host application"
0
     task :copy_assets do
0
- puts "Copying assets for <%= module_name %> - do not edit these as the will be overwritten!"
0
- [:image, :javascript, :stylesheet].each do |type|
0
- src_path = <%= module_name %>.dir_for(type)
0
- dst_path = <%= module_name %>.app_dir_for(type)
0
- Dir[src_path / '**/*'].each do |file|
0
- relative_path = file.relative_path_from(src_path)
0
- puts "- installing :#{type} #{relative_path}"
0
- mkdir_p(dst_path / File.dirname(relative_path))
0
- copy_entry(file, dst_path / relative_path, false, false, true)
0
- end
0
- end
0
+ puts "Copying assets for <%= module_name %> - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.mirror_public!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
     end
0
     
0
     desc "Migrate the database"
0
@@ -46,5 +40,51 @@ namespace :slices do
0
       # implement this to perform any database related setup steps
0
     end
0
     
0
+ desc "Freeze <%= module_name %> into your app (only <%= base_name %>/app)"
0
+ task :freeze => [ "freeze:app" ]
0
+
0
+ namespace :freeze do
0
+
0
+ desc "Freezes <%= module_name %> by installing the gem into application/gems using merb-freezer"
0
+ task :gem do
0
+ begin
0
+ Object.const_get(:Freezer).freeze(ENV["GEM"] || "<%= base_name %>", ENV["UPDATE"], ENV["MODE"] || 'rubygems')
0
+ rescue NameError
0
+ puts "! dependency 'merb-freezer' missing"
0
+ end
0
+ end
0
+
0
+ desc "Freezes <%= module_name %> by copying all files from <%= base_name %>/app to your application"
0
+ task :app do
0
+ puts "Copying all <%= base_name %>/app files to your application - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.mirror_app!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
+ end
0
+
0
+ desc "Freeze all views into your application for easy modification"
0
+ task :views do
0
+ puts "Copying all view templates to your application - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.mirror_views!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
+ end
0
+
0
+ desc "Freezes <%= module_name %> as a gem and copies over <%= base_name %>/app"
0
+ task :app_with_gem => [:gem, :app]
0
+
0
+ desc "Freezes <%= module_name %> by unpacking all files into your application"
0
+ task :unpack do
0
+ puts "Unpacking <%= module_name %> files to your application - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.unpack_slice!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
+ end
0
+
0
+ end
0
+
0
   end
0
 end
0
\ No newline at end of file
...
40
41
42
43
44
 
 
 
 
45
46
 
47
48
49
...
40
41
42
 
 
43
44
45
46
47
 
48
49
50
51
0
@@ -40,10 +40,12 @@ if defined?(Merb::Plugins)
0
     
0
     # This sets up a very thin slice's structure.
0
     def self.setup_default_structure!
0
- self.push_path(:application, self.root, 'application.rb')
0
- self.push_app_path(:application, Merb.root / 'slices' / self.identifier, 'application.rb')
0
+ self.push_app_path(:root, Merb.root / 'slices' / self.identifier)
0
+
0
+ self.push_path(:application, root, 'application.rb')
0
+ self.push_app_path(:application, app_dir_for(:root), 'application.rb')
0
             
0
- self.push_path(:public, self.root / 'public', nil)
0
+ self.push_path(:public, root_path('public'), nil)
0
       self.push_app_path(:public, Merb.root / 'public' / 'slices' / self.identifier, nil)
0
       
0
       [:stylesheet, :javascript, :image].each do |component|
...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
 
 
 
 
42
43
44
...
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
...
28
29
30
 
 
 
 
 
 
 
 
 
 
 
31
32
33
34
35
36
37
38
...
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
0
@@ -28,17 +28,11 @@ namespace :slices do
0
     
0
     desc "Copy public assets to host application"
0
     task :copy_assets do
0
- puts "Copying assets for <%= module_name %> - do not edit these as the will be overwritten!"
0
- [:image, :javascript, :stylesheet].each do |type|
0
- src_path = <%= module_name %>.dir_for(type)
0
- dst_path = <%= module_name %>.app_dir_for(type)
0
- Dir[src_path / '**/*'].each do |file|
0
- relative_path = file.relative_path_from(src_path)
0
- puts "- installing :#{type} #{relative_path}"
0
- mkdir_p(dst_path / File.dirname(relative_path))
0
- copy_entry(file, dst_path / relative_path, false, false, true)
0
- end
0
- end
0
+ puts "Copying assets for <%= module_name %> - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.mirror_public!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
     end
0
     
0
     desc "Migrate the database"
0
@@ -46,5 +40,51 @@ namespace :slices do
0
       # implement this to perform any database related setup steps
0
     end
0
     
0
+ desc "Freeze <%= module_name %> into your app (only <%= base_name %>/app)"
0
+ task :freeze => [ "freeze:app" ]
0
+
0
+ namespace :freeze do
0
+
0
+ desc "Freezes <%= module_name %> by installing the gem into application/gems using merb-freezer"
0
+ task :gem do
0
+ begin
0
+ Object.const_get(:Freezer).freeze(ENV["GEM"] || "<%= base_name %>", ENV["UPDATE"], ENV["MODE"] || 'rubygems')
0
+ rescue NameError
0
+ puts "! dependency 'merb-freezer' missing"
0
+ end
0
+ end
0
+
0
+ desc "Freezes <%= module_name %> by copying all files from <%= base_name %>/app to your application"
0
+ task :app do
0
+ puts "Copying all <%= base_name %>/app files to your application - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.mirror_app!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
+ end
0
+
0
+ desc "Freeze all views into your application for easy modification"
0
+ task :views do
0
+ puts "Copying all view templates to your application - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.mirror_views!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
+ end
0
+
0
+ desc "Freezes <%= module_name %> as a gem and copies over <%= base_name %>/app"
0
+ task :app_with_gem => [:gem, :app]
0
+
0
+ desc "Freezes <%= module_name %> by unpacking all files into your application"
0
+ task :unpack do
0
+ puts "Unpacking <%= module_name %> files to your application - resolves any collisions"
0
+ copied, preserved = <%= module_name %>.unpack_slice!
0
+ puts "- no files to copy" if copied.empty? && preserved.empty?
0
+ copied.each { |f| puts "- copied #{f}" }
0
+ preserved.each { |f| puts "! preserved override as #{f}" }
0
+ end
0
+
0
+ end
0
+
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.