asset_sweeper 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -3,7 +3,7 @@ README.rdoc
3
3
  Rakefile
4
4
  init.rb
5
5
  lib/asset_sweeper.rb
6
- nbproject/private/private.xml
6
+ nbproject/private/private.properties
7
7
  nbproject/project.properties
8
8
  nbproject/project.xml
9
9
  tasks/asset_sweeper.rake
@@ -1,27 +1,59 @@
1
1
  = Asset Sweeper
2
2
 
3
- This plugin is for cleaning up rails application by removing unused images from application.
3
+ This gem is for cleaning up rails application by removing unused images, listing unused stylesheets and javascripts from application
4
+ also with help of this you can list down missing images called from stylesheets which causes page loading slower.
4
5
 
5
6
  == Install
6
7
 
7
- ruby script/plugin install git@github.com:anilg/asset_sweeper.git
8
+ gem install asset_sweeper
9
+
10
+ It's also available in plugin form. You can install a plugin by following command.
11
+
12
+ ruby script/plugin install git://github.com/anilg/asset_sweeper.git
8
13
 
9
14
 
10
15
  == Usage
11
16
 
12
17
  Run rake task
13
18
 
14
- rake asset_sweeper:sweep -t
19
+ rake asset_sweeper:remove_unused_images -t
20
+
21
+ This rake task scans for all images (in "public/images" folder) (.jpg, .png, .gif) in application (rb, html, css, js files)
22
+ and create a folder named unused in applications root directory and move images which are not used in application.
23
+
24
+ But if image name is constructed dynamically in code this script will list such images.
25
+
26
+
27
+ rake asset_sweeper:list_unused_stylesheets -t
28
+
29
+ This rake task scans for all stylesheet names present in "public/stylesheets/*" folder in application (html files i.e. views)
30
+ and list down as ununsed if it doesnt get any stylesheet being included in any of views in application.
31
+
32
+ But this rake task also lists all third party stylesheets as unused as it doesnt get
33
+ their names in views. Also if stylesheets names are being constructed programatically
34
+ even those stylesheets will be listed as ununsed ones. So before actually deleting
35
+ stylesheets you have verify manually whether that is being actually used or not.
36
+
37
+
38
+ rake asset_sweeper:list_unused_javascripts -t
39
+
40
+ This rake task scans for all javascripts names present in "public/javascripts/*" folder in application (html files i.e. views)
41
+ and list down as ununsed if it doesnt get any stylesheet being included in any of views in application.
42
+
43
+ But this rake task also lists all third party javascripts as unused as it doesnt get
44
+ their names in views. Also if javascripts names are being constructed programatically
45
+ even those javascripts will be listed as ununsed ones. So before actually deleting
46
+ javascripts you have verify manually whether that is being actually used or not.
15
47
 
16
- This rake task scans for all images (.jpg, .png, .gif) in application (html, css, js files)
17
- and create a folder named unused in applications root directory and list all images which are not used in application.
18
- But if image name is constructed dynamically in code this script will list such images also
19
- and images in assets/attachments like folder will be listed so you need to verify images in that folder before deleting.
48
+ rake asset_sweeper:find_missing_images -t
20
49
 
50
+ This rake task will scan through all stylesheets present in application and
51
+ verifies whether called images are present in application and list down all images path
52
+ which are not present in application.
21
53
 
22
54
  == License
23
55
 
24
- Copyright (c) 2008 Ryan Bates
56
+ Copyright (c) 2011 Anil Galve
25
57
 
26
58
  Permission is hereby granted, free of charge, to any person obtaining
27
59
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -2,8 +2,8 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('asset_sweeper', '0.1.0') do |p|
6
- p.description = "Cleans up application by removing unused images."
5
+ Echoe.new('asset_sweeper', '0.2.0') do |p|
6
+ p.description = "This gem is for cleaning up rails application by removing unused images, listing unused stylesheets and javascripts from application also with help of this you can list down missing images called from stylesheets which causes page loading slower."
7
7
  p.url = "http://github.com/anilg/asset_sweeper"
8
8
  p.author = "Anil Galve"
