0
@@ -209,6 +209,10 @@ module ActionView
0
# Note that the default javascript files will be included first. So Prototype and Scriptaculous are available to
0
# all subsequently included files.
0
+ # If you want Rails to search in all the subdirectories under javascripts, you should explicitly set <tt>:recursive</tt>:
0
+ # javascript_include_tag :all, :recursive => true
0
# == Caching multiple javascripts into one
0
# You can also cache multiple javascripts into one file, which requires less HTTP connections to download and can better be
0
@@ -235,18 +239,23 @@ module ActionView
0
# javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is true =>
0
# <script type="text/javascript" src="/javascripts/shop.js"></script>
0
+ # The <tt>:recursive</tt> option is also available for caching:
0
+ # javascript_include_tag :all, :cache => true, :recursive => true
0
def javascript_include_tag(*sources)
0
options = sources.extract_options!.stringify_keys
0
cache = options.delete("cache")
0
+ recursive = options.delete("recursive")
0
if ActionController::Base.perform_caching && cache
0
joined_javascript_name = (cache == true ? "all" : cache) + ".js"
0
joined_javascript_path = File.join(JAVASCRIPTS_DIR, joined_javascript_name)
0
- write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources
)) unless File.exists?(joined_javascript_path)
0
+ write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources
, recursive)) unless File.exists?(joined_javascript_path)
0
javascript_src_tag(joined_javascript_name, options)
0
- expand_javascript_sources(sources
).collect { |source| javascript_src_tag(source, options) }.join("\n")
0
+ expand_javascript_sources(sources
, recursive).collect { |source| javascript_src_tag(source, options) }.join("\n")
0
@@ -332,13 +341,17 @@ module ActionView
0
# <link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />
0
# <link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />
0
- # You can also include all styles in the stylesheet
directory using <tt>:all</tt> as the source:
0
+ # You can also include all styles in the stylesheet
s directory using <tt>:all</tt> as the source:
0
# stylesheet_link_tag :all # =>
0
# <link href="/stylesheets/style1.css" media="screen" rel="stylesheet" type="text/css" />
0
# <link href="/stylesheets/styleB.css" media="screen" rel="stylesheet" type="text/css" />
0
# <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" type="text/css" />
0
+ # If you want Rails to search in all the subdirectories under stylesheets, you should explicitly set <tt>:recursive</tt>:
0
+ # stylesheet_link_tag :all, :recursive => true
0
# == Caching multiple stylesheets into one
0
# You can also cache multiple stylesheets into one file, which requires less HTTP connections and can better be
0
@@ -362,18 +375,23 @@ module ActionView
0
# stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true =>
0
# <link href="/stylesheets/payment.css" media="screen" rel="stylesheet" type="text/css" />
0
+ # The <tt>:recursive</tt> option is also available for caching:
0
+ # stylesheet_link_tag :all, :cache => true, :recursive => true
0
def stylesheet_link_tag(*sources)
0
options = sources.extract_options!.stringify_keys
0
cache = options.delete("cache")
0
+ recursive = options.delete("recursive")
0
if ActionController::Base.perform_caching && cache
0
joined_stylesheet_name = (cache == true ? "all" : cache) + ".css"
0
joined_stylesheet_path = File.join(STYLESHEETS_DIR, joined_stylesheet_name)
0
- write_asset_file_contents(joined_stylesheet_path, compute_stylesheet_paths(sources
)) unless File.exists?(joined_stylesheet_path)
0
+ write_asset_file_contents(joined_stylesheet_path, compute_stylesheet_paths(sources
, recursive)) unless File.exists?(joined_stylesheet_path)
0
stylesheet_tag(joined_stylesheet_name, options)
0
- expand_stylesheet_sources(sources
).collect { |source| stylesheet_tag(source, options) }.join("\n")
0
+ expand_stylesheet_sources(sources
, recursive).collect { |source| stylesheet_tag(source, options) }.join("\n")
0
@@ -556,18 +574,19 @@ module ActionView
0
tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(path_to_stylesheet(source)) }.merge(options), false, false)
0
- def compute_javascript_paths(sources)
0
- expand_javascript_sources(sources).collect { |source| compute_public_path(source, 'javascripts', 'js', false) }
0
+ def compute_javascript_paths(*args)
0
+ expand_javascript_sources(*args).collect { |source| compute_public_path(source, 'javascripts', 'js', false) }
0
- def compute_stylesheet_paths(sources)
0
- expand_stylesheet_sources(sources).collect { |source| compute_public_path(source, 'stylesheets', 'css', false) }
0
+ def compute_stylesheet_paths(*args)
0
+ expand_stylesheet_sources(*args).collect { |source| compute_public_path(source, 'stylesheets', 'css', false) }
0
- def expand_javascript_sources(sources
)
0
+ def expand_javascript_sources(sources
, recursive = false)
0
if sources.include?(:all)
0
- all_javascript_files = Dir[File.join(JAVASCRIPTS_DIR, '*.js')].collect { |file| File.basename(file).gsub(/\.\w+$/, '') }.sort
0
- @@all_javascript_sources ||= ((determine_source(:defaults, @@javascript_expansions).dup & all_javascript_files) + all_javascript_files).uniq
0
+ all_javascript_files = collect_asset_files(JAVASCRIPTS_DIR, ('**' if recursive), '*.js')
0
+ @@all_javascript_sources ||= {}
0
+ @@all_javascript_sources[recursive] ||= ((determine_source(:defaults, @@javascript_expansions).dup & all_javascript_files) + all_javascript_files).uniq
0
expanded_sources = sources.collect do |source|
0
determine_source(source, @@javascript_expansions)
0
@@ -577,9 +596,10 @@ module ActionView
0
- def expand_stylesheet_sources(sources
)
0
+ def expand_stylesheet_sources(sources
, recursive)
0
if sources.first == :all
0
- @@all_stylesheet_sources ||= Dir[File.join(STYLESHEETS_DIR, '*.css')].collect { |file| File.basename(file).gsub(/\.\w+$/, '') }.sort
0
+ @@all_stylesheet_sources ||= {}
0
+ @@all_stylesheet_sources[recursive] ||= collect_asset_files(STYLESHEETS_DIR, ('**' if recursive), '*.css')
0
sources.collect do |source|
0
determine_source(source, @@stylesheet_expansions)
0
@@ -604,6 +624,14 @@ module ActionView
0
FileUtils.mkdir_p(File.dirname(joined_asset_path))
0
File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
0
+ def collect_asset_files(*path)
0
+ Dir[File.join(*path.compact)].collect do |file|
0
+ file[-(file.size - dir.size - 1)..-1].sub(/\.\w+$/, '')
Comments
No one has commented yet.