Skip to content
Browse files

Allow resources to be inlined in the HTML. Convert the current bootst…

…rap code to a directly inlined JS. This way it can be minified.
  • Loading branch information...
1 parent 5fe5d37 commit 8642d3e35f97fb0a25e0da801a1743bd1b3e9b3b Charles Jolley committed Sep 29, 2009
Showing with 89 additions and 2 deletions.
  1. +3 −0 Buildfile
  2. +84 −0 lib/sproutcore/helpers/static_helper.rb
  3. +2 −2 lib/sproutcore/models/manifest.rb
View
3 Buildfile
@@ -73,6 +73,9 @@ mode :all do
# frameworks automatically if found.
:theme => 'sproutcore/standard_theme',
+ # use default bootstrap framework
+ :bootstrap_inline => 'sproutcore/bootstrap:javascript',
+
:use_packed => true,
# if set to true then the index.html will build into the global language
View
84 lib/sproutcore/helpers/static_helper.rb
@@ -115,6 +115,90 @@ def javascripts_for_client(target_name = nil, opts = {})
urls.join("\n")
end
+ # Detects and includes any bootstrap code
+ #
+ def bootstrap
+
+ ret = []
+
+ # Reference any external bootstrap scripts
+ 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)
+ Array(resources_names).each do |resource_name|
+ ret << inline_javascript(resource_name)
+ end
+ end
+
+ # Reference any @content_for_bootstrap
+ if @content_for_bootstrap
+ ret << %(<script type="text/javascript">\n#{@content_for_bootstrap}\n</script>)
+ end
+
+ return ret * "\n"
+ end
+
+ # Attempts to include the named javascript entry inline to the file
+ #
+ # === Options
+ # language:: the language to use. defaults to current
+ #
+ def inline_javascript(resource_name, opts ={})
+
+ resource_name = resource_name.to_s
+
+ # determine which manifest to search. if a language is explicitly
+ # specified, lookup manifest for that language. otherwise use
+ # current manifest.
+ m = self.manifest
+ if opts[:language]
+ m = target.manifest_for(:language => opts[:language]).build!
+ end
+
+ entry = m.find_entry(resource_name, :entry_type => :javascript)
+ if entry.nil?
+ entry = m.find_entry(resource_name, :hidden => true, :entry_type => :javascript)
+ end
+
+ return '' if entry.nil?
+
+ ret = File.readlines(entry.build!.build_path)*''
+ return %(<script type="text/javascript">\n#{ret}\n</script>)
+ end
+
+ # Attempts to include the named javascript entry inline to the file
+ #
+ # === Options
+ # language:: the language to use. defaults to current
+ #
+ def inline_stylesheet(resource_name, opts ={})
+
+ resource_name = resource_name.to_s
+
+ # determine which manifest to search. if a language is explicitly
+ # specified, lookup manifest for that language. otherwise use
+ # current manifest.
+ m = self.manifest
+ if opts[:language]
+ m = target.manifest_for(:language => opts[:language]).build!
+ end
+
+ entry = m.find_entry(resource_name, :entry_type => :stylesheet)
+ if entry.nil?
+ entry = m.find_entry(resource_name, :hidden => true, :entry_type => :stylesheet)
+ end
+
+ return '' if entry.nil?
+
+ ret = File.readlines(entry.build!.build_path)
+ return %(<style>\n#{ret*"\n"}\n</style>)
+ end
+
# Attempts to render the named entry as a partial
#
# === Options
View
4 lib/sproutcore/models/manifest.rb
@@ -350,7 +350,7 @@ def find_entry(fragment, opts = {}, seen=nil)
def unique_staging_path(path)
paths = entries(:hidden => true).map { |e| e.staging_path }
while paths.include?(path)
- path = path.sub(/(__\$[0-9]+)?(\.\w+)?$/,"__$#{next_staging_uuid}\\2")
+ path = path.sub(/(__\$[0-9]+)?(\.\w+)?$/,"__#{next_staging_uuid}\\2")
end
return path
end
@@ -360,7 +360,7 @@ def unique_staging_path(path)
def unique_cache_path(path)
paths = entries(:hidden => true).map { |e| e.cache_path }
while paths.include?(path)
- path = path.sub(/(__\$[0-9]+)?(\.\w+)?$/,"__$#{next_staging_uuid}\\2")
+ path = path.sub(/(__\$[0-9]+)?(\.\w+)?$/,"__#{next_staging_uuid}\\2")
end
return path
end

0 comments on commit 8642d3e

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