9
9
  p.email = "galve.anil@gmail.com"
@@ -2,21 +2,21 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "asset_sweeper"
5
- s.version = "0.1.0"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Anil Galve"]
9
- s.date = "2011-09-14"
10
- s.description = "Cleans up application by removing unused images."
9
+ s.date = "2011-12-11"
10
+ s.description = "This gem is for cleaning up rails application by removing unused images, listing unused stylesheets and javascripts from application also with help of this you can list down missing images called from stylesheets which causes page loading slower."
11
11
  s.email = "galve.anil@gmail.com"
12
12
  s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/asset_sweeper.rb", "tasks/asset_sweeper.rake"]
13
- s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "init.rb", "lib/asset_sweeper.rb", "nbproject/private/private.xml", "nbproject/project.properties", "nbproject/project.xml", "tasks/asset_sweeper.rake", "Manifest", "asset_sweeper.gemspec"]
13
+ s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "init.rb", "lib/asset_sweeper.rb", "nbproject/private/private.properties", "nbproject/project.properties", "nbproject/project.xml", "tasks/asset_sweeper.rake", "Manifest", "asset_sweeper.gemspec"]
14
14
  s.homepage = "http://github.com/anilg/asset_sweeper"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Asset_sweeper", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "asset_sweeper"
18
18
  s.rubygems_version = "1.8.10"
19
- s.summary = "Cleans up application by removing unused images."
19
+ s.summary = "This gem is for cleaning up rails application by removing unused images, listing unused stylesheets and javascripts from application also with help of this you can list down missing images called from stylesheets which causes page loading slower."
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  s.specification_version = 3
@@ -0,0 +1,2 @@
1
+ file.reference.asset_sweeper-lib=/home/anil/projects/asset_sweeper/lib
2
+ file.reference.asset_sweeper-tasks=/home/anil/projects/asset_sweeper/tasks
@@ -1,3 +1,7 @@
1
+ file.reference.asset_sweeper-lib=lib
2
+ file.reference.asset_sweeper-tasks=tasks
1
3
  main.file=
2
- platform.active=JRuby
4
+ platform.active=Ruby
3
5
  source.encoding=UTF-8
6
+ src.dir=${file.reference.asset_sweeper-lib}
7
+ tasks.dir=${file.reference.asset_sweeper-tasks}
@@ -3,8 +3,11 @@
3
3
  <type>org.netbeans.modules.ruby.rubyproject</type>
4
4
  <configuration>
5
5
  <data xmlns="http://www.netbeans.org/ns/ruby-project/1">
6
- <name>sweeper</name>
7
- <source-roots/>
6
+ <name>asset_sweeper</name>
7
+ <source-roots>
8
+ <root id="src.dir"/>
9
+ <root id="tasks.dir"/>
10
+ </source-roots>
8
11
  <test-roots/>
9
12
  </data>
10
13
  </configuration>
@@ -1,10 +1,10 @@
1
1
  # Author Anil
2
2
  # Task to remove unused images
3
3
  namespace :asset_sweeper do
4
- task :sweep => :environment do
4
+ task :remove_unused_images => :environment do
5
5
  require "fileutils"
6
- img=Dir.glob("**/*.jpg")+Dir.glob("**/*.png")+Dir.glob("**/*.gif")
7
- data=Dir.glob("**/*.htm*")+Dir.glob("**/*.css")+Dir.glob("**/*.js")
6
+ img=Dir.glob("**/public/images/**/*.jpg")+Dir.glob("**/public/images/**/*.png")+Dir.glob("**/public/images/**/*.gif")
7
+ data=Dir.glob("**/*.htm*")+Dir.glob("**/*.css")+Dir.glob("**/*.js")+Dir.glob("**/*.rb")
8
8
  puts img.length.to_s+" images found & "+data.length.to_s+" files found to search against"
9
9
  content=""
10
10
  data.each do |f|
@@ -13,9 +13,73 @@ namespace :asset_sweeper do
13
13
  img.each do |m|
14
14
  if not content=~ Regexp.new("\\b"+File.basename(m)+"\\b")
15
15
  FileUtils.mkdir_p "unused/"+File.dirname(m)
16
- FileUtils.cp m,"unused/"+m
16
+ FileUtils.mv m,"unused/"+m
17
17
  puts "Image "+m+" moved to unused/"+File.dirname(m)+" folder"
18
18
  end
19
19
  end
20
20
  end
21
+
22
+ task :list_unused_stylesheets => :environment do
23
+ stylesheets = Dir.glob("**/*.css")
24
+ data=Dir.glob("**/*.htm*")
25
+ content=""
26
+ data.each do |f|
27
+ content+=File.open(f, 'r').read
28
+ end
29
+ p"=========================================================="
30
+ p'Following stylesheets are not called from any view in application. Hence look like unused ones. Please verity and delete if they are not being used actually.'
31
+ stylesheets.each do |s|
32
+ if not content=~ Regexp.new("\\b"+File.basename(s)+"\\b")
33
+ p"#{s}"
34
+ end
35
+ end
36
+ p"=========================================================="
37
+ end
38
+
39
+ task :list_unused_javascripts => :environment do
40
+ javascripts = Dir.glob("**/*.js")
41
+ data=Dir.glob("**/*.htm*")
42
+ content=""
43
+ data.each do |f|
44
+ content+=File.open(f, 'r').read
45
+ end
46
+ p"=========================================================="
47
+ p'Following javascripts are not called from any view in application. Hence look like unused ones. Please verity and delete if they are not being used actually.'
48
+ javascripts.each do |j|
49
+ if not content=~ Regexp.new("\\b"+File.basename(j)+"\\b")
50
+ p"#{j}"
51
+ end
52
+ end
53
+ p"=========================================================="
54
+ end
55
+
56
+ task :find_missing_images => :environment do
57
+ image_paths = []
58
+ data = Dir.glob("**/*.css")
59
+ content=""
60
+ data.each do |f|
61
+ content+=File.open(f, 'r').read
62
+ end
63
+ next_image_path = true
64
+ while next_image_path
65
+ arr = content.split('url(')
66
+ arr.delete_at(0)
67
+ content = arr.join('url(')
68
+ if arr.size > 1
69
+ arr = content.split(')')
70
+ image_paths << arr[0]
71
+ arr.delete_at(0)
72
+ content = arr.join(')')
73
+ else
74
+ next_image_path = false
75
+ end
76
+ end
77
+ image_paths.each do |path|
78
+ path = path.gsub('../','').gsub("'","").gsub('"','').gsub('./','').gsub('//','')
79
+ path = path.starts_with?('/') ? 'public'+path : 'public/'+path
80
+ unless File.exist?(path)
81
+ p"image is missing at #{path}"
82
+ end
83
+ end
84
+ end
21
85
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_sweeper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Anil Galve
@@ -15,10 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-14 00:00:00 Z
18
+ date: 2011-12-11 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
- description: Cleans up application by removing unused images.
21
+ description: This gem is for cleaning up rails application by removing unused images, listing unused stylesheets and javascripts from application also with help of this you can list down missing images called from stylesheets which causes page loading slower.
22
22
  email: galve.anil@gmail.com
23
23
  executables: []
24
24
 
@@ -35,7 +35,7 @@ files:
35
35
  - Rakefile
36
36
  - init.rb
37
37
  - lib/asset_sweeper.rb
38
- - nbproject/private/private.xml
38
+ - nbproject/private/private.properties
39
39
  - nbproject/project.properties
40
40
  - nbproject/project.xml
41
41
  - tasks/asset_sweeper.rake
@@ -79,6 +79,6 @@ rubyforge_project: asset_sweeper
79
79
  rubygems_version: 1.8.10
80
80
  signing_key:
81
81
  specification_version: 3
82
- summary: Cleans up application by removing unused images.
82
+ summary: This gem is for cleaning up rails application by removing unused images, listing unused stylesheets and javascripts from application also with help of this you can list down missing images called from stylesheets which causes page loading slower.
83
83
  test_files: []
84
84
 
@@ -1,4 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project-private xmlns="http://www.netbeans.org/ns/project-private/1">
3
- <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
4
- </project-private>