caboose-cms 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: baac14246cad522d361a83bef4fc56834e4aa6ec
4
- data.tar.gz: d59419b1a8984e4728df7f301a5e51c3284e5bb9
3
+ metadata.gz: f7fa62eedcbe6c49f9413de0c7122c1d031529c8
4
+ data.tar.gz: 35c06e4da3cbed369eb5520afd5ed6cd04f86cfb
5
5
  SHA512:
6
- metadata.gz: 58d92891b8f85db3a35682cf03140055bd6929e16e6e577263643a88e86f44e6c2d4298feaa677a5c853f9c62e5f71c8bb17530730b90bc5bee4504bc90d6050
7
- data.tar.gz: a3d136234e9b51bb59a8d95e7a1159700a66f929c198a6507717cf21e5c02bcc98f2387f84e3ae3e18ce1d58e9956611476d8362e2f8394a91bbd6f85153254f
6
+ metadata.gz: 6afad2c94f730d41418042307f71c9d083934feb73cf34779f546c9c8374ebad2912cc2cf9a2b3c9512835b5b7cb75ac3291e8c1b03611a243bbac4bfcb491b9
7
+ data.tar.gz: 92493e93f3cca39b2dd45e27a8939969aafd347703fa0e57f7c97740b5d056abfcd5a608701aeb5fc44f8186d1999cb7427e88b25d533cfa8ba533fe495a3b87
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -528,109 +528,164 @@ end
528
528
 
529
529
  namespace :assets do
530
530
 
531
- desc "Precompile assets, upload to S3, then remove locally"
532
- task :purl, [:sitename, :sitename2, :sitename3, :sitename4] => :environment do |t, args|
533
-
534
- sitenames = []
535
- sitenames << args.sitename if !args.sitename.blank?
536
- sitenames << args.sitename2 if !args.sitename2.blank?
537
- sitenames << args.sitename3 if !args.sitename3.blank?
538
- sitenames << args.sitename4 if !args.sitename4.blank?
539
- where = args.sitename.blank? ? "" : "name = '#{args.sitename}'"
540
- where += " OR name = '#{args.sitename2}'" if !args.sitename2.blank?
541
- where += " OR name = '#{args.sitename3}'" if !args.sitename3.blank?
542
- where += " OR name = '#{args.sitename4}'" if !args.sitename4.blank?
543
-
544
- `mv #{Rails.root.join('public', 'assets', 'manifest.yml')} #{Rails.root.join('public', 'manifest1.yml')}`
545
-
546
- puts "Copying site assets into host assets..."
547
- Caboose::Site.where(where).all.each do |site|
548
- site_js = Rails.root.join(Caboose::site_assets_path, site.name, 'js')
549
- site_css = Rails.root.join(Caboose::site_assets_path, site.name, 'css')
550
- site_images = Rails.root.join(Caboose::site_assets_path, site.name, 'images')
551
- site_fonts = Rails.root.join(Caboose::site_assets_path, site.name, 'fonts')
552
-
553
- host_js = Rails.root.join('app', 'assets', 'javascripts' , site.name)
554
- host_css = Rails.root.join('app', 'assets', 'stylesheets' , site.name)
555
- host_images = Rails.root.join('app', 'assets', 'images' , site.name)
556
- host_fonts = Rails.root.join('app', 'assets', 'fonts' , site.name)
531
+ desc "Precompile assets, upload to S3, then remove locally"
532
+ task :purl, [:filename, :force] => :environment do |t, args|
533
+ if args.filename
534
+ dest = "#{Rails.root}/tmp/#{args.filename}"
557
535
 
