Skip to content

Commit

Permalink
Fixed critical bug that prevented sc-build from correctly compiling s…
Browse files Browse the repository at this point in the history
…tylesheets and javascript.
  • Loading branch information
Charles Jolley committed Jul 1, 2008
1 parent f1e09b2 commit 2c1e6f5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 50 deletions.
4 changes: 4 additions & 0 deletions History.txt
@@ -1,4 +1,8 @@

* Fixed critical bug that prevented sc-build from correctly compiling stylesheets and javascript.

== 0.9.12

* Added :include_method = :link|:import option to the stylesheets_for_client helper. This allows you to select between inclusion using link tags vs @import (which is required for OpenSocial apps) - Thanks Johannes Fahrenkrug!

* Proxy now handles posts and rewrites Location headers so they stay in the same domain. Should make this feature far more robust.
Expand Down
2 changes: 1 addition & 1 deletion bin/sc-build
Expand Up @@ -140,7 +140,7 @@ SC.logger.info("Selected Languages: #{languages.join(', ')}")
SC.logger.info('')
bundles.each do |bundle|
SC.logger.info("Building #{bundle.bundle_name} > #{bundle.build_root}...")

if clean
SC.logger.debug("~ Cleaning #{bundle.build_root}")
FileUtils.rm_rf(bundle.build_root)
Expand Down
12 changes: 6 additions & 6 deletions lib/sproutcore/bundle.rb
Expand Up @@ -74,7 +74,7 @@ class Bundle
# The default build mode for bundles. This should be set once before you
# start using bundles. You can override this when you create a specific
# bundle, but that should not be the typical behavior
def self.build_mode; @build_mode || :development; end
def self.build_mode; (@build_mode || :development).to_sym; end

def self.build_mode=(new_mode); @build_mode = new_mode; end

Expand Down Expand Up @@ -210,7 +210,7 @@ def initialize(bundle_name, opts ={})
@index_root = opts[:index_root] || ['',(index_prefix.nil? || index_prefix.size==0) ? nil : index_prefix, bundle_name.to_s].compact.join('/')

# build_mode:: The build mode to use when combining resources.
@build_mode = opts[:build_mode] || SproutCore::Bundle.build_mode
@build_mode = (opts[:build_mode] || SproutCore::Bundle.build_mode || :development).to_sym

# layout: Path to the layout resource. This should be of the form
@layout = opts[:layout] || 'sproutcore:lib/index.rhtml'
Expand Down Expand Up @@ -253,7 +253,7 @@ def entries_for(resource_type, opts={})
with_hidden = opts[:hidden] || :none

language = opts[:language] || preferred_language
mode = opts[:build_mode] || build_mode
mode = (opts[:build_mode] || build_mode).to_sym
manifest = manifest_for(language, mode)

ret = manifest.entries_for(resource_type)
Expand All @@ -280,7 +280,7 @@ def entry_for(resource_name, opts={})
with_hidden = opts[:hidden] || :none

language = opts[:language] || preferred_language
mode = opts[:build_mode] || build_mode
mode = (opts[:build_mode] || build_mode).to_sym
manifest = manifest_for(language, mode)

ret = manifest.entry_for(resource_name)
Expand Down Expand Up @@ -359,7 +359,7 @@ def entries(opts ={})
with_hidden = opts[:hidden] || :none

language = opts[:language] || preferred_language
mode = opts[:build_mode] || build_mode
mode = (opts[:build_mode] || build_mode).to_sym
manifest = manifest_for(language, mode)

ret = manifest.entries
Expand Down Expand Up @@ -627,7 +627,7 @@ def strings_for_entry(strings_entry)
#
def strings_hash(opts={})

build_mode = opts[:build_mode] ||= build_mode
build_mode = (opts[:build_mode] ||= self.build_mode).to_sym
language = opts[:language] ||= preferred_language
key = [build_mode.to_s, language.to_s].join(':').to_sym

Expand Down
86 changes: 44 additions & 42 deletions lib/sproutcore/bundle_manifest.rb
Expand Up @@ -92,56 +92,53 @@ def build!

# STEP 3: Handle special build modes...

# a. Merge fixture types into JS types & tests
if self.include_fixtures? && !entries[:fixture].nil?
entries[:javascript] = (entries[:javascript] || []) + entries[:fixture]
else
entries.delete(:fixture)
end
# a. Merge fixture types into JS types & tests
if self.include_fixtures? && !entries[:fixture].nil?
entries[:javascript] = (entries[:javascript] || []) + entries[:fixture]
else
entries.delete(:fixture)
end

# b. Rewrite all of the JS & CSS file paths and URLs to point to
# cached versions
# (Cached versions are written to _cache/filename-ctime.ext)
if self.build_mode == :development
(entries[:javascript] ||= []).each do | entry |
setup_timestamp_token(entry)
end

(entries[:stylesheet] ||= []).each do | entry |
setup_timestamp_token(entry)
end

# c. Rewrite the URLs for all other resources to go through the _src
# symlink
## -----> Already done build_entry_for()
# a. Combine the JS file paths into a single entry for the
# javascript.js
hide_composite = self.combine_javascript?
if (working = entries[:javascript]) && working.size>0
entry = build_entry_for('javascript.js', :javascript, working, hide_composite)
setup_timestamp_token(entry) if self.build_mode == :development
entry.hidden = true unless hide_composite
working << entry
# b. Rewrite all of the JS & CSS file paths and URLs to point to
# cached versions
# (Cached versions are written to _cache/filename-ctime.ext)
if self.build_mode == :development
(entries[:javascript] ||= []).each do | entry |
setup_timestamp_token(entry)
end

# b. Combine the CSS file paths into a single entry for the
# stylesheet.css
hide_composite = self.combine_stylesheets?
if (working = entries[:stylesheet]) && working.size>0
entry = build_entry_for('stylesheet.css', :stylesheet, working, hide_composite)
setup_timestamp_token(entry) if self.build_mode == :development
entry.hidden = true unless hide_composite
working << entry
(entries[:stylesheet] ||= []).each do | entry |
setup_timestamp_token(entry)
end




# c. Remove the entries for anything that is not JS, CSS, HTML or
# Resource
# Resource in non-development modes
else
entries.delete(:test)
end

# c. Rewrite the URLs for all other resources to go through the _src
# symlink
## -----> Already done build_entry_for()
# a. Combine the JS file paths into a single entry for the
# javascript.js
hide_composite = self.combine_javascript?
if (working = entries[:javascript]) && working.size>0
entry = build_entry_for('javascript.js', :javascript, working, hide_composite)
setup_timestamp_token(entry) if self.build_mode == :development
entry.hidden = true unless hide_composite
working << entry
end

# b. Combine the CSS file paths into a single entry for the
# stylesheet.css
hide_composite = self.combine_stylesheets?
if (working = entries[:stylesheet]) && working.size>0
entry = build_entry_for('stylesheet.css', :stylesheet, working, hide_composite)
setup_timestamp_token(entry) if self.build_mode == :development
entry.hidden = true unless hide_composite
working << entry
end

# Save entries into hashes
@entries_by_type = entries
Expand Down Expand Up @@ -272,7 +269,12 @@ def build_entry_for(src_path, src_type, composite=nil, hide_composite = true)
# well
unless composite.nil?
composite.each { |x| x.hidden = true } if hide_composite
ret.composite = composite

# IMPORTANT: The array of composite entries passed in here can come
# directly from the entries hash, which will later be updated to
# include the composite entry (ret) itself. Dup the array here to
# make sure the list of composites maintained here does not change.
ret.composite = composite.dup
end

# The build path is the build_root + the filename
Expand Down
1 change: 1 addition & 0 deletions lib/sproutcore/helpers/static_helper.rb
Expand Up @@ -96,6 +96,7 @@ def static_url(resource_name, opts = {})

# Localizes the passed string, using the optional passed options.
def loc(string, opts = {})
string = string.nil? ? '' : string.to_s
opts[:language] ||= language
bundle.strings_hash(opts)[string] || string
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sproutcore/library.rb
Expand Up @@ -276,7 +276,7 @@ def combine_javascript_build_modes
# The build modes wherein javascript should be combined.
def combine_stylesheets_build_modes
env = base_environment || {}
[(env[:combine_stylesheets] || [:development, :production])].flatten
[(env[:combine_stylesheets] || :production)].flatten
end

# ==== Returns
Expand Down

0 comments on commit 2c1e6f5

Please sign in to comment.