Skip to content
Browse files

Significantly improve performance by eliminating use of StructHash in…

…ternally. The StructHash API is still available to user Buildfiles, where the method_missing is only hit a few times. Using it internally, on the other hand, resulted in huge amounts of hits to this relatively slow code path.
  • Loading branch information...
1 parent 9d6ccfd commit 0cc2392f74a898c65092b7969f38df3f3685df9c @wycats wycats committed Aug 20, 2010
View
15 lib/sproutcore.rb
@@ -69,8 +69,8 @@ def self.env=(hash); @env = HashStruct.new(hash); end
def self.logger
return @logger unless @logger.nil?
- if env.logfile
- @logger = Logger.new env.logfile, 10, 1024000
+ if env[:logfile]
+ @logger = Logger.new env[:logfile], 10, 1024000
else
@logger = Logger.new $stderr
@@ -80,7 +80,7 @@ def self.logger
end
end
- @logger.level = (env.log_level == :debug) ? Logger::DEBUG : ((env.log_level == :info) ? Logger::INFO : Logger::WARN)
+ @logger.level = (env[:log_level] == :debug) ? Logger::DEBUG : ((env[:log_level] == :info) ? Logger::INFO : Logger::WARN)
return @logger
end
@@ -91,7 +91,7 @@ def self.logger
# compatibility reasons, :development and :debug are treated as being
# identical.
def self.build_mode
- ret = env.build_mode || :production
+ ret = env[:build_mode] || :production
ret = ret.to_sym unless ret.nil?
ret = :debug if ret == :development # backwards compatibility
ret
@@ -127,6 +127,13 @@ def self.load_project(path = nil, opts = {})
end
end
+ def self.yui_jar
+ @yui_jar ||= begin
+ yui_root = File.expand_path("../vendor/yui-compressor", __FILE__)
+ File.join(yui_root, 'yuicompressor-2.4.2.jar')
+ end
+ end
+
end # module SC
SC = SproutCore # alias
View
12 lib/sproutcore/builders/combine.rb
@@ -19,10 +19,10 @@ class Builder::Combine < Builder::Base
def build(dst_path)
lines = []
- entries = entry.ordered_entries || entry.source_entries
+ entries = entry[:ordered_entries] || entry[:source_entries]
- target_name = entry.target.target_name.to_s.sub(/^\//,'')
- if entry.top_level_lazy_instantiation && entry.combined
+ target_name = entry.target[:target_name].to_s.sub(/^\//,'')
+ if entry[:top_level_lazy_instantiation] && entry[:combined]
lines << ";
if ((typeof SC !== 'undefined') && SC && !SC.LAZY_INSTANTIATION) {
SC.LAZY_INSTANTIATION = {};
@@ -37,15 +37,15 @@ def build(dst_path)
end
entries.each do |entry|
- src_path = entry.stage!.staging_path
+ src_path = entry.stage![:staging_path]
next unless File.exist?(src_path)
- lines << "/* >>>>>>>>>> BEGIN #{entry.filename} */\n"
+ lines << "/* >>>>>>>>>> BEGIN #{entry[:filename]} */\n"
lines += readlines(src_path)
lines << "\n"
end
- if entry.top_level_lazy_instantiation && entry.combined
+ if entry[:top_level_lazy_instantiation] && entry[:combined]
lines << "
}
)
View
32 lib/sproutcore/builders/html.rb
@@ -44,7 +44,7 @@ class Builder::Html < Builder::Base
# manifest owning the current entry
attr_reader :manifest
- def target_name; target.target_name.to_s.sub(/^\//,''); end
+ def target_name; target[:target_name].to_s.sub(/^\//,''); end
alias_method :bundle_name, :target_name # backwards compat
def config; target.config; end
@@ -59,29 +59,29 @@ def layout_entry
# from the layout property, which is a relative pathname.
def layout_path
entry = layout_entry
- entry.nil? ? nil : entry.staging_path
+ entry.nil? ? nil : entry[:staging_path]
end
def initialize(entry)
super(entry)
@target = @bundle = entry.manifest.target
- @filename = entry.filename
- @language = @entry.manifest.language
+ @filename = entry[:filename]
+ @language = @entry.manifest[:language]
@project = @library = @target.project
@manifest = entry.manifest
@renderer = nil
# set the current layout from the target's config.layout
- @layout = @target.config.layout || 'lib/index.rhtml'
+ @layout = @target.config[:layout] || 'lib/index.rhtml'
# find all entries -- use source_Entries + required if needed
- @entries = entry.source_entries.dup
+ @entries = entry[:source_entries].dup
if entry.include_required_targets?
@target.expand_required_targets.each do |target|
cur_manifest = target.manifest_for(@manifest.variation).build!
- cur_entry = cur_manifest.entry_for(entry.filename, :combined => true) || cur_manifest.entry_for(entry.filename, :hidden => true, :combined => true)
+ cur_entry = cur_manifest.entry_for(entry[:filename], :combined => true) || cur_manifest.entry_for(entry[:filename], :hidden => true, :combined => true)
next if cur_entry.nil?
- @entries += cur_entry.source_entries
+ @entries += cur_entry[:source_entries]
end
end
end
@@ -90,7 +90,7 @@ def initialize(entry)
# This method can be overridden by subclasses to provide specific
# config settings.
def expand_required_targets(target, opts = {})
- opts[:debug] = target.config.load_debug
+ opts[:debug] = target.config[:load_debug]
opts[:theme] = true
return target.expand_required_targets(opts)
end
@@ -112,9 +112,9 @@ def render
end
def build(dst_path)
- if CONFIG.html5_manifest
+ if CONFIG[:html5_manifest]
$to_html5_manifest << dst_path
- $to_html5_manifest_networks = CONFIG.html5_manifest_networks
+ $to_html5_manifest_networks = CONFIG[:html5_manifest_networks]
@content_for_html5_manifest = true
end
writelines dst_path, [self.render]
@@ -155,7 +155,7 @@ def compile(render_engine, input_path, content_for_key = nil)
input = File.read(input_path)
content_for content_for_key do
- _render_compiled_template( render_engine.compile(input) )
+ _render_compiled_template( render_engine.compile(input), input_path )
end
@render = old_renderer
@@ -188,15 +188,15 @@ def render_partial(entry)
def render_entry(entry)
@content_for_designer = '<script type="text/javascript">SC.suppressMain = YES;</script>' if $design_mode
entry.stage!
- entry.target.buildfile.invoke entry.render_task,
+ entry.target.buildfile.invoke entry[:render_task],
:entry => entry,
- :src_path => entry.staging_path,
+ :src_path => entry[:staging_path],
:context => self
end
# Renders a compiled template within this context
- def _render_compiled_template(compiled_template)
- self.instance_eval "def __render(); #{compiled_template}; end"
+ def _render_compiled_template(compiled_template, input_path="(compiled erb)")
+ self.instance_eval "def __render(); #{compiled_template}; end", input_path
begin
self.send(:__render) do |*names|
self.instance_variable_get("@content_for_#{names.first}")
View
14 lib/sproutcore/builders/javascript.rb
@@ -18,10 +18,10 @@ class Builder::JavaScript < Builder::Base
def build(dst_path)
lines = []
- target_name = entry.target.target_name.to_s.sub(/^\//,'')
+ target_name = entry.target[:target_name].to_s.sub(/^\//,'')
- if entry.lazy_instantiation && entry.notify_onload
- lines << ";
+ if entry[:lazy_instantiation] && entry[:notify_onload]
+ lines << ";
if ((typeof SC !== 'undefined') && SC && !SC.LAZY_INSTANTIATION) {
SC.LAZY_INSTANTIATION = {};
}
@@ -34,14 +34,14 @@ def build(dst_path)
"
end
- lines << readlines(entry.source_path).map { |l| rewrite_inline_code(l) }
+ lines << readlines(entry[:source_path]).map { |l| rewrite_inline_code(l) }
# Try to load dependencies if we're not combining javascript.
- if entry.notify_onload
+ if entry[:notify_onload]
lines << "; if ((typeof SC !== 'undefined') && SC && SC.scriptDidLoad) SC.scriptDidLoad('#{target_name}');"
end
- if entry.lazy_instantiation && entry.notify_onload
+ if entry[:lazy_instantiation] && entry[:notify_onload]
lines << "
}
)
@@ -57,7 +57,7 @@ def build(dst_path)
# strings. -- You can name a string key beginning with "@@" and it will
# be removed.
def localized_strings?
- @lstrings ||= entry.localized? && entry.filename =~ /strings.js$/
+ @lstrings ||= entry.localized? && entry[:filename] =~ /strings.js$/
end
# Rewrites inline content for a single line
View
13 lib/sproutcore/builders/minify.rb
@@ -40,7 +40,7 @@ def build_css(dst_path)
FileUtils.copy(entry.source_path, dst_path)
else
FileUtils.mkdir_p(File.dirname(dst_path)) # make sure loc exists...
- filecompress = "java -jar " + yui_jar + " --charset utf-8 --line-break 0 --nomunge --preserve-semi --disable-optimizations " + entry.source_path + " -o \"" + dst_path + "\" 2>&1"
+ filecompress = "java -jar " + SC.yui_jar + " --charset utf-8 --line-break 0 --nomunge --preserve-semi --disable-optimizations " + entry.source_path + " -o \"" + dst_path + "\" 2>&1"
SC.logger.info 'Compressing CSS with YUI .... '+ dst_path
SC.logger.debug `#{filecompress}`
@@ -61,7 +61,7 @@ def build_javascript(dst_path)
FileUtils.copy(entry.source_path, dst_path)
else
FileUtils.mkdir_p(File.dirname(dst_path)) # make sure loc exists...
- filecompress = "java -jar " + yui_jar + " --charset utf-8 --line-break 80 " + entry.source_path + " -o \"" + dst_path + "\" 2>&1"
+ filecompress = "java -jar " + SC.yui_jar + " --charset utf-8 --line-break 80 " + entry.source_path + " -o \"" + dst_path + "\" 2>&1"
SC.logger.info 'Compressing with YUI: '+ dst_path + "..."
output = `#{filecompress}` # It'd be nice to just read STDERR, but
@@ -78,7 +78,7 @@ def build_javascript(dst_path)
def build_inline_javascript(dst_path)
SC.logger.info 'Compressing inline Javascript with YUI: ' + dst_path + "..."
FileUtils.mkdir_p(File.dirname(dst_path)) # make sure loc exists...
- filecompress = "java -jar " + yui_jar + " --charset utf-8 --line-break 80 " + entry.source_path + " -o \"" + dst_path + "\" 2>&1"
+ filecompress = "java -jar " + SC.yui_jar + " --charset utf-8 --line-break 80 " + entry.source_path + " -o \"" + dst_path + "\" 2>&1"
SC.logger.info 'Compressing with YUI: '+ dst_path + "..."
output = `#{filecompress}` # It'd be nice to just read STDERR, but
@@ -93,13 +93,6 @@ def build_inline_javascript(dst_path)
private
- def yui_jar
- @yui_jar ||= begin
- yui_root = File.expand_path("../../vendor/yui-compressor", __FILE__)
- File.join(yui_root, 'yuicompressor-2.4.2.jar')
- end
- end
-
def _report_error(output, input_filename, input_filepath)
# The output might have some clues to what exactly was wrong, and it'll
# be convenient for users if we include the subset. So we'll read the
View
2 lib/sproutcore/builders/strings.rb
@@ -16,7 +16,7 @@ module SC
class Builder::Strings < Builder::Base
def build(dst_path)
- data = parse_strings_js(entry.source_path)
+ data = parse_strings_js(entry[:source_path])
writelines dst_path, [data.to_yaml]
end
View
2 lib/sproutcore/builders/stylesheet.rb
@@ -19,7 +19,7 @@ module SC
class Builder::Stylesheet < Builder::Base
def build(dst_path)
- lines = readlines(entry.source_path).map { |l| rewrite_inline_code(l) }
+ lines = readlines(entry[:source_path]).map { |l| rewrite_inline_code(l) }
writelines dst_path, lines
end
View
10 lib/sproutcore/builders/test.rb
@@ -15,7 +15,7 @@ class Builder::Test < Builder::Html
def initialize(entry)
super(entry)
- @layout = @target.config.test_layout || 'lib/test.rhtml'
+ @layout = @target.config[:test_layout] || 'lib/test.rhtml'
end
# Always include any required test targets as well when loading unit
@@ -30,13 +30,13 @@ def expand_required_targets(target, opts = {})
def render_entry(entry)
entry.stage!
- case entry.ext
+ case entry[:ext]
when 'js'
render_jstest(entry)
when 'rhtml'
entry.target.buildfile.invoke 'render:erubis',
:entry => entry,
- :src_path => entry.staging_path,
+ :src_path => entry[:staging_path],
:context => self
end
end
@@ -47,8 +47,8 @@ def default_content_for_key; :body; end
# into its own closure so that globals defined by one test will not
# conflict with any others.
def render_jstest(entry)
- lines = readlines(entry.staging_path)
- pathname = entry.staging_path.gsub(/^.+\/staging\//,'').gsub(/"/, '\"')
+ lines = readlines(entry[:staging_path])
+ pathname = entry[:staging_path].gsub(/^.+\/staging\//,'').gsub(/"/, '\"')
lines.unshift %[<script type="text/javascript">\nif (typeof SC !== "undefined") {\n SC.mode = "TEST_MODE";\n SC.filename = "#{pathname}"; \n}\n(function() {\n]
lines.push %[\n})();\n</script>\n]
@content_for_final = (@content_for_final || '') + lines.join("")
View
4 lib/sproutcore/builders/test_index.rb
@@ -15,8 +15,8 @@ class Builder::TestIndex < Builder::Base
def build(dst_path)
require 'json'
- items = entry.source_entries.map do |e|
- { "filename" => e.filename.ext(''), "url" => e.url }
+ items = entry[:source_entries].map do |e|
+ { "filename" => e[:filename].ext(''), "url" => e[:url] }
end
writelines dst_path, [items.to_json]
end
View
16 lib/sproutcore/buildfile.rb
@@ -103,7 +103,7 @@ class Buildfile
# Determines if this directory has a buildfile or not...
def self.has_buildfile?(dir_path, buildfile_names=nil)
- buildfile_names ||= (SC.env.buildfile_names || BUILDFILE_NAMES)
+ buildfile_names ||= (SC.env[:buildfile_names] || BUILDFILE_NAMES)
buildfile_names.each do |path|
path = File.join(dir_path, path)
return true if File.exist?(path) && !File.directory?(path)
@@ -152,9 +152,9 @@ def self.define(&block)
# === Returns
# self
#
- def define!(string=nil, &block)
+ def define!(string=nil, filename="(unknown Buildfile)", &block)
context = reset_define_context :current_mode => :all
- instance_eval(string) if string
+ instance_eval(string, filename) if string
instance_eval(&block) if block_given?
load_imports
reset_define_context context
@@ -183,7 +183,7 @@ def load!(filename=nil, buildfile_names=nil)
if File.directory?(filename)
# search directory for buildfiles and load them.
- buildfile_names ||= (SC.env.buildfile_names || BUILDFILE_NAMES)
+ buildfile_names ||= (SC.env[:buildfile_names] || BUILDFILE_NAMES)
buildfile_names.each do |path|
path = File.join(filename, path)
next unless File.exist?(path) && !File.directory?(path)
@@ -195,7 +195,7 @@ def load!(filename=nil, buildfile_names=nil)
@current_path = filename
loaded_paths << filename # save loaded paths
SC.logger.debug "Loading buildfile at #{filename}"
- define!(File.read(filename)) if filename && File.exist?(filename)
+ define!(File.read(filename), filename) if filename && File.exist?(filename)
@current_path = old_path
end
return self
@@ -261,11 +261,11 @@ def intern(task_class, task_name)
#
def current_mode
- @define_context.current_mode
+ @define_context[:current_mode]
end
def current_mode=(new_mode)
- @define_context.current_mode = new_mode
+ @define_context[:current_mode] = new_mode
end
# Configures the buildfile for use with the specified target. Call this
@@ -275,7 +275,7 @@ def current_mode=(new_mode)
# self
#
def for_target(target)
- @target_name = target.target_name.to_s
+ @target_name = target[:target_name].to_s
return self
end
View
2 lib/sproutcore/buildfile/task.rb
@@ -228,7 +228,7 @@ def execute(args=nil)
@execute_count += 1
args ||= EMPTY_TASK_ARGS
- return if SC.env.dryrun
+ return if SC.env[:dryrun]
@actions.each do |act|
case act.arity
View
18 lib/sproutcore/helpers/entry_sorter.rb
@@ -35,10 +35,10 @@ def sort(entries)
# first remove bundle entries which MUST be first or last
entries = entries.select do |entry|
- if entry.filename == 'bundle_info.js'
+ if entry[:filename] == 'bundle_info.js'
bundleInfoEntry = [entry]
false
- elsif entry.filename == 'bundle_loaded.js'
+ elsif entry[:filename] == 'bundle_loaded.js'
bundleLoadedEntry = [entry]
false
else
@@ -48,8 +48,8 @@ def sort(entries)
# then sort remaining entries by filename - ignoring case
entries = entries.sort do |a,b|
- a = (a.filename || '').to_s.downcase
- b = (b.filename || '').to_s.downcase
+ a = (a[:filename] || '').to_s.downcase
+ b = (b[:filename] || '').to_s.downcase
# lproj/foo_page.js and main.js are loaded last
a_kind = (a =~ /(lproj|resources)\/.+_page\.js$/) ? 1 : -1
@@ -86,19 +86,19 @@ def required_entries(required, entries, requiring_entry, all_entries)
filename = filename.to_s.downcase.ext('')
source_filename = "source/#{filename}"
entry = all_entries.find do |e|
- e.filename.to_s.downcase.ext('') == source_filename
+ e[:filename].to_s.downcase.ext('') == source_filename
end
# try localized version...
if entry.nil? && !(filename =~ /^lproj\//)
source_filename = "source/lproj/#{filename}"
entry = all_entries.find do |e|
- e.filename.to_s.downcase.ext('') == source_filename
+ e[:filename].to_s.downcase.ext('') == source_filename
end
end
if entry.nil?
- SC.logger.warn "Could not find entry '#{filename}' required in #{requiring_entry.target.target_name.to_s.sub(/^\//,'')}:#{requiring_entry.filename}"
+ SC.logger.warn "Could not find entry '#{filename}' required in #{requiring_entry.target[:target_name].to_s.sub(/^\//,'')}:#{requiring_entry[:filename]}"
end
entry
@@ -112,7 +112,7 @@ def next_entry(entries)
# look for preferred entries first...
@preferred_filenames.each do |filename|
- ret = entries.find { |e| e.filename.to_s.downcase == filename }
+ ret = entries.find { |e| e[:filename].to_s.downcase == filename }
break if ret
end
@@ -126,7 +126,7 @@ def add_entry_to_set(entry, ret, seen, entries, all_entries)
return if seen.include?(entry)
seen << entry
- req = required_entries(entry.required, entries, entry, all_entries)
+ req = required_entries(entry[:required], entries, entry, all_entries)
req.each do |required|
next if required.nil?
add_entry_to_set(required, ret, seen, entries, all_entries)
View
38 lib/sproutcore/helpers/static_helper.rb
@@ -37,18 +37,18 @@ def stylesheets_for_client(target_name = nil, opts = nil)
# collect urls from entries
urls = []
- combine_stylesheets = t.config.combine_stylesheets
+ combine_stylesheets = t.config[:combine_stylesheets]
combined_entries(t, opts, 'stylesheet.css', 'stylesheet-packed.css') do |cur_target, cur_entry|
# include either the entry URL or URL of ordered entries
# depending on setup
if combine_stylesheets
urls << cur_entry.cacheable_url
else
- urls += cur_entry.ordered_entries.map { |e| e.cacheable_url }
+ urls += cur_entry[:ordered_entries].map { |e| e.cacheable_url }
end
# add any stylesheet libs from the target
- urls += (cur_target.config.stylesheet_libs || [])
+ urls += (cur_target.config[:stylesheet_libs] || [])
end
# Convert to HTML and return
@@ -89,19 +89,19 @@ def javascripts_for_client(target_name = nil, opts = {})
# collect urls from entries
urls = []
- combine_javascript = t.config.combine_javascript
+ combine_javascript = t.config[:combine_javascript]
combined_entries(t, opts, 'javascript.js', 'javascript-packed.js') do |cur_target, cur_entry|
# include either the entry URL or URL of ordered entries
# depending on setup
- if cur_target.config.combine_javascript
+ if cur_target.config[:combine_javascript]
urls << cur_entry.cacheable_url
else
- urls += cur_entry.ordered_entries.map { |e| e.cacheable_url }
+ urls += cur_entry[:ordered_entries].map { |e| e.cacheable_url }
end
# add any stylesheet libs from the target
- urls += (cur_target.config.javascript_libs || [])
+ urls += (cur_target.config[:javascript_libs] || [])
end
# Convert to HTML and return
@@ -122,14 +122,14 @@ def bootstrap
ret = []
# Reference any external bootstrap scripts
- if (resources_names = target.config.bootstrap)
+ if (resources_names = target.config[:bootstrap])
Array(resources_names).each do |resource_name|
ret << %(<script src="#{sc_static(resource_name)}" type="text/javascript" ></script>)
end
end
# Reference any inlined bootstrap scripts
- if (resources_names = target.config.bootstrap_inline)
+ if (resources_names = target.config[:bootstrap_inline])
Array(resources_names).each do |resource_name|
ret << inline_javascript(resource_name)
end
@@ -264,19 +264,19 @@ def loc(string, opts = {})
# theme framework, if set.
def theme_name(opts ={})
ret = opts[:default] || 'sc-theme'
- if target.config.theme_name
- ret = target.config.theme_name
- elsif target.config.theme
- if theme_target = target.target_for(target.config.theme)
- ret = theme_target.config.theme_name || ret
+ if target.config[:theme_name]
+ ret = target.config[:theme_name]
+ elsif target.config[:theme]
+ if theme_target = target.target_for(target.config[:theme])
+ ret = theme_target.config[:theme_name] || ret
end
end
return ret
end
def title(cur_target=nil)
cur_target = self.target if cur_target.nil?
- cur_target.config.title || cur_target.target_name.to_s.sub(/^\//,'').gsub(/[-_\/]/,' ').split(' ').map { |x| x.capitalize }.join(' ')
+ cur_target.config[:title] || cur_target[:target_name].to_s.sub(/^\//,'').gsub(/[-_\/]/,' ').split(' ').map { |x| x.capitalize }.join(' ')
end
private
@@ -309,13 +309,13 @@ def strings_hash(for_language)
cur_manifest.build!
# ...and find a strings entry, if there is one.
- strings_entry = cur_manifest.entries(:hidden => true).find { |e| e.entry_type == :strings }
+ strings_entry = cur_manifest.entries(:hidden => true).find { |e| e[:entry_type] == :strings }
next if strings_entry.nil?
# then load the strings
strings_entry.stage!
- next if !File.exist?(strings_entry.staging_path)
- strings_hash = YAML.load(File.read(strings_entry.staging_path))
+ next if !File.exist?(strings_entry[:staging_path])
+ strings_hash = YAML.load(File.read(strings_entry[:staging_path]))
next if strings_hash.nil? # could not load...
# if strings loaded, merge into ret...
@@ -337,7 +337,7 @@ def combined_entries(t, opts, entry_name, packed_entry_name=nil, &block)
# choose which targets to include packed and unpacked
targets = expand_required_targets(t)
- if t.config.use_packed && packed_entry_name # must pass to activate
+ if t.config[:use_packed] && packed_entry_name # must pass to activate
packed, unpacked = SC::Helpers::PackedOptimizer.optimize(targets)
unpacked << t # always use unpacked for main target
else
View
18 lib/sproutcore/models/hash_struct.rb
@@ -53,8 +53,8 @@ def initialize(opts = {})
end
# Allow for method-like access to hash also...
- def method_missing(method_name, *args)
- method_name = method_name.to_s
+ def method_missing(id, *args)
+ method_name = id.to_s
if method_name =~ /=$/
# suppoert property? = true
if method_name =~ /\?=$/
@@ -70,6 +70,15 @@ def method_missing(method_name, *args)
elsif method_name =~ /\?$/
!!self[method_name[0..-2]]
else
+ first_caller = caller.find {|str| str !~ /hash_struct\.rb/ }
+
+ unless first_caller =~ %r{spec/.*(_spec|spec_helper).rb}
+ puts "---"
+ puts method_name
+ puts first_caller
+ puts "---"
+ end
+
self[method_name]
end
end
@@ -78,13 +87,14 @@ def method_missing(method_name, *args)
def [](key)
sym_key = key.to_sym rescue nil
raise "HashStruct cannot convert #{key} to symbol" if sym_key.nil?
- fetch(sym_key, nil)
+ fetch sym_key, nil
end
def []=(key, value)
sym_key = key.to_sym rescue nil
raise "HashStruct cannot convert #{key} to symbol" if sym_key.nil?
- store(sym_key, value)
+
+ store sym_key, value
end
# Reimplement merge! to go through the []=() method so that keys can be
View
32 lib/sproutcore/models/manifest.rb
@@ -69,7 +69,7 @@ def prepared?; @is_prepared || false; end
# other_manifest = other_target.manifest_for(my_manifest.variation)
#
def variation
- return { :language => self.language }
+ return { :language => self[:language] }
end
# Builds the manifest if it has not been built yet.
@@ -175,7 +175,7 @@ def add_composite(filename, opts = {})
opts[:composite] = true
@entries << (ret = ManifestEntry.new(self, opts)).prepare!
- ret.source_entries.each { |entry| entry.hide! } if should_hide_entries
+ ret[:source_entries].each { |entry| entry.hide! } if should_hide_entries
return ret
end
@@ -210,14 +210,14 @@ def add_transform(entry, opts ={})
# 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)
+ 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)
+ 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)
+ opts[:cache_path] ||= unique_cache_path(entry[:cache_path])
# copy other useful entries
opts.source_entry = entry
@@ -226,13 +226,13 @@ def add_transform(entry, opts ={})
opts.transform = true # make .transform? = true
# Normalize to new extension if provided. else copy ext from entry...
- if opts.ext
+ if opts[:ext]
%w(filename build_path staging_path url).each do |key|
- opts[key] = opts[key].ext(opts.ext)
+ opts[key] = opts[key].ext(opts[:ext])
end
- opts.ext = opts.ext.to_s
+ opts[:ext] = opts[:ext].to_s
else
- opts.ext = entry.ext
+ opts[:ext] = entry[:ext]
end
# Create new entry and hide old one
@@ -285,7 +285,7 @@ def entry_for(filename, opts = {})
end
manifest.entries(:hidden => opts[:hidden]).find do |entry|
- (entry.filename == filename) && entry.has_options?(opts)
+ (entry[:filename] == filename) && entry.has_options?(opts)
end
end
@@ -321,8 +321,8 @@ def find_entry(fragment, opts = {}, seen=nil)
# look on our own target only if target is named
ret = cur_manifest.entries(:hidden => opts[:hidden]).reject do |entry|
if entry.has_options?(opts)
- entry_extname = File.extname(entry.filename)
- entry_rootname = entry.filename.sub(/#{entry_extname}$/,'')
+ entry_extname = File.extname(entry[:filename])
+ entry_rootname = entry[:filename].sub(/#{entry_extname}$/,'')
ext_match = (extname.nil? || extname.size == 0) || (entry_extname == extname)
else
ext_match = false
@@ -351,7 +351,7 @@ def find_entry(fragment, opts = {}, seen=nil)
# Finds a unique staging path starting with the root proposed staging
# path.
def unique_staging_path(path)
- paths = entries(:hidden => true).map { |e| e.staging_path }
+ paths = entries(:hidden => true).map { |e| e[:staging_path] }
while paths.include?(path)
path = path.sub(/(__\$[0-9]+)?(\.\w+)?$/,"__#{next_staging_uuid}\\2")
end
@@ -361,7 +361,7 @@ def unique_staging_path(path)
# Finds a unique cache path starting with the root proposed staging
# path.
def unique_cache_path(path)
- paths = entries(:hidden => true).map { |e| e.cache_path }
+ paths = entries(:hidden => true).map { |e| e[:cache_path] }
while paths.include?(path)
path = path.sub(/(__\$[0-9]+)?(\.\w+)?$/,"__#{next_staging_uuid}\\2")
end
@@ -371,7 +371,7 @@ def unique_cache_path(path)
protected
def next_staging_uuid
- self.staging_uuid = (self.staging_uuid || 0) + 1
+ self[:staging_uuid] = (self[:staging_uuid] || 0) + 1
end
end
View
60 lib/sproutcore/models/manifest_entry.rb
@@ -128,9 +128,9 @@ def timestamp
timestamps.max
elsif composite?
- source_entries.map { |e| e.timestamp || 0 }.max || Time.now.to_i
+ self[:source_entries].map { |e| e.timestamp || 0 }.max || Time.now.to_i
else
- File.exist?(source_path) ? File.mtime(source_path).to_i : 0
+ File.exist?(self[:source_path]) ? File.mtime(self[:source_path]).to_i : 0
end
end
@@ -139,9 +139,9 @@ def timestamp
# assigned domain name prepended if hyper-domaining is turned on. Otherwise
# returns the URL itself.
def cacheable_url
- ret = self.url
- ret = [ret, self.timestamp].join('?') if target.config.timestamp_urls
- if target.config.hyper_domaining
+ ret = self[:url]
+ ret = [ret, self.timestamp].join('?') if target.config[:timestamp_urls]
+ if target.config[:hyper_domaining]
ret = [self.hyperdomain_prefix(ret), ret].join('')
end
return ret
@@ -167,11 +167,11 @@ def hyperdomain_prefix(url)
# entry.extract_content(/require\((.+)\)/) { |line| $1 }
#
def scan_source(regexp, &block)
- if entries = self.source_entries
+ if entries = self[:source_entries]
entries.each { |entry| entry.stage! }
end
- if paths = self.source_paths
+ if paths = self[:source_paths]
paths.each do |path|
next unless File.exist?(path)
@@ -205,17 +205,17 @@ def discover_build_directives!
target.begin_attr_changes
self.required = []
- entry = self.transform? ? self.source_entry : self
+ entry = self.transform? ? self[:source_entry] : self
entry.scan_source(BUILD_DIRECTIVES_REGEX) do |matches|
# strip off any file ext
filename = matches[2].ext ''
case matches[0]
when 'sc_require'
- self.required << filename
+ self[:required] << filename
when 'require'
- self.required << filename
+ self[:required] << filename
when 'sc_resource'
- self.resource = filename
+ self[:resource] = filename
end
end
@@ -230,13 +230,13 @@ def discover_build_directives!
# Invokes the entry's build task to build to its build path. If the
# entry has source entries, they will be staged first.
def build!
- build_to self.build_path
+ build_to self[:build_path]
end
# Builds an entry into its staging path. This method can be invoked on
# any entry whose output is required by another entry to be built.
def stage!
- build_to self.staging_path
+ build_to self[:staging_path]
end
# Removes the build and staging files for this entry so the next
@@ -245,23 +245,23 @@ def stage!
# === Returns
# self
def clean!
- FileUtils.rm(self.build_path) if File.exist?(self.build_path)
- FileUtils.rm(self.staging_path) if File.exist?(self.staging_path)
+ FileUtils.rm(self[:build_path]) if File.exist?(self[:build_path])
+ FileUtils.rm(self[:staging_path]) if File.exist?(self[:staging_path])
return self
end
# Diagnostic function. Indicates what will happen if you called build
def inspect_build_state
- inspect_build_to self.build_path
+ inspect_build_to self[:build_path]
end
def inspect_staging_state
- inspect_build_to self.staging_path
+ inspect_build_to self[:staging_path]
end
def inline_contents
- unless File.exists?(self.staging_path)
+ unless File.exists?(self[:staging_path])
# stage source entries if needed...
(self.source_entries || []).each { |e| e.stage! } if composite?
@@ -278,11 +278,11 @@ def inline_contents
:target => self.manifest.target,
:config => self.manifest.target.config,
:project => self.manifest.target.project,
- :src_path => self.source_path,
- :src_paths => self.source_paths,
- :dst_path => self.staging_path
- end
- File.readlines(self.staging_path)
+ :src_path => self[:source_path],
+ :src_paths => self[:source_paths],
+ :dst_path => self[:staging_path]
+ end
+ File.readlines(self[:staging_path])
end
private
@@ -305,27 +305,27 @@ def inspect_build_to(dst_path)
end
def build_to(dst_path)
- if self.build_task.nil?
+ if self[:build_task].nil?
raise "no build task defined for #{self.filename}"
end
# stage source entries if needed...
- (self.source_entries || []).each { |e| e.stage! } if composite?
+ (self[:source_entries] || []).each { |e| e.stage! } if composite?
# get build task and build it
buildfile = manifest.target.buildfile
- if !buildfile.task_defined?(self.build_task)
- raise "Could not build entry #{self.filename} because build task '#{self.build_task}' is not defined"
+ if !buildfile.task_defined?(self[:build_task])
+ raise "Could not build entry #{self[:filename]} because build task '#{self[:build_task]}' is not defined"
end
- buildfile.invoke self.build_task,
+ buildfile.invoke self[:build_task],
:entry => self,
:manifest => self.manifest,
:target => self.manifest.target,
:config => self.manifest.target.config,
:project => self.manifest.target.project,
- :src_path => self.source_path,
- :src_paths => self.source_paths,
+ :src_path => self[:source_path],
+ :src_paths => self[:source_paths],
:dst_path => dst_path
return self
View
6 lib/sproutcore/models/project.rb
@@ -210,7 +210,7 @@ def find_targets_for(root_path, root_name, config)
# look for directories matching the target_types keys and create target
# with target_types value as type. -- normalize to lowercase string
target_types = {}
- (config.target_types || {}).each do |key, value|
+ (config[:target_types] || {}).each do |key, value|
target_types[key.to_s.downcase] = value
end
@@ -232,7 +232,7 @@ def find_targets_for(root_path, root_name, config)
# if target's config allows nested targets, then call recursively
# asking the target's config allows the target's Buildfile to
# override the default.
- if target.config.allow_nested_targets
+ if target.config[:allow_nested_targets]
find_targets_for(source_root, target_name, target.config)
end
end # Dir.glob
@@ -258,7 +258,7 @@ def generator_for(generator_name, opts={})
# is how we inherit inherit targets from a parent project.
def dup_targets(to_dup)
to_dup.each do | target_name, target |
- add_target target_name, target.target_type, target.to_hash
+ add_target target_name, target[:target_type], target.to_hash
end
end
View
121 lib/sproutcore/models/target.rb
@@ -41,6 +41,13 @@ module SC
# entirely synthesized from other sources.
#
class Target < HashStruct
+ def source_root
+ self[:source_root]
+ end
+
+ def project
+ self[:project]
+ end
def initialize(target_name, target_type, opts={})
# Add target_name & type of options so they can be enumerated as part
@@ -96,7 +103,7 @@ def prepared?; @is_prepared || false; end
# Buildfile
#
def buildfile
- @buildfile ||= parent_target.buildfile.dup.for_target(self).load!(self.source_root)
+ @buildfile ||= parent_target.buildfile.dup.for_target(self).load!(source_root)
end
# Returns the config for the current project. The config is computed by
@@ -106,7 +113,7 @@ def buildfile
#
# This is the config hash you should use to control how items are built.
def config
- return @config ||= buildfile.config_for(target_name, SC.build_mode).merge(SC.env)
+ return @config ||= buildfile.config_for(self[:target_name], SC.build_mode).merge(SC.env)
end
# Clears the cached config, reloading it from the buildfile again. This
@@ -152,33 +159,33 @@ def required_targets(opts={})
return ret unless ret.nil?
# else compute return value, respecting options
- ret = [config.required]
- if opts[:debug] && config.debug_required
- ret << config.debug_required
+ ret = [config[:required]]
+ if opts[:debug] && config[:debug_required]
+ ret << config[:debug_required]
end
- if opts[:test] && config.test_required
- ret << config.test_required
+ if opts[:test] && config[:test_required]
+ ret << config[:test_required]
end
- if opts_design && config.design_required
- ret << config.design_required
+ if opts_design && config[:design_required]
+ ret << config[:design_required]
end
- if opts[:theme] && self.loads_theme? && config.theme
+ if opts[:theme] && self.loads_theme? && config[:theme]
# verify theme is a theme target type - note that if no matching
# target is found, we'll just let this go through so the standard
# not found warning can show.
- t = target_for(config.theme)
- if t && t.target_type != :theme
- SC.logger.warn "Target #{config.theme} was set as theme for #{target_name} but it is not a theme."
+ t = target_for(config[:theme])
+ if t && t[:target_type] != :theme
+ SC.logger.warn "Target #{config[:theme]} was set as theme for #{self[:target_name]} but it is not a theme."
else
- ret << config.theme
+ ret << config[:theme]
end
end
ret = ret.flatten.compact.map do |n|
if (t = target_for(n)).nil?
- SC.logger.warn "Could not find target #{n} that is required by #{target_name}"
+ SC.logger.warn "Could not find target #{n} that is required by #{self[:target_name]}"
end
t
end
@@ -215,22 +222,22 @@ def dynamic_required_targets(opts={})
return ret unless ret.nil?
# else compute return value, respecting options
- ret = [config.dynamic_required]
- if opts[:debug] && config.debug_dynamic_required
- ret << config.debug_dynamic_required
+ ret = [config[:dynamic_required]]
+ if opts[:debug] && config[:debug_dynamic_required]
+ ret << config[:debug_dynamic_required]
end
- if opts[:test] && config.test_dynamic_required
- ret << config.test_dynamic_required
+ if opts[:test] && config[:test_dynamic_required]
+ ret << config[:test_dynamic_required]
end
- if opts[:theme] && self.loads_theme? && config.theme
+ if opts[:theme] && self.loads_theme? && config[:theme]
# verify theme is a theme target type - note that if no matching
# target is found, we'll just let this go through so the standard
# not found warning can show.
- t = target_for(config.theme)
- if t && t.target_type != :theme
- SC.logger.warn "Target #{config.theme} was set as theme for #{target_name} but it is not a theme."
+ t = target_for(config[:theme])
+ if t && t[:target_type] != :theme
+ SC.logger.warn "Target #{config[:theme]} was set as theme for #{target_name} but it is not a theme."
else
- ret << config.theme
+ ret << config[:theme]
end
end
@@ -251,7 +258,7 @@ def dynamic_required_targets(opts={})
# the value yourself.
def loads_theme?;
ret = self[:loads_theme]
- ret.nil? ? (target_type == :app) : ret
+ ret.nil? ? (self[:target_type] == :app) : ret
end
# Returns the expanded list of required targets, ordered as they actually
@@ -289,7 +296,7 @@ def _expand_required_targets(opts, seen)
# according to the target's current config.
def target_directory?(path, root_path=nil)
root_path = self.source_root if root_path.nil?
- @target_names ||= self.config.target_types.keys
+ @target_names ||= self.config[:target_types].keys
path = path.to_s.sub /^#{Regexp.escape root_path}\//, ''
@target_names.each do |name|
return true if path =~ /^#{Regexp.escape name.to_s}/
@@ -299,7 +306,7 @@ def target_directory?(path, root_path=nil)
# path to attr_cache file
def file_attr_cache_path
- @file_attr_cache_path ||= (self.cache_root / '__file_attr_cache.yml')
+ @file_attr_cache_path ||= (self[:cache_root] / '__file_attr_cache.yml')
end
# suspend writing the file cache out if needed
@@ -386,13 +393,13 @@ def compute_build_number(seen=nil, opts = {})
build_number = nil if opts[:force]
# Look for a global build_numbers hash and try that
- if (build_numbers = config.build_numbers)
- build_number = build_numbers[target_name.to_s] || build_numbers[target_name.to_sym]
+ if (build_numbers = config[:build_numbers])
+ build_number = build_numbers[self[:target_name].to_s] || build_numbers[self[:target_name].to_sym]
end
# Otherwise, use config build number specifically for this target, if
# specified
- build_number ||= config.build_number
+ build_number ||= config[:build_number]
# Otherwise, actually compute a build number.
if build_number.nil?
@@ -421,7 +428,7 @@ def compute_build_number(seen=nil, opts = {})
seen ||= []
_targets = required_targets(:theme => true).sort do |a,b|
- (a.target_name||'').to_s <=> (b.target_name||'').to_s
+ (a[:target_name]||'').to_s <=> (b[:target_name]||'').to_s
end
_targets.each do |ct|
@@ -475,50 +482,50 @@ def manifest_for(variation={})
# target_name must still be added, but we'll never use the actual contents
# and don't need to waste bandwidth downloading it.
def bundle_info(opts ={})
- if target_type == :app
+ if self[:target_type] == :app
raise "bundle_info called on an app target"
else
requires = required_targets(opts) # only go one-level deep!
# Targets that aren't pre-loaded can't be packed together. That leaves
# loading css and js individually and/or loading the combined or
# minified css and js.
- combine_css = config.combine_stylesheets
- combine_js = config.combine_javascript
- minify_css = config.minify_css
- minify_css = config.minify if minify_css.nil?
- minify_js = config.minify_javascript
- minify_js = config.minify if minify_js.nil?
- pack_css = config.use_packed
- pack_js = config.use_packed
+ combine_css = config[:combine_stylesheets]
+ combine_js = config[:combine_javascript]
+ minify_css = config[:minify_css]
+ minify_css = config[:minify] if minify_css.nil?
+ minify_js = config[:minify_javascript]
+ minify_js = config[:minify] if minify_js.nil?
+ pack_css = config[:use_packed]
+ pack_js = config[:use_packed]
# sort entries...
css_entries = {}
javascript_entries = {}
manifest_for(opts[:variation]).build!.entries.each do |entry|
- if entry.resource.nil?
- entry.resource = ''
+ if entry[:resource].nil?
+ entry[:resource] = ''
end
# look for CSS or JS type entries
- case entry.entry_type
+ case entry[:entry_type]
when :css
- (css_entries[entry.resource] ||= []) << entry
+ (css_entries[entry[:resource]] ||= []) << entry
when :javascript
- (javascript_entries[entry.resource] ||= []) << entry
+ (javascript_entries[entry[:resource]] ||= []) << entry
end
end
css_urls = []
css_entries.each do |resource_name, entries|
SC::Helpers::EntrySorter.sort(entries).each do |entry|
- if minify_css && entry.minified
+ if minify_css && entry[:minified]
css_urls << entry.cacheable_url
- elsif pack_css && entry.packed && !entry.minified
+ elsif pack_css && entry[:packed] && !entry[:minified]
css_urls << entry.cacheable_url
- elsif combine_css && entry.combined && !entry.packed && !entry.minified
+ elsif combine_css && entry[:combined] && !entry[:packed] && !entry[:minified]
css_urls << entry.cacheable_url
- elsif !entry.combined && !entry.packed && !entry.minified
+ elsif !entry[:combined] && !entry[:packed] && !entry[:minified]
css_urls << entry.cacheable_url
end
end
@@ -529,13 +536,13 @@ def bundle_info(opts ={})
resource_name = resource_name.ext('js')
pf = (resource_name == 'javascript.js') ? %w(source/lproj/strings.js source/core.js source/utils.js) : []
SC::Helpers::EntrySorter.sort(entries, pf).each do |entry|
- if minify_js && entry.minified
+ if minify_js && entry[:minified]
js_urls << entry.cacheable_url
- elsif pack_js && entry.packed && !entry.minified
+ elsif pack_js && entry[:packed] && !entry[:minified]
js_urls << entry.cacheable_url
- elsif combine_js && entry.combined && !entry.packed && !entry.minified
+ elsif combine_js && entry[:combined] && !entry[:packed] && !entry[:minified]
js_urls << entry.cacheable_url
- elsif !entry.combined && !entry.packed && !entry.minified
+ elsif !entry[:combined] && !entry[:packed] && !entry[:minified]
js_urls << entry.cacheable_url
end
end
@@ -561,7 +568,7 @@ def bundle_info(opts ={})
def parent_target
return @parent_target unless @parent_target.nil?
return nil if project.nil?
- tname = target_name
+ tname = self[:target_name]
while @parent_target.nil?
tname = tname.to_s.sub(/\/[^\/]+$/,'')
@parent_target = (tname.size>0) ? project.target_for(tname) : project
@@ -592,7 +599,7 @@ def target_for(target_name)
else # relative target...
# look for any targets that are children of this target
- ret = project.target_for([self.target_name, target_name].join('/'))
+ ret = project.target_for([self[:target_name], target_name].join('/'))
# Ask my parent target to look for the target, and so on.
if ret.nil?
@@ -616,7 +623,7 @@ def installed_languages
next unless path =~ /\/([^\/]+)\.lproj/
(LONG_LANGUAGE_MAP[$1.downcase.to_sym] || $1).to_s
end
- ret << config.preferred_language.to_s if config.preferred_language
+ ret << config[:preferred_language].to_s if config[:preferred_language]
ret.compact.uniq.sort { |a,b| a.downcase <=> b.downcase }.map { |l| l.to_sym }
end
View
24 lib/sproutcore/rack/builder.rb
@@ -81,7 +81,6 @@ def initialize(project)
# Main entry point for this Rack application. Returns 404 if no
# matching entry could be found in the project.
def call(env)
-
# define local variables so they will survive the mutext contexts
# below...
ret = url = target = language = cacheable = manifest = entry = nil
@@ -113,14 +112,14 @@ def call(env)
manifest = target.manifest_for(:language => language).build!
# lookup entry by url
- unless entry = manifest.entries.find { |e| e.url == url }
+ unless entry = manifest.entries.find { |e| e[:url] == url }
ret = not_found("No matching entry in target")
end
end
if ret.nil?
- build_path = entry.build_path
- if [:html, :test].include?(entry.entry_type)
+ build_path = entry[:build_path]
+ if [:html, :test].include?(entry[:entry_type])
#if did_reload || !File.exist?(build_path)
#always clean html files...
entry.clean!.build!
@@ -142,7 +141,7 @@ def call(env)
return not_found("File could not build (entry: #{entry.filename} - build_path: #{build_path}")
end
- SC.logger.info "Serving #{target.target_name.to_s.sub(/^\//,'')}:#{entry.filename}"
+ SC.logger.info "Serving #{target[:target_name].to_s.sub(/^\//,'')}:#{entry[:filename]}"
# define response headers
file_size = File.size(build_path)
@@ -183,7 +182,7 @@ def reload_project!
monitor_project!
# don't reload if no project or is disabled
- return false if @project.nil? || !@project.config.reload_project
+ return false if @project.nil? || !@project.config[:reload_project]
_did_reload = false
@@ -259,9 +258,10 @@ def target_for(url)
# target.
url_parts = url.split '/'
ret = nil
+
while url_parts.size>0 && ret.nil?
url = url_parts.join '/'
- ret = targets.find { |t| t.url_root == url || t.index_root == url }
+ ret = targets.find { |t| t[:url_root] == url || t[:index_root] == url }
url_parts.pop
end
return ret
@@ -294,27 +294,27 @@ def normalize_url(url, target)
# /foo/en - /foo/en/index.html
# /foo/en/build_number - /foo/en/build_number/index.html
# /foo/en/CURRENT/resource-name
- matched = url.match(/^#{Regexp.escape target.index_root}(\/([^\/\.]+))?(\/([^\/\.]+))?(\/(.*))?$/)
+ matched = url.match(/^#{Regexp.escape target[:index_root]}(\/([^\/\.]+))?(\/([^\/\.]+))?(\/(.*))?$/)
unless matched.nil?
- matched_language = matched[2] || target.config.preferred_language
+ matched_language = matched[2] || target.config[:preferred_language]
matched_build_number = matched[4]
if matched_build_number.blank? || matched_build_number == 'current'
- matched_build_number = target.build_number
+ matched_build_number = target[:build_number]
end
resource_name = matched[6]
resource_name = 'index.html' if resource_name.blank?
# convert to url root based
- url = [target.url_root, matched_language, matched_build_number,
+ url = [target[:url_root], matched_language, matched_build_number,
resource_name] * '/'
cacheable = false # index_root based urls are not cacheable
# otherwise, just get the language -- url_root-based urls must be
# fully qualified
else
- matched = url.match(/^#{Regexp.escape target.url_root}\/([^\/\.]+)/)
+ matched = url.match(/^#{Regexp.escape target[:url_root]}\/([^\/\.]+)/)
matched_language = matched ? matched[1] : nil
end
View
25 lib/sproutcore/rack/service.rb
@@ -119,34 +119,35 @@ def middleware_for(project)
# setup some conditional items...
config = project.config
- #if config.serve_test_runner || config.serve_docs
- apps << SC::Rack::Dev.new(project)
- #end
-
- # Add builder for the project itself
- apps << SC::Rack::Builder.new(project)
# serve files out of the public directory if serve_public is
# configures && the public directory exists
- if config.serve_public
+ if config[:serve_public]
pubdir = File.join(project.project_root, 'public')
apps << ::Rack::File.new(pubdir) if File.directory?(pubdir)
end
- if project.buildfile.proxies.size > 0
- apps << SC::Rack::Proxy.new(project)
- end
-
if self.filesystem
apps << SC::Rack::Filesystem.new(project)
end
+ #if config.serve_test_runner || config.serve_docs
+ apps << SC::Rack::Dev.new(project)
+ #end
+
+ # Add builder for the project itself
+ apps << SC::Rack::Builder.new(project)
+
+ if project.buildfile.proxies.size > 0
+ apps << SC::Rack::Proxy.new(project)
+ end
+
# Wrap'em in a cascade if needed. This will return the first
# app that does not return nil
app = apps.size == 1 ? apps.first : ::Rack::Cascade.new(apps)
# Add show exceptions handler if enabled
- app = ::Rack::ShowExceptions.new(app) if config.serve_exceptions
+ app = ::Rack::ShowExceptions.new(app) if config[:serve_exceptions]
return app # done!
end
View
10 lib/sproutcore/tools.rb
@@ -98,21 +98,21 @@ def options; @tool_options ||= HashStruct.new(super); end
# Configure the expected log level and log target. Handles the
# --verbose, --very-verbose and --logfile options
def prepare_logger!
- SC.env.log_level = options['very-verbose'] ? :debug : (options.verbose ? :info : :warn)
- SC.env.logfile = File.expand_path(options.logfile) if options.logfile
+ SC.env[:log_level] = options['very-verbose'] ? :debug : (options[:verbose] ? :info : :warn)
+ SC.env[:logfile] = File.expand_path(options[:logfile]) if options[:logfile]
end
# Configure the current build mode. Handles the --mode and
# --environment options. (--environment is provided for backwards
# compatibility)
def prepare_mode!(preferred_mode = 'production')
- build_mode = (options.mode || options.environment || preferred_mode).to_s.downcase.to_sym
+ build_mode = (options[:mode] || options[:environment] || preferred_mode).to_s.downcase.to_sym
SC.build_mode = build_mode
end
# Configure the current build numbers. Handles the --build option.
def prepare_build_numbers!
- return unless (numbers = options.build)
+ return unless (numbers = options[:build])
numbers = numbers.split(',').map { |n| n.split(':') }
if numbers.size==1 && numbers.first.size==1
SC.env.build_number = numbers.first.first
@@ -148,7 +148,7 @@ def project
@discovered_project = true
ret = nil
- project_path = options.project || options.library
+ project_path = options[:project] || options[:library]
# if no project_path is named explicitly, attempt to autodiscover from
# working dir. If none is found, just set project to nil
View
4 lib/sproutcore/tools/build.rb
@@ -88,9 +88,7 @@ def build(*targets)
end
if $to_minify.length > 0
- yui_root = File.expand_path(File.join(LIBPATH, '..', 'vendor', 'yui-compressor'))
- jar_path = File.join(yui_root, 'SCyuicompressor-2.4.2.jar')
- filecompress = "java -jar " + jar_path + " --charset utf-8 --line-break 80 " + $to_minify * ' ' + " 2>&1"
+ filecompress = "java -jar " + SC.yui_jar + " --charset utf-8 --line-break 80 " + $to_minify * ' ' + " 2>&1"
SC.logger.info 'Compressing with YUI...'
output = `#{filecompress}` # It'd be nice to just read STDERR, but
View
2 lib/sproutcore/tools/build_number.rb
@@ -16,7 +16,7 @@ class Tools
desc "build-number TARGET", "Computes a build number for the target"
def build_number(*targets)
target = requires_target!(*targets)
- $stdout << target.prepare!.build_number
+ $stdout << target.prepare![:build_number]
end
end
View
6 lib/sproutcore/tools/server.rb
@@ -19,14 +19,14 @@ class Tools
def server
prepare_mode!('debug') # set mode again, using debug as default
- SC.env.build_prefix = options.buildroot if options.buildroot
- SC.env.staging_prefix = options.stageroot if options.stageroot
+ SC.env[:build_prefix] = options[:buildroot] if options[:buildroot]
+ SC.env[:staging_prefix] = options[:stageroot] if options[:stageroot]
# get project and start service.
project = requires_project!
# start shell if passed
- if options.irb
+ if options[:irb]
require 'irb'
require 'irb/completion'
if File.exists? ".irbrc"

0 comments on commit 0cc2392

Please sign in to comment.
Something went wrong with that request. Please try again.