558
- `mkdir -p #{host_js }` if File.directory?(site_js)
559
- `mkdir -p #{host_css }` if File.directory?(site_css)
560
- `mkdir -p #{host_images }` if File.directory?(site_images)
561
- `mkdir -p #{host_fonts }` if File.directory?(site_fonts)
562
-
563
- `cp -R #{site_js } #{host_js }` if File.directory?(site_js)
564
- `cp -R #{site_css } #{host_css }` if File.directory?(site_css)
565
- `cp -R #{site_images } #{host_images }` if File.directory?(site_images)
566
- `cp -R #{site_fonts } #{host_fonts }` if File.directory?(site_fonts)
567
- end
568
-
569
- puts "Running precompile..."
570
- Rake::Task['assets:precompile'].invoke
571
-
572
- if !sitenames.blank?
573
-
574
- puts "Moving manifest.yml to public > manifest2.yml"
575
- `mv #{Rails.root.join('public', 'assets', 'manifest.yml')} #{Rails.root.join('public', 'manifest2.yml')}`
576
-
577
- new_string = ""
578
-
579
- prefixes = sitenames.map{ |sn| sn + "/"}
580
- prefixes << "caboose/"
581
- prefixes << "col/"
582
- prefixes << "shared/"
583
- prefixes << "ninelite.css"
584
-
585
- File.readlines("#{Rails.root.join('public', 'manifest1.yml')}").each do |line|
586
- if !line.starts_with?(*prefixes)
587
- new_string += (line)
588
- end
589
- end
590
-
591
- File.readlines("#{Rails.root.join('public', 'manifest2.yml')}").each do |line|
592
- if line.starts_with?(*prefixes)
593
- new_string += (line)
594
- end
595
- end
596
-
597
- puts "Writing to public > manifest3.yml"
598
- `touch #{Rails.root.join('public', 'manifest3.yml')}`
599
- File.open("#{Rails.root.join('public', 'manifest3.yml')}", "w") { |f| f.write(new_string)}
600
-
601
- puts "Removing assets from public/assets, but leaving manifest file..."
602
- `mv #{Rails.root.join('public', 'assets', 'sources_manifest.yml')} #{Rails.root.join('public', 'sources_manifest.yml')}`
603
- `rm -rf #{Rails.root.join('public', 'assets')}`
604
- `rm #{Rails.root.join('public', 'manifest1.yml')}`
605
- `rm #{Rails.root.join('public', 'manifest2.yml')}`
606
- `mkdir #{Rails.root.join('public', 'assets')}`
607
- `mv #{Rails.root.join('public', 'manifest3.yml')} #{Rails.root.join('public', 'assets', 'manifest.yml')}`
608
- `mv #{Rails.root.join('public', 'sources_manifest.yml')} #{Rails.root.join('public', 'assets', 'sources_manifest.yml')}`
609
-
610
- else
611
- puts "Removing assets from public/assets, but leaving manifest file..."
612
- `rm #{Rails.root.join('public', 'manifest1.yml')}`
613
- `mv #{Rails.root.join('public', 'assets', 'manifest.yml')} #{Rails.root.join('public', 'manifest.yml')}`
614
- `mv #{Rails.root.join('public', 'assets', 'sources_manifest.yml')} #{Rails.root.join('public', 'sources_manifest.yml')}`
615
- `rm -rf #{Rails.root.join('public', 'assets')}`
616
- `mkdir #{Rails.root.join('public', 'assets')}`
617
- `mv #{Rails.root.join('public', 'manifest.yml')} #{Rails.root.join('public', 'assets', 'manifest.yml')}`
618
- `mv #{Rails.root.join('public', 'sources_manifest.yml')} #{Rails.root.join('public', 'assets', 'sources_manifest.yml')}`
536
+ # Compile the file
537
+ puts "Compiling #{args.filename}..."
538
+ File.write(dest, Uglifier.compile(Rails.application.assets.find_asset(args.filename).to_s))
539
+
540
+ # Copy the file from dest to s3/assets
541
+ puts "Copying #{args.filename} to s3..."
542
+ config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))['production']
543
+ AWS.config({ :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] })
544
+ bucket = AWS::S3::Bucket.new(config['bucket'])
545
+ obj = bucket.objects["assets/#{args.filename}"]
546
+ obj.write(:file => dest, :acl => :public_read)
547
+
548
+ # Remove the temp file
549
+ puts "Cleaning up..."
550
+ `rm -rf #{dest}`
551
+ exit
619
552
  end
553
+
554
+ # Otherwise, precompile all the files
555
+
556
+ # Copy any site assets into the host app assets directory first
557
+ puts "Copying site assets into host assets..."
558
+ copy_site_assets_info_host_assets(args.force)
559
+
560
+ #puts "Running precompile..."
561
+ Rake::Task['assets:precompile'].invoke("--trace")
562
+
563
+ puts "Removing assets from public/assets, but leaving manifest file..."
564
+ str = `ls -l #{Rails.root}/public/assets/.sprockets-manifest-*.json`
565
+ manifest = str.strip.split('/').last
566
+ `mv #{Rails.root.join('public', 'assets', manifest)} #{Rails.root.join('public', manifest)}`
567
+ `rm -rf #{Rails.root.join('public', 'assets')}`
568
+ `mkdir #{Rails.root.join('public', 'assets')}`
569
+ `mv #{Rails.root.join('public', manifest)} #{Rails.root.join('public', 'assets', manifest)}`
570
+
571
+ # Clean up
572
+ puts "Removing site assets from host assets..."
573
+ remove_site_assets_from_host_assets
574
+
575
+ # Upload the block type manifest file
576
+ Rake::Task['assets:upload_assets_manifest'].invoke
577
+
578
+ # Copy non-digest file names to s3
579
+ Rake::Task['assets:upload_nondigest_assets'].invoke
580
+
581
+ end
582
+
583
+ desc "PURL without precompile"
584
+ task :purl_without_precompile => :environment do |t, args|
585
+
586
+ # Copy any site assets into the host app assets directory first
587
+ puts "Copying site assets into host assets..."
588
+ copy_site_assets_info_host_assets(args.force)
620
589
 
