slight_assets 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ require 'rbconfig'
2
+
3
+ module SlightAssets
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+
6
+ def generate
7
+ copy_file "config/assets.yml", "config/assets.yml"
8
+ copy_file "config/initializers/assets.rb", "config/initializers/assets.rb"
9
+ end
10
+
11
+ def self.gem_root
12
+ File.expand_path("../../../../../", __FILE__)
13
+ end
14
+
15
+ def self.source_root
16
+ File.join(gem_root, 'templates/install')
17
+ end
18
+
19
+ end
20
+ end
@@ -41,6 +41,15 @@ namespace :asset do
41
41
  end
42
42
  @css_list
43
43
  end
44
+ def mime_type_title_of(path)
45
+ if image_mime_type(path)
46
+ "Image"
47
+ elsif font_mime_type(path)
48
+ "Font"
49
+ else
50
+ "Media"
51
+ end
52
+ end
44
53
  end
45
54
  end
46
55
 
@@ -97,7 +106,7 @@ namespace :asset do
97
106
  puts "=" * 80
98
107
  writer.image_report.each_pair do |image_file, report|
99
108
  refs = report[:found_in].size
100
- puts "Image: #{image_file[(Rails.public_path.size)..-1]} (#{"\033[1;31m" unless refs == 1}#{refs} occurrence#{"s" unless refs == 1}\033[0m)"
109
+ puts "#{writer.mime_type_title_of(image_file)}: #{image_file[(Rails.public_path.size)..-1]} (#{"\033[1;31m" unless refs == 1}#{refs} occurrence#{"s" unless refs == 1}\033[0m)"
101
110
  report[:found_in].each_pair do |css_file, count|
102
111
  mode = report[:exists] ? (report[:embeddable] && count == 1 ? "embedded" : "\033[0;33mnot embedded\033[0m") : "\033[0;31mnot found\033[0m"
103
112
  puts " found in #{css_file[(Rails.public_path.size)..-1]} (#{count} ref#{"s" unless count == 1}, #{mode})"
@@ -52,6 +52,6 @@ module SlightAssets
52
52
  end
53
53
 
54
54
  Cfg = Config.new
55
- Cfg.load_config File.expand_path(File.join(*%w[.. settings default_config.yml]), __FILE__)
55
+ Cfg.load_config File.expand_path(File.join(*%w[.. .. .. templates install config assets.yml]), __FILE__)
56
56
  Cfg.load_config ::Rails.root.join(*%w[config assets.yml]) if defined?(::Rails)
57
57
  end
@@ -75,7 +75,7 @@ module SlightAssets
75
75
  end
76
76
  else
77
77
  image_file_path = asset_expand_path(image_path, file_path)
78
- if (mt = image_mime_type(image_path)) &&
78
+ if (mt = image_mime_type(image_path) || file_url.nil? && font_mime_type(image_path)) &&
79
79
  (encode64 = encoded_file_contents(image_file_path, file_path))
80
80
  if image_contents[image_file_path].nil?
81
81
  part_name = "img#{multipart.size}_#{File.basename(image_file_path)}"
@@ -152,6 +152,19 @@ module SlightAssets
152
152
  end
153
153
  module_function :image_mime_type
154
154
 
155
+ def font_mime_type(path)
156
+ return if path !~ /\.([^\.]+)$/
157
+ case $1.downcase.to_sym
158
+ when :ttf
159
+ "font/truetype"
160
+ when :otf
161
+ "font/opentype"
162
+ when :woff
163
+ "font/woff"
164
+ end
165
+ end
166
+ module_function :font_mime_type
167
+
155
168
  def encoded_file_contents(file_path, css_file_path = nil)
156
169
  if css_file_path && is_rake?
157
170
  @image_report[file_path] ||= {:found_in => {}}
@@ -1,6 +1,6 @@
1
1
  module SlightAssets
2
2
  version = nil
3
3
  version = $1 if ::File.expand_path('../..', __FILE__) =~ /\/slight_assets-(\d[\w\.]+)/
4
- version = ::StepUp::Driver::Git.new.last_version_tag if version.nil? && ::File.exists?(::File.expand_path('../../../.git', __FILE__))
4
+ version = ::StepUp::Driver::Git.new.last_version_tag rescue "v0.0.0" if version.nil? && ::File.exists?(::File.expand_path('../../../.git', __FILE__))
5
5
  VERSION = version.gsub(/^v?([^\+]+)\+?\d*$/, '\1')
6
6
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slight_assets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
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
  - Marcelo Manzan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-20 00:00:00 -03:00
18
+ date: 2011-07-14 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -103,13 +103,13 @@ extra_rdoc_files: []
103
103
 
104
104
  files:
105
105
  - generators/slight_assets/slight_assets_generator.rb
106
+ - lib/generators/slight_assets/install/install_generator.rb
106
107
  - lib/slight_assets.rb
107
108
  - lib/slight_assets/base.rb
108
109
  - lib/slight_assets/js_reducer.rb
109
110
  - lib/slight_assets/rails.rb
110
111
  - lib/slight_assets/rake_tasks.rb
111
112
  - lib/slight_assets/settings.rb
112
- - lib/slight_assets/settings/default_config.yml
113
113
  - lib/slight_assets/util.rb
114
114
  - lib/slight_assets/version.rb
115
115
  - templates/install/config/assets.yml
@@ -1,43 +0,0 @@
1
- slight_asset: &slight_asset
2
-
3
- # Maximum embedded file size
4
- # The limit file size to decide whether or not to embed
5
- # Must be less than or equal to "32kB"
6
- maximum_embedded_file_size: "32kB"
7
-
8
- # Scope of assets to minify in batch process (rake).
9
- # The prefix "-" indicates the files to exclude from minifying.
10
- # Keep in mind that the sequence matters.
11
- minify_assets:
12
- - **/*.js
13
- - -**/ckeditor/**/*.js
14
- - **/*.css
15
- # in the end, the masks below will be used for cleaning (even if omitted).
16
- - -**/*.min.js
17
- - -**/*.min.css
18
-
19
- # Absolute MHTML base href (Optional)
20
- # If present, the CSS images that was referenced twice or more
21
- # will be embedded inside a MHTML block
22
- #mhtml_base_href: "http://localhost:3000"
23
-
24
- # JavaScript Reducer (Optional)
25
- # This mode enables obfuscation for JavaScript compression, reducing
26
- # even more the file size.
27
- # Sets the JavaScript reduce mode:
28
- # "rake" - Reduce only when executing rake task (asset:compress:js)
29
- # true - Reduce at runtime or when executing rake
30
- # false - Don't reduce JavaScript's
31
- js_reducer: false
32
-
33
- development:
34
- slight_asset:
35
- <<: *slight_asset
36
-
37
- test:
38
- slight_asset:
39
- <<: *slight_asset
40
-
41
- production:
42
- slight_asset:
43
- <<: *slight_asset