rad_assets 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,5 +7,5 @@ project(
7
7
  summary: "Assets for Rad Framework",
8
8
 
9
9
  author: "Alexey Petrushin",
10
- homepage: "http://github.com/alexeypetrushin/rad_assets"
10
+ homepage: "http://github.com/alexeypetrushin/rad_assets"
11
11
  )
@@ -1,4 +1,4 @@
1
1
  rad.register :assets, depends_on: :environment do
2
- require 'rad/assets/require'
2
+ require 'rad/assets/require'
3
3
  Rad::Assets.new
4
4
  end
@@ -1,42 +1,42 @@
1
- class Rad::Assets
2
- inject logger: :logger, environment: :environment
3
-
4
- #
1
+ class Rad::Assets
2
+ inject logger: :logger, environment: :environment
3
+
4
+ #
5
5
  # Config
6
- #
6
+ #
7
7
  attr_accessor :static_path_prefix
8
8
  # attr_required :static_path_prefix
9
-
10
-
11
- def resolve_http_paths http_path
9
+
10
+
11
+ def resolve_http_paths http_path
12
12
  resource = pack? ? Rad::Assets::PackagedResource.new(http_path) : Rad::Assets::Resource.new(http_path)
13
13
  resource.resolved_http_paths
14
14
  end
15
15
  cache_method_with_params_in_production :resolve_http_paths
16
-
16
+
17
17
  def paths
18
18
  @paths ||= []
19
19
  end
20
-
20
+
21
21
  def copy_to_public!
22
22
  paths.each do |path|
23
23
  path = path.to_dir
24
24
  raise "asset path should exist (#{path})!" unless path.exist?
25
- raise "asset path should be a directory (#{path})!" unless path.dir?
26
- path.copy_to! "#{rad.http.public_path}#{static_path_prefix}".to_dir
25
+ raise "asset path should be a directory (#{path})!" unless path.dir?
26
+ path.copy_to "#{rad.http.public_path}#{static_path_prefix}".to_dir
27
27
  end
28
28
  end
29
-
30
- def fs_path http_path
29
+
30
+ def fs_path http_path
31
31
  http_path.must =~ /^\//
32
32
  environment.find_file http_path, paths
33
33
  end
34
-
34
+
35
35
  def asset? http_path
36
36
  !!((http_path =~ /^\//) and fs_path(http_path))
37
37
  end
38
38
  cache_method_with_params_in_production :asset?
39
-
39
+
40
40
  protected
41
41
  def pack?
42
42
  rad.production?
@@ -5,7 +5,7 @@ class Rad::Assets::Compressor
5
5
  # `ruby #{jsmin} <#{path} >#{packaged_path} \n`
6
6
  # },
7
7
  css: -> path, packaged_path {
8
- data = path.to_file.read
8
+ data = path.to_file.read
9
9
  data.gsub!(/\s+/, " ") # collapse space
10
10
  data.gsub!(/\/\*(.*?)\*\//, "") # remove comments - caution, might want to remove this if using css hacks
11
11
  data.gsub!(/\} /, "}\n") # add line breaks
@@ -15,7 +15,7 @@ class Rad::Assets::Compressor
15
15
  packaged_path.to_file.write data
16
16
  }
17
17
  }
18
-
18
+
19
19
  def self.pack! path
20
20
  file = path.to_file.must.exist
21
21
  packager = COMPRESSORS[file.extension.to_sym]
@@ -1,4 +1,4 @@
1
- if respond_to? :fake_gem
1
+ if respond_to? :fake_gem
2
2
  fake_gem 'rad_core'
3
3
  fake_gem 'vfs'
4
4
  end
@@ -1,9 +1,9 @@
1
- class Rad::Assets::PackagedResource < Rad::Assets::Resource
1
+ class Rad::Assets::PackagedResource < Rad::Assets::Resource
2
2
  PACKAGED_POSTFIX = 'packaged'
3
-
3
+
4
4
  def resolved_http_paths
5
5
  http_path = "#{assets.static_path_prefix}#{self.http_path}"
6
-
6
+
7
7
  fs_path = self.fs_path http_path
8
8
  http_paths = []
9
9
  fs_path.to_file.read.scan ASSET_REQUIRE_RE do |dependency_http_path|
@@ -11,40 +11,40 @@ class Rad::Assets::PackagedResource < Rad::Assets::Resource
11
11
  http_paths.push *res.resolved_http_paths
12
12
  end
13
13
  http_paths << http_path
14
-
15
- fs_paths = http_paths.collect{|path| self.fs_path path}
14
+
15
+ fs_paths = http_paths.collect{|path| self.fs_path path}
16
16
  packaged_file = self.fs_path(packaged_http_path(http_path)).to_file
17
-
17
+
18
18
  rebuild = (
19
19
  !packaged_file.exist? or
20
20
  fs_paths.any?{|path| path.to_file.updated_at > packaged_file.updated_at}
21
21
  )
22
22
  rebuild! packaged_file, fs_paths if rebuild
23
-
23
+
24
24
  [packaged_http_path(http_path)]
25
25
  end
26
-
26
+
27
27
  protected
28
28
  def fs_path http_path
29
29
  "#{rad.http.public_path}#{http_path}"
30
30
  end
31
-
31
+
32
32
  def packaged_http_path http_path
33
33
  extension = File.extname(http_path)
34
34
  base = http_path[0..(http_path.size - extension.size - 1)]
35
35
  "#{base}.packaged#{extension}"
36
36
  end
37
-
38
- def rebuild! packaged_file, fs_paths
37
+
38
+ def rebuild! packaged_file, fs_paths
39
39
  # merging
40
- packaged_file.write! do |writer|
40
+ packaged_file.write do |writer|
41
41
  fs_paths.each do |path|
42
- path.to_file.read do |buff|
43
- writer.call buff
42
+ path.to_file.read do |buff|
43
+ writer.write buff
44
44
  end
45
45
  end
46
46
  end
47
-
47
+
48
48
  # packing
49
49
  Rad::Assets::Compressor.pack! packaged_file.path
50
50
  end
@@ -1,9 +1,9 @@
1
- class Rad::Assets::Resource
1
+ class Rad::Assets::Resource
2
2
  attr_reader :http_path
3
3
  inject assets: :assets
4
-
4
+
5
5
  ASSET_REQUIRE_RE = /rad\.assets\.require[ \t]+['"]([a-zA-Z0-9_\-\.\/]+)['"]/
6
-
6
+
7
7
  def initialize http_path
8
8
  raise "resources path should be absolute (#{http_path})!" unless http_path =~ /^\//
9
9
  @http_path = http_path
@@ -5,8 +5,8 @@ class Rad::Assets::StaticFiles < Rack::File
5
5
 
6
6
  def call(env)
7
7
  path = env["PATH_INFO"]
8
-
9
- if path != '/' and (!@filter or (@filter and @filter =~ path)) and (resolved_path = find_file(path))
8
+
9
+ if path != '/' and (!@filter or (@filter and @filter =~ path)) and (resolved_path = find_file(path))
10
10
  @path = resolved_path
11
11
  serving(env)
12
12
  else
@@ -16,13 +16,16 @@ class Rad::Assets::StaticFiles < Rack::File
16
16
 
17
17
  protected
18
18
  inject assets: :assets
19
-
19
+
20
20
  def find_file http_path
21
- if rad.production? and rad.http.public_path?
21
+ http_path = http_path.url_unescape
22
+ if rad.http.public_path?
22
23
  fs_path = "#{rad.http.public_path}#{http_path}"
23
- fs_path if fs_path.to_file.exist?
24
- else
25
- http_path = http_path.sub rad.assets.static_path_prefix, ''
24
+ return fs_path if fs_path.to_file.exist?
25
+ end
26
+
27
+ if rad.development?
28
+ http_path = http_path.sub rad.assets.static_path_prefix, ''
26
29
  fs_path = assets.fs_path http_path
27
30
  fs_path.sub rad.http.public_path, '' if fs_path
28
31
  end
@@ -10,7 +10,7 @@ module Rad::Assets::ViewHelper
10
10
  end
11
11
  resolved_http_paths
12
12
  end
13
-
13
+
14
14
  def stylesheet_link_tag *a
15
15
  super(*packaged_assets(*a))
16
16
  end
@@ -1,15 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Assets' do
4
- the_spec_dir = with_tmp_spec_dir
4
+ the_spec_dir = with_tmp_spec_dir
5
5
  with_load_path(
6
6
  "#{the_spec_dir}/app/lib",
7
7
  "#{the_spec_dir}/plugin_a/lib",
8
8
  "#{the_spec_dir}/plugin_b/lib",
9
9
  )
10
-
10
+
11
11
  inject assets: :assets
12
-
12
+
13
13
  before do
14
14
  rad.stub!(:runtime_path).and_return("#{spec_dir}/app/runtime")
15
15
  load "app/init.rb"
@@ -3,41 +3,41 @@ require 'spec_helper'
3
3
  describe 'Resources' do
4
4
  with_tmp_spec_dir
5
5
  inject assets: :assets
6
-
6
+
7
7
  describe "development" do
8
8
  before do
9
9
  assets.stub!(:fs_path){|http_path| "#{spec_dir}/development#{http_path}"}
10
10
  assets.stub!(:pack?).and_return(false)
11
11
  end
12
-
13
- it "resolve_http_paths" do
12
+
13
+ it "resolve_http_paths" do
14
14
  assets.resolve_http_paths('/app.js').should == %w(/static/vendor/jquery.js /static/lib/tools.js /static/app.js)
15
15
  end
16
16
  end
17
-
17
+
18
18
  describe "production" do
19
19
  before do
20
20
  rad.http.stub!(:public_path).and_return("#{spec_dir}/production/public")
21
21
  assets.stub!(:pack?).and_return(true)
22
22
  @static_dir = "#{spec_dir}/production/public/static"
23
23
  end
24
-
24
+
25
25
  it "resolve_http_paths" do
26
26
  assets.resolve_http_paths('/app.js').should == %w(/static/app.packaged.js)
27
-
27
+
28
28
  packaged_file = "#{@static_dir}/app.packaged.js".to_file
29
29
  packaged_file.should exist
30
30
  packaged_file.read.should =~ /jQuery.*Tools.*App/m
31
-
31
+
32
32
  "#{@static_dir}/lib/tools.packaged.js".to_file.should exist
33
33
  "#{@static_dir}/vendor/jquery.packaged.js".to_file.should exist
34
34
  end
35
-
35
+
36
36
  it "should create new packed version if sources are updated" do
37
37
  assets.resolve_http_paths('/app.js').should == %w(/static/app.packaged.js)
38
38
  packaged_file = "#{@static_dir}/app.packaged.js".to_file
39
39
  packaged_file.read.should =~ /jQuery.*Tools.*App/m
40
-
40
+
41
41
  sleep 1.1 # file system can't notice smaller difference in file update time
42
42
  "#{@static_dir}/vendor/jquery.js".to_file.write "newQuery"
43
43
  assets.resolve_http_paths('/app.js').should == %w(/static/app.packaged.js)
metadata CHANGED
@@ -1,28 +1,22 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rad_assets
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.8
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Alexey Petrushin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-08-08 00:00:00 +04:00
14
- default_executable:
12
+ date: 2011-09-22 00:00:00.000000000Z
15
13
  dependencies: []
16
-
17
14
  description:
18
15
  email:
19
16
  executables: []
20
-
21
17
  extensions: []
22
-
23
18
  extra_rdoc_files: []
24
-
25
- files:
19
+ files:
26
20
  - Rakefile
27
21
  - readme.md
28
22
  - lib/components/assets.rb
@@ -53,33 +47,28 @@ files:
53
47
  - spec/resources_spec/production/public/static/vendor/jquery.js
54
48
  - spec/resources_spec.rb
55
49
  - spec/spec_helper.rb
56
- has_rdoc: true
57
50
  homepage: http://github.com/alexeypetrushin/rad_assets
58
51
  licenses: []
59
-
60
52
  post_install_message:
61
53
  rdoc_options: []
62
-
63
- require_paths:
54
+ require_paths:
64
55
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
56
+ required_ruby_version: !ruby/object:Gem::Requirement
66
57
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: "0"
71
- required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
63
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: "0"
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
77
68
  requirements: []
78
-
79
69
  rubyforge_project:
80
- rubygems_version: 1.5.1
70
+ rubygems_version: 1.8.6
81
71
  signing_key:
82
72
  specification_version: 3
83
73
  summary: Assets for Rad Framework
84
74
  test_files: []
85
-