590
+ #puts "Running precompile..."
591
+ #Rake::Task['assets:precompile'].invoke("--trace")
592
+
593
+ puts "Removing assets from public/assets, but leaving manifest file..."
594
+ str = `ls -l #{Rails.root}/public/assets/.sprockets-manifest-*.json`
595
+ manifest = str.strip.split('/').last
596
+ `mv #{Rails.root.join('public', 'assets', manifest)} #{Rails.root.join('public', manifest)}`
597
+ `rm -rf #{Rails.root.join('public', 'assets')}`
598
+ `mkdir #{Rails.root.join('public', 'assets')}`
599
+ `mv #{Rails.root.join('public', manifest)} #{Rails.root.join('public', 'assets', manifest)}`
600
+
601
+ # Clean up
621
602
  puts "Removing site assets from host assets..."
622
- Caboose::Site.where(where).all.each do |site|
623
- host_js = Rails.root.join('app', 'assets', 'javascripts' , site.name)
624
- host_css = Rails.root.join('app', 'assets', 'stylesheets' , site.name)
625
- host_images = Rails.root.join('app', 'assets', 'images' , site.name)
626
- host_fonts = Rails.root.join('app', 'assets', 'fonts' , site.name)
603
+ remove_site_assets_from_host_assets
604
+
605
+ end
606
+
607
+ desc "Copy non-digest file names in asset manifest file to s3"
608
+ task :upload_nondigest_assets => :environment do
609
+
610
+ puts "Uploading non-digest files..."
611
+
612
+ str = `ls -l #{Rails.root}/public/assets/.sprockets-manifest-*.json`
613
+ manifest = str.strip.split('/').last
614
+ str = File.read("#{Rails.root}/public/assets/#{manifest}")
615
+ m = JSON.parse(str)
616
+ #ap m
617
+
618
+ config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env]
619
+ s3 = Aws::S3::Client.new(:region => 'us-east-1', :credentials => Aws::Credentials.new(config['access_key_id'], config['secret_access_key']))
627
620
 
628
- `rm -rf #{host_js }`
629
- `rm -rf #{host_css }`
630
- `rm -rf #{host_images }`
631
- `rm -rf #{host_fonts }`
621
+ m['assets'].each do |k,d|
622
+ puts " - Uploading #{k}..."
623
+ begin
624
+ s3.copy_object(
625
+ :copy_source => "#{config['bucket']}/assets/#{d}",
626
+ :bucket => config['bucket'],
627
+ :key => "assets/#{k}"
628
+ #:content_type => content_type,
629
+ #:metadata_directive => 'REPLACE'
630
+ )
631
+ rescue Exception => ex
632
+ puts "- Error uploading #{k} - #{ex.message}"
633
+ end
632
634
  end
633
-
635
+
636
+ #m['files'].each do |k,f|
637
+ # puts " - Uploading #{f['logical_path']}..."
638
+ # s3.copy_object(
639
+ # :copy_source => "#{config['bucket']}/assets/#{k}",
640
+ # :bucket => config['bucket'],
641
+ # :key => "assets/#{f['logical_path']}"
642
+ # #:content_type => content_type,
643
+ # #:metadata_directive => 'REPLACE'
644
+ # )
645
+ #end
646
+
647
+ end
648
+
649
+ desc "Upload a mini version of the asset manifest file to S3"
650
+ task :upload_assets_manifest => :environment do
651
+
652
+ # Find the sprockets manifest file
653
+ str = `ls #{Rails.root}/public/assets/.sprockets-manifest-*.json`
654
+ file = str.strip.split("\n").first.split('/').last
655
+ h = JSON.parse(File.read("#{Rails.root}/public/assets/#{file}"))
656
+ h2 = {}
657
+ h['assets'].each do |k,v|
658
+ arr = k.split('.')
659
+ ext = arr.pop
660
+ filename = arr.join('.')
661
+ h2[k] = v.gsub("#{filename}-",'').gsub(".#{ext}",'')
662
+ end
663
+
664
+ # Create a new digest number
665
+ digest = Caboose.random_string(32)
666
+
667
+ json_str = h2.to_json
668
+ jsonp_str = "Caboose.asset_loader.assets_manifest_callback(#{json_str});"
669
+
670
+ # Write the files locally
671
+ puts " - Writing local file #{Rails.root}/public/assets/.assets-manifest-#{digest}.json..."
672
+ File.open("#{Rails.root}/public/assets/.assets-manifest-#{digest}.json", 'w+') { |f| f.write(json_str) }
673
+ puts " - Writing local file #{Rails.root}/public/assets/.assets-manifest-#{digest}.js..."
674
+ File.open("#{Rails.root}/public/assets/.assets-manifest-#{digest}.js", 'w+') { |f| f.write(jsonp_str) }
675
+
676
+ # Upload to S3
677
+ config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env]
678
+ s3 = Aws::S3::Client.new(:region => 'us-east-1', :credentials => Aws::Credentials.new(config['access_key_id'], config['secret_access_key']))
679
+ puts " - Uploading .assets-manifest-#{digest}.json..."
680
+ s3.put_object(:body => json_str , :bucket => config['bucket'], :key => "assets/.assets-manifest-#{digest}.json")
681
+ puts " - Uploading .assets-manifest-#{digest}.js..."
682
+ s3.put_object(:body => jsonp_str , :bucket => config['bucket'], :key => "assets/.assets-manifest-#{digest}.js")
683
+ end
684
+
685
+ desc "Force Purl"
686
+ task :purl_force => :environment do
687
+ puts "Running precompile..."
688
+ Rake::Task['assets:purl'].invoke(nil, true)
634
689
  end
635
690
 
636
691
  desc "Create .gz versions of assets"
@@ -671,6 +726,58 @@ namespace :assets do
671
726
  i = i + 1
672
727
  end
673
728
  end
674
- end
729
+ end
730
+
731
+ def copy_site_assets_info_host_assets(force)
732
+ Caboose::Site.all.each do |site|
733
+ site_js = Rails.root.join(Caboose::site_assets_path, site.name, 'js')
734
+ site_css = Rails.root.join(Caboose::site_assets_path, site.name, 'css')
735
+ site_images = Rails.root.join(Caboose::site_assets_path, site.name, 'images')
736
+ site_fonts = Rails.root.join(Caboose::site_assets_path, site.name, 'fonts')
737
+
738
+ host_js = Rails.root.join('app', 'assets', 'javascripts' , site.name)
739
+ host_css = Rails.root.join('app', 'assets', 'stylesheets' , site.name)
740
+ host_images = Rails.root.join('app', 'assets', 'images' , site.name)
741
+ host_fonts = Rails.root.join('app', 'assets', 'fonts' , site.name)
742
+
743
+ # Check to see if the host folders already exist (could have been from a previous failed purl)
744
+ abort "Error: Both #{host_js } and #{site_js } exist. Please remove one or the other before purling." if !force && File.exists?(host_js)
745
+ abort "Error: Both #{host_css } and #{site_css } exist. Please remove one or the other before purling." if !force && File.exists?(host_css)
746
+ abort "Error: Both #{host_images } and #{site_images } exist. Please remove one or the other before purling." if !force && File.exists?(host_images)
747
+ abort "Error: Both #{host_fonts } and #{site_fonts } exist. Please remove one or the other before purling." if !force && File.exists?(host_fonts)
748
+
749
+ if force
750
+ `rm -rf #{host_js }` if File.exists?(host_js)
751
+ `rm -rf #{host_css }` if File.exists?(host_css)
752
+ `rm -rf #{host_images }` if File.exists?(host_images)
753
+ `rm -rf #{host_fonts }` if File.exists?(host_fonts)
754
+ end
755
+
756
+ `mkdir -p #{host_js }` if File.directory?(site_js)
757
+ `mkdir -p #{host_css }` if File.directory?(site_css)
758
+ `mkdir -p #{host_images }` if File.directory?(site_images)
759
+ `mkdir -p #{host_fonts }` if File.directory?(site_fonts)
760
+
761
+ `cp -R #{site_js } #{host_js }` if File.directory?(site_js)
762
+ `cp -R #{site_css } #{host_css }` if File.directory?(site_css)
763
+ `cp -R #{site_images } #{host_images }` if File.directory?(site_images)
764
+ `cp -R #{site_fonts } #{host_fonts }` if File.directory?(site_fonts)
765
+ end
766
+ end
767
+
768
+ def remove_site_assets_from_host_assets
769
+ Caboose::Site.all.each do |site|
770
+
771
+ host_js = Rails.root.join('app', 'assets', 'javascripts' , Shellwords.escape(site.name))
772
+ host_css = Rails.root.join('app', 'assets', 'stylesheets' , Shellwords.escape(site.name))
773
+ host_images = Rails.root.join('app', 'assets', 'images' , Shellwords.escape(site.name))
774
+ host_fonts = Rails.root.join('app', 'assets', 'fonts' , Shellwords.escape(site.name))
775
+
776
+ `rm -rf #{host_js }`
777
+ `rm -rf #{host_css }`
778
+ `rm -rf #{host_images }`
779
+ `rm -rf #{host_fonts }`
780
+ end
781
+ end
675
782
 
676
783
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry