Module: ApplicationHelper
- Defined in:
- lib/templates/app/helpers/application_helper.rb
Instance Method Summary collapse
- #asset_file_path2(path) ⇒ Object
- #asset_file_path2!(path) ⇒ Object
- #collect_gem_js ⇒ Object
- #collect_js(*patterns) ⇒ Object
- #compute_javascript_paths2(*args) ⇒ Object
- #compute_stylesheet_paths2(*args) ⇒ Object
-
#expand_javascript_sources2(sources, recursive = false) ⇒ Object
ActionView::Helpers::AssetTagHelper.javascript_expansions.
-
#expand_stylesheet_sources2(sources, recursive = false) ⇒ Object
ActionView::Helpers::AssetTagHelper.javascript_expansions.
- #javascript_generate(js_sources) ⇒ Object
- #javascript_include_tag2(*sources) ⇒ Object
- #join_asset_file_contents2(paths) ⇒ Object
-
#stylesheet_generate(css_sources) ⇒ Object
def javascript_src_tag2(source, options) content_tag(“script”, “”, { “type” => Mime::JS, “src” => javascript_path2(source) }.merge(options)) end def compute_public_path2(source, dir, ext = nil, include_host = true) return source if is_uri?(source).
- #write_asset_file_contents2(joined_asset_path, asset_paths) ⇒ Object
Instance Method Details
#asset_file_path2(path) ⇒ Object
79 80 81 |
# File 'lib/templates/app/helpers/application_helper.rb', line 79 def asset_file_path2(path) File.join( path.split('?').first) end |
#asset_file_path2!(path) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/templates/app/helpers/application_helper.rb', line 83 def asset_file_path2!(path) unless is_uri?(path) absolute_path = asset_file_path2(path) raise(Errno::ENOENT, "Asset file not found at '#{absolute_path}'" ) unless File.exist?(absolute_path) return absolute_path end end |
#collect_gem_js ⇒ Object
12 13 14 15 16 |
# File 'lib/templates/app/helpers/application_helper.rb', line 12 def collect_gem_js ot = Array.new $app_js.map{|x| collect_asset_files(x, '*' + '.js').map{|y| ot.push(y)}} ot end |
#collect_js(*patterns) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/templates/app/helpers/application_helper.rb', line 2 def collect_js(*patterns) = patterns..stringify_keys recursion = !["without_recursion"] # with recursion by default patterns.collect do |pattern| scripts = collect_asset_files(File.join(RAILS_ROOT, 'public', 'javascripts'), pattern + '.js') scripts = scripts + collect_asset_files(File.join(RAILS_ROOT, 'public', 'javascripts'), pattern, '**', '*.js') if recursion scripts end end |
#compute_javascript_paths2(*args) ⇒ Object
46 47 48 |
# File 'lib/templates/app/helpers/application_helper.rb', line 46 def compute_javascript_paths2(*args) (*args).collect { |source| source } end |
#compute_stylesheet_paths2(*args) ⇒ Object
196 197 198 |
# File 'lib/templates/app/helpers/application_helper.rb', line 196 def compute_stylesheet_paths2(*args) (*args).collect { |source| source } end |
#expand_javascript_sources2(sources, recursive = false) ⇒ Object
ActionView::Helpers::AssetTagHelper.javascript_expansions
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/templates/app/helpers/application_helper.rb', line 50 def (sources, recursive = false) if sources.include?(:all) all_javascript_files = (collect_asset_files(config.javascripts_dir, ('**' if recursive), '*.js') - ['application']) << 'application' ((determine_source(:defaults, ActionView::Helpers::AssetTagHelper.javascript_expansions).dup & all_javascript_files) + all_javascript_files).uniq else = sources.collect do |source| determine_source(source, ActionView::Helpers::AssetTagHelper.javascript_expansions) end.flatten << "application" if sources.include?(:defaults) && File.exist?(File.join(config.javascripts_dir, "application.js")) end end |
#expand_stylesheet_sources2(sources, recursive = false) ⇒ Object
ActionView::Helpers::AssetTagHelper.javascript_expansions
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/templates/app/helpers/application_helper.rb', line 200 def (sources, recursive = false) if sources.include?(:all) all_javascript_files = (collect_asset_files(config.javascripts_dir, ('**' if recursive), '*.css') - ['application']) << 'application' ((determine_source(:defaults, ActionView::Helpers::AssetTagHelper.javascript_expansions).dup & all_javascript_files) + all_javascript_files).uniq else = sources.collect do |source| determine_source(source, ActionView::Helpers::AssetTagHelper.stylesheet_expansions) end.flatten << "application" if sources.include?(:defaults) && File.exist?(File.join(config.javascripts_dir, "application.js")) end end |
#javascript_generate(js_sources) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/templates/app/helpers/application_helper.rb', line 99 def javascript_generate(js_sources) js = js_sources sources = Array.new if config.perform_caching #ot = Array.new js.map{|x| collect_asset_files(x, '*' + '.js').map{|y| sources.push(x+'/'+y+'.js')}} joined_javascript_name = "all.js" joined_javascript_path = File.join(config.javascripts_dir, joined_javascript_name) unless config.perform_caching && File.exists?(joined_javascript_path) #return joined_javascript_path write_asset_file_contents2(joined_javascript_path, compute_javascript_paths2(sources, false)) end javascript_src_tag(joined_javascript_name, {}) else #p = x.split(/\/javascript/)[1] #if !p # p = '' #end js.map{|x| collect_asset_files(x,'**', '*' + '.js').map{|y| k = x.split("javascripts/")[1]+'/' if x.split("javascripts/")[1] sources.push(k.to_s+y+'.js') #return sources } } #return sources sources = (sources, false) #ensure_javascript_sources!(sources) if cache sources.collect { |source| javascript_src_tag(source, {}) }.join("\n").html_safe end end |
#javascript_include_tag2(*sources) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/templates/app/helpers/application_helper.rb', line 18 def javascript_include_tag2(*sources) = sources..stringify_keys concat = .delete("concat") cache = concat || .delete("cache") recursive = .delete("recursive") if concat || (!config.perform_caching && cache) joined_javascript_name = (cache == true ? "all" : cache) + ".js" joined_javascript_path = File.join(joined_javascript_name[/^#{File::SEPARATOR}/] ? config.assets_dir : config.javascripts_dir, joined_javascript_name) unless config.perform_caching && File.exists?(joined_javascript_path) #return joined_javascript_path write_asset_file_contents2(joined_javascript_path, compute_javascript_paths2(sources, recursive)) end javascript_src_tag(joined_javascript_name, ) else sources = (sources, recursive) ensure_javascript_sources!(sources) if cache sources.collect { |source| javascript_src_tag(source, ) }.join("\n").html_safe end end |
#join_asset_file_contents2(paths) ⇒ Object
91 92 93 |
# File 'lib/templates/app/helpers/application_helper.rb', line 91 def join_asset_file_contents2(paths) paths.collect { |path| File.read(asset_file_path2!(path)) }.join("\n\n") end |
#stylesheet_generate(css_sources) ⇒ Object
def javascript_src_tag2(source, options)
content_tag("script", "", { "type" => Mime::JS, "src" => javascript_path2(source) }.merge(options))
end
def compute_public_path2(source, dir, ext = nil, include_host = true)
return source if is_uri?(source)
source += ".#{ext}" if rewrite_extension?(source, dir, ext)
#source = "/#{dir}/#{source}" unless source[0] == ?/
source = rewrite_asset_path(source, config.asset_path)
#return config.assets_dir
has_request = controller.respond_to?(:request)
if has_request && include_host && source !~ %r{^#{controller.config.relative_url_root}/}
source = "#{controller.config.relative_url_root}#{source}"
end
source = rewrite_host_and_protocol(source, has_request) if include_host
source
end
def javascript_path2(source)
compute_public_path2(source, '', '')
end
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/templates/app/helpers/application_helper.rb', line 161 def stylesheet_generate(css_sources) css = css_sources sources = Array.new if config.perform_caching #ot = Array.new css.map{|x| collect_asset_files(x, '*' + '.css').map{|y| sources.push(x+'/'+y+'.css')}} joined_javascript_name = "all.css" joined_javascript_path = File.join(config.stylesheets_dir, joined_javascript_name) unless config.perform_caching && File.exists?(joined_javascript_path) #return joined_javascript_path write_asset_file_contents2(joined_javascript_path, compute_stylesheet_paths2(sources, false)) end stylesheet_tag(joined_javascript_name, {}) else #p = x.split(/\/javascript/)[1] #if !p # p = '' #end css.map{|x| collect_asset_files(x,'**', '*' + '.css').map{|y| k = x.split("stylesheets/")[1]+'/' if x.split("stylesheets/")[1] sources.push(k.to_s+y+'.css') } } sources = (sources, false) #ensure_javascript_sources!(sources) if cache sources.collect { |source| stylesheet_tag(source, {}) }.join("\n").html_safe end end |
#write_asset_file_contents2(joined_asset_path, asset_paths) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/templates/app/helpers/application_helper.rb', line 68 def write_asset_file_contents2(joined_asset_path, asset_paths) FileUtils.mkdir_p(File.dirname(joined_asset_path)) File.atomic_write(joined_asset_path) { |cache| cache.write(join_asset_file_contents2(asset_paths)) } # Set mtime to the latest of the combined files to allow for # consistent ETag without a shared filesystem. mt = asset_paths.map { |p| File.mtime(asset_file_path2(p)) }.max File.utime(mt, mt, joined_asset_path) end |