merb-assets 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 YOUR NAME
1
+ Copyright (c) 2008 Ezra Zygmuntowicz
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ GEM_EMAIL = "ez@engineyard.com"
17
17
 
18
18
  GEM_NAME = "merb-assets"
19
19
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20
- GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.7") + PKG_BUILD
20
+ GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.8") + PKG_BUILD
21
21
 
22
22
  RELEASE_NAME = "REL #{GEM_VERSION}"
23
23
 
@@ -35,7 +35,7 @@ spec = Gem::Specification.new do |s|
35
35
  s.author = GEM_AUTHOR
36
36
  s.email = GEM_EMAIL
37
37
  s.homepage = PROJECT_URL
38
- s.add_dependency('merb-core', '>= 0.9.7')
38
+ s.add_dependency('merb-core', '>= 0.9.8')
39
39
  s.require_path = 'lib'
40
40
  s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
41
41
  end
@@ -45,21 +45,33 @@ Rake::GemPackageTask.new(spec) do |pkg|
45
45
  end
46
46
 
47
47
  desc "Install the gem"
48
- task :install => [:package] do
49
- sh install_command(GEM_NAME, GEM_VERSION)
48
+ task :install do
49
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
50
50
  end
51
51
 
52
- namespace :jruby do
52
+ desc "Uninstall the gem"
53
+ task :uninstall do
54
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
55
+ end
53
56
 
54
- desc "Run :package and install the resulting .gem with jruby"
55
- task :install => :package do
56
- sh jinstall_command(GEM_NAME, GEM_VERSION)
57
+ desc "Create a gemspec file"
58
+ task :gemspec do
59
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
60
+ file.puts spec.to_ruby
57
61
  end
58
-
59
62
  end
60
63
 
61
- desc "Run all specs"
62
- Spec::Rake::SpecTask.new("specs") do |t|
63
- t.spec_opts = ["--format", "specdoc", "--colour"]
64
- t.spec_files = Dir["spec/**/*_spec.rb"].sort
64
+ desc "Run all examples (or a specific spec with TASK=xxxx)"
65
+ Spec::Rake::SpecTask.new('spec') do |t|
66
+ t.spec_opts = ["-cfs"]
67
+ t.spec_files = begin
68
+ if ENV["TASK"]
69
+ ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
70
+ else
71
+ FileList['spec/**/*_spec.rb']
72
+ end
73
+ end
65
74
  end
75
+
76
+ desc 'Default: run spec examples'
77
+ task :default => 'spec'
@@ -169,8 +169,8 @@ module Merb
169
169
  # *files<String>:: Names of the files to bundle.
170
170
  def initialize(name, *files)
171
171
  @bundle_name = name == true ? :all : name
172
- @bundle_filename = asset_path(self.class.asset_type, @bundle_name, true)
173
- @files = files.map { |f| asset_path(self.class.asset_type, f, true) }
172
+ @bundle_filename = Merb.root / asset_path(self.class.asset_type, @bundle_name, true)
173
+ @files = files.map { |f| Merb.root / asset_path(self.class.asset_type, f, true) }
174
174
  end
175
175
 
176
176
  # Creates the new bundled file, executing all the callbacks.
@@ -113,6 +113,8 @@ module Merb
113
113
  end
114
114
  opts[:src] ||= opts.delete(:path) + img
115
115
  end
116
+ random = opts.delete(:reload) || Merb::Config[:reload_templates]
117
+ opts[:src] += random_query_string if random
116
118
  %{<img #{ opts.to_xml_attributes } />}
117
119
  end
118
120
 
@@ -427,6 +429,8 @@ module Merb
427
429
  def js_include_tag(*scripts)
428
430
  options = scripts.last.is_a?(Hash) ? scripts.pop : {}
429
431
  return nil if scripts.empty?
432
+
433
+ reload = options[:reload] || Merb::Config[:reload_templates]
430
434
 
431
435
  if (bundle_name = options[:bundle]) && Merb::Assets.bundle? && scripts.size > 1
432
436
  bundler = Merb::Assets::JavascriptAssetBundler.new(bundle_name, *scripts)
@@ -437,8 +441,10 @@ module Merb
437
441
  tags = ""
438
442
 
439
443
  for script in scripts
444
+ src = asset_path(:javascript, script)
445
+ src += random_query_string if reload
440
446
  attrs = {
441
- :src => asset_path(:javascript, script),
447
+ :src => src,
442
448
  :type => "text/javascript"
443
449
  }
444
450
  tags << %Q{<script #{attrs.to_xml_attributes}></script>}
@@ -486,6 +492,8 @@ module Merb
486
492
  options = stylesheets.last.is_a?(Hash) ? stylesheets.pop : {}
487
493
  return nil if stylesheets.empty?
488
494
 
495
+ reload = options[:reload] || Merb::Config[:reload_templates]
496
+
489
497
  if (bundle_name = options[:bundle]) && Merb::Assets.bundle? && stylesheets.size > 1
490
498
  bundler = Merb::Assets::StylesheetAssetBundler.new(bundle_name, *stylesheets)
491
499
  bundled_asset = bundler.bundle!
@@ -495,8 +503,10 @@ module Merb
495
503
  tags = ""
496
504
 
497
505
  for stylesheet in stylesheets
506
+ href = asset_path(:stylesheet, stylesheet)
507
+ href += random_query_string if reload
498
508
  attrs = {
499
- :href => asset_path(:stylesheet, stylesheet),
509
+ :href => href,
500
510
  :type => "text/css",
501
511
  :rel => "Stylesheet",
502
512
  :charset => options[:charset] || 'utf-8',
@@ -631,5 +641,9 @@ module Merb
631
641
  end
632
642
  end
633
643
 
644
+ def random_query_string
645
+ Time.now.strftime("?%m%d%H%M%S#{rand(99)}")
646
+ end
647
+
634
648
  end
635
649
  end
@@ -53,6 +53,11 @@ describe "Accessing Assets" do
53
53
  image_tag('charts', :path => '/dynamic/').should ==
54
54
  "<img src=\"/dynamic/charts\" />"
55
55
  end
56
+
57
+ it "should create image tag with a random query string" do
58
+ result = image_tag('foo.gif', :reload => true)
59
+ result.should match(%r{<img src="/images/foo.gif\?\d+" />})
60
+ end
56
61
 
57
62
  end
58
63
 
@@ -182,7 +187,19 @@ describe "External JavaScript and Stylesheets" do
182
187
  result.should match(%r{/stylesheets/style.css})
183
188
  result.should match(%r{/stylesheets/layout.css})
184
189
  end
190
+
191
+ it "should create a js include tag with a random query string" do
192
+ Merb::Config[:reload_templates] = true
193
+ result = js_include_tag('jquery.js')
194
+ result.should match(%r{/javascripts/jquery.js\?\d+})
195
+ Merb::Config[:reload_templates] = false
196
+ end
185
197
 
198
+ it "should create a css include tag with a random query string" do
199
+ result = css_include_tag('style.css', :reload => true)
200
+ result.should match(%r{/stylesheets/style.css\?\d+})
201
+ end
202
+
186
203
  it "should create a css include tag with the specified media" do
187
204
  css_include_tag('style', :media => :print).should match(%r{media="print"})
188
205
  end
@@ -1,4 +1,3 @@
1
- $TESTING=true
2
1
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
2
  require "rubygems"
4
3
  require "merb-core"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-10 00:00:00 +03:00
12
+ date: 2008-10-06 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.7
23
+ version: 0.9.8
24
24
  version:
25
25
  description: Merb plugin that provides the helpers for assets and asset bundling
26
26
  email: ez@engineyard.com