Skip to content

Commit

Permalink
Faster ext replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Aug 22, 2010
1 parent 6e724b0 commit 9c47970
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/buildtasks/manifest.rake
Expand Up @@ -173,7 +173,7 @@ namespace :manifest do
test_entries << manifest.add_transform(entry,
:build_task => "build:test",
:entry_type => :test,
:ext => :html)
:ext => 'html')

# Strip off dirnames, saving each by dirname...
dirname = entry[:filename]
Expand All @@ -188,7 +188,7 @@ namespace :manifest do
manifest.add_composite filename,
:build_task => "build:test",
:entry_type => :test,
:ext => :html,
:ext => 'html',
:source_entries => entries,
:hide_entries => false
end
Expand Down
4 changes: 4 additions & 0 deletions lib/sproutcore/buildfile/string_ext.rb
Expand Up @@ -32,6 +32,10 @@ def rake_extension(method)
#
class String
rake_extension("ext") do
def replace_ext!(newext)
sub!(%r(([^/\\])\.[^./\\]*$)) { $1 + newext }
end

# Replace the file extension with +newext+. If there is no extenson on
# the string, append the new extension to the end. If the new extension
# is not given, or is the empty string, remove any existing extension.
Expand Down
26 changes: 14 additions & 12 deletions lib/sproutcore/models/manifest.rb
Expand Up @@ -204,34 +204,36 @@ def add_transform(entry, opts ={})

# Clone important properties to new transform...
opts = HashStruct.new(opts)
%w(filename build_path url).each do |key|
opts[key.to_sym] ||= entry[key.to_sym]
end

opts[:filename] ||= entry[:filename]
opts[:build_path] ||= entry[:build_path]
opts[:url] ||= entry[:url]

# generate a unique staging path. If the original entry has its
# staging_path set == to source_root (optimization for build:copy), then
# first rebase staging path against the staging root.
if (staging_path = entry[:staging_path]) == entry[:source_path]
staging_path = File.join(self[:staging_root], entry[:filename])
end

opts[:staging_path] ||= unique_staging_path(staging_path)

# generate a unique cache path from the staging page. just sub the
# staging root for the cache root
opts[:cache_path] ||= unique_cache_path(entry[:cache_path])

# copy other useful entries
opts.source_entry = entry
opts.source_entries = [entry]
opts.composite = true
opts.transform = true # make .transform? = true
opts[:source_entry] = entry
opts[:source_entries] = [entry]
opts[:composite] = true
opts[:transform] = true # make .transform? = true

# Normalize to new extension if provided. else copy ext from entry...
if opts[:ext]
%w(filename build_path staging_path url).each do |key|
opts[key.to_sym] = opts[key.to_sym].ext(opts[:ext])
end
opts[:ext] = opts[:ext].to_s
if ext = opts[:ext]
opts[:url].replace_ext!(ext)
opts[:staging_path].replace_ext!(ext)
opts[:build_path].replace_ext!(ext)
opts[:filename].replace_ext!(ext)
else
opts[:ext] = entry[:ext]
end
Expand Down

0 comments on commit 9c47970

Please sign in to comment.