zfben_rails_assets 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/.gitignore +1 -4
  2. data/Gemfile +11 -1
  3. data/README.rdoc +0 -8
  4. data/Rakefile +13 -0
  5. data/app/controllers/assets_controller.rb +32 -0
  6. data/app/helpers/assets_helper.rb +64 -0
  7. data/app/models/asset_format.rb +103 -0
  8. data/app/models/asset_format/css.rb +19 -0
  9. data/app/models/asset_format/js.rb +13 -0
  10. data/config/routes.rb +10 -0
  11. data/lib/{zfben_rails_assets/tasks.rb → tasks/tasks.rake} +0 -0
  12. data/lib/zfben_rails_assets.rb +3 -9
  13. data/test/assets_test.rb +145 -0
  14. data/{example → test/dummy}/Rakefile +2 -2
  15. data/test/dummy/app/assets/blank.css +1 -0
  16. data/test/dummy/app/assets/blank.js +1 -0
  17. data/test/dummy/app/assets/coffee.coffee +1 -0
  18. data/test/dummy/app/assets/import.css +1 -0
  19. data/test/dummy/app/assets/import.js +1 -0
  20. data/test/dummy/app/assets/import_404.css +1 -0
  21. data/test/dummy/app/assets/import_404.js +1 -0
  22. data/test/dummy/app/assets/import_iteration.css +1 -0
  23. data/test/dummy/app/assets/import_iteration.js +1 -0
  24. data/test/dummy/app/assets/import_twice.css +2 -0
  25. data/test/dummy/app/assets/import_twice.js +2 -0
  26. data/test/dummy/app/assets/sass.sass +2 -0
  27. data/test/dummy/app/assets/scss.scss +3 -0
  28. data/{example → test/dummy}/app/controllers/application_controller.rb +0 -0
  29. data/{example → test/dummy}/app/helpers/application_helper.rb +0 -0
  30. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/{example → test/dummy}/config.ru +1 -1
  32. data/test/dummy/config/application.rb +20 -0
  33. data/test/dummy/config/boot.rb +10 -0
  34. data/{example → test/dummy}/config/database.yml +0 -3
  35. data/{example → test/dummy}/config/environment.rb +1 -1
  36. data/{example → test/dummy}/config/environments/development.rb +4 -5
  37. data/{example → test/dummy}/config/environments/production.rb +13 -16
  38. data/{example → test/dummy}/config/environments/test.rb +2 -16
  39. data/{example → test/dummy}/config/initializers/backtrace_silencers.rb +0 -0
  40. data/{example → test/dummy}/config/initializers/inflections.rb +0 -0
  41. data/{example → test/dummy}/config/initializers/mime_types.rb +0 -0
  42. data/{example → test/dummy}/config/initializers/secret_token.rb +1 -1
  43. data/{example → test/dummy}/config/initializers/session_store.rb +2 -2
  44. data/{example → test/dummy}/config/locales/en.yml +1 -1
  45. data/test/dummy/config/routes.rb +58 -0
  46. data/{example → test/dummy}/public/404.html +0 -0
  47. data/{example → test/dummy}/public/422.html +0 -0
  48. data/{example → test/dummy}/public/500.html +0 -0
  49. data/{example → test/dummy}/public/favicon.ico +0 -0
  50. data/test/dummy/public/javascripts/application.js +2 -0
  51. data/test/dummy/public/javascripts/controls.js +965 -0
  52. data/test/dummy/public/javascripts/dragdrop.js +974 -0
  53. data/test/dummy/public/javascripts/effects.js +1123 -0
  54. data/test/dummy/public/javascripts/prototype.js +6001 -0
  55. data/test/dummy/public/javascripts/rails.js +202 -0
  56. data/{example/app/mailers → test/dummy/public/stylesheets}/.gitkeep +0 -0
  57. data/{example → test/dummy}/script/rails +0 -0
  58. data/test/dummy/tmp/assets/blank.css +1 -0
  59. data/test/dummy/tmp/assets/blank.js +1 -0
  60. data/test/dummy/tmp/assets/coffee.js +2 -0
  61. data/test/dummy/tmp/assets/import.css +4 -0
  62. data/test/dummy/tmp/assets/import.js +4 -0
  63. data/{example/app/models/.gitkeep → test/dummy/tmp/assets/import_404.css} +0 -0
  64. data/{example/db/development.sqlite3 → test/dummy/tmp/assets/import_404.js} +0 -0
  65. data/test/dummy/tmp/assets/import_iteration.css +11 -0
  66. data/test/dummy/tmp/assets/import_iteration.js +11 -0
  67. data/{example/lib/tasks/.gitkeep → test/dummy/tmp/assets/import_iteration.min.css} +0 -0
  68. data/{example/test/fixtures/.gitkeep → test/dummy/tmp/assets/import_iteration.min.js} +0 -0
  69. data/test/dummy/tmp/assets/import_twice.css +8 -0
  70. data/test/dummy/tmp/assets/import_twice.js +8 -0
  71. data/test/dummy/tmp/assets/sass.css +3 -0
  72. data/test/dummy/tmp/assets/scss.css +3 -0
  73. data/test/dummy/tmp/assets/simple.sass +3 -0
  74. data/test/test_helper.rb +10 -0
  75. data/zfben_rails_assets.gemspec +14 -4
  76. metadata +136 -133
  77. data/example/.gitignore +0 -7
  78. data/example/.sass-cache/686d48c4bb3405df08bdcc662a0722bb96d63df5/test.sassc +0 -0
  79. data/example/.sass-cache/7a5615116aa96cc45242210dec5b677975f46879/reset.sassc +0 -0
  80. data/example/Gemfile +0 -8
  81. data/example/README +0 -261
  82. data/example/app/assets/images/rails.png +0 -0
  83. data/example/app/assets/javascripts/application.js +0 -9
  84. data/example/app/assets/javascripts/test.js +0 -1
  85. data/example/app/assets/stylesheets/application.css +0 -7
  86. data/example/app/assets/stylesheets/test.css +0 -1
  87. data/example/app/controllers/test_controller.rb +0 -7
  88. data/example/app/views/test/index.haml +0 -12
  89. data/example/config/application.rb +0 -49
  90. data/example/config/boot.rb +0 -6
  91. data/example/config/initializers/wrap_parameters.rb +0 -12
  92. data/example/config/routes.rb +0 -3
  93. data/example/db/seeds.rb +0 -7
  94. data/example/doc/README_FOR_APP +0 -2
  95. data/example/public/robots.txt +0 -5
  96. data/example/test/functional/.gitkeep +0 -0
  97. data/example/test/integration/.gitkeep +0 -0
  98. data/example/test/performance/browsing_test.rb +0 -12
  99. data/example/test/test_helper.rb +0 -13
  100. data/example/test/unit/.gitkeep +0 -0
  101. data/example/vendor/assets/javascripts/zff.js +0 -0
  102. data/example/vendor/assets/javascripts/zff/core.js +0 -1
  103. data/example/vendor/assets/javascripts/zff/core/core.js +0 -57
  104. data/example/vendor/assets/javascripts/zff/lib/jquery/core.js +0 -8936
  105. data/example/vendor/assets/javascripts/zff/lib/jquery/grid.js +0 -467
  106. data/example/vendor/assets/javascripts/zff/lib/jquery/ui.js +0 -11631
  107. data/example/vendor/assets/javascripts/zff/lib/underscore/core.js +0 -807
  108. data/example/vendor/assets/javascripts/zff/spec.js +0 -2
  109. data/example/vendor/assets/javascripts/zff/spec/core.js +0 -38
  110. data/example/vendor/assets/javascripts/zff/spec/qunit.js +0 -1448
  111. data/example/vendor/assets/stylesheets/zff/lib/qunit.css +0 -225
  112. data/example/vendor/assets/stylesheets/zff/reset.sass +0 -1
  113. data/example/vendor/assets/stylesheets/zff/spec.css +0 -1
  114. data/example/vendor/plugins/.gitkeep +0 -0
  115. data/lib/zfben_rails_assets/Gemfile +0 -13
  116. data/lib/zfben_rails_assets/assets/javascripts/zff/core.js +0 -1
  117. data/lib/zfben_rails_assets/assets/javascripts/zff/core/0_config.js +0 -5
  118. data/lib/zfben_rails_assets/assets/javascripts/zff/core/1_jquery.js +0 -5
  119. data/lib/zfben_rails_assets/assets/javascripts/zff/core/2_load.js +0 -53
  120. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/colorbox.js +0 -872
  121. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/contextmenu.js +0 -144
  122. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/core.js +0 -8936
  123. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/grid.js +0 -2
  124. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/grid/addons.js +0 -704
  125. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/grid/core.js +0 -10913
  126. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/grid/i18n/cn.js +0 -132
  127. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/grid/i18n/en.js +0 -128
  128. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/grid/postext.js +0 -64
  129. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/grid/setcolumns.js +0 -126
  130. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/qunit.js +0 -1448
  131. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/searchFilter.js +0 -716
  132. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/tablednd.js +0 -383
  133. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/ui.js +0 -11631
  134. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/jquery/ui/multiselect.js +0 -314
  135. data/lib/zfben_rails_assets/assets/javascripts/zff/lib/underscore/core.js +0 -807
  136. data/lib/zfben_rails_assets/assets/javascripts/zff/spec.js +0 -3
  137. data/lib/zfben_rails_assets/assets/javascripts/zff/spec/core.js +0 -38
  138. data/lib/zfben_rails_assets/assets/stylesheets/zff/lib/jquery/grid/grid.css +0 -140
  139. data/lib/zfben_rails_assets/assets/stylesheets/zff/lib/jquery/qunit/qunit.css +0 -225
  140. data/lib/zfben_rails_assets/assets/stylesheets/zff/lib/jquery/ui/multiselect.css +0 -30
  141. data/lib/zfben_rails_assets/assets/stylesheets/zff/reset.sass +0 -1
  142. data/lib/zfben_rails_assets/assets/stylesheets/zff/spec.css +0 -1
  143. data/lib/zfben_rails_assets/version.rb +0 -3
data/.gitignore CHANGED
@@ -1,8 +1,5 @@
1
1
  *.gem
2
+ *.log
2
3
  .bundle
3
4
  Gemfile.lock
4
5
  pkg/*
5
- example/app/assets/javascripts/zff
6
- example/app/assets/stylesheets/zff
7
- example/app/assets/images/zff
8
- example/config/compass.rb
data/Gemfile CHANGED
@@ -1,4 +1,14 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
3
  # Specify your gem's dependencies in zfben_rails_assets.gemspec
4
4
  gemspec
5
+
6
+ gem 'rails', '>= 3.1.0'
7
+
8
+ gem 'compass'
9
+
10
+ gem 'therubyracer'
11
+ gem 'coffee-script'
12
+ gem 'uglifier'
13
+
14
+ #gem 'zfben_rails_assets', :path => File.dirname(__FILE__)
@@ -11,11 +11,3 @@ This is plugin to add some useful assets to rails.
11
11
  2. update bundle
12
12
 
13
13
  bundle install
14
-
15
- 3. install assets
16
-
17
- rake assets:install
18
-
19
- 4. install assets gems
20
-
21
- bundle install
data/Rakefile CHANGED
@@ -1 +1,14 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
1
5
  require 'bundler/gem_tasks'
6
+
7
+ require 'rake/testtask'
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = false
14
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+ class AssetsController < ActionController::Base
3
+ caches_action :index, :show, cache_path: Proc.new{ |c| c.params }, if: Proc.new{ |c| request.get? && c.params[:version] != 'direct' }
4
+
5
+ def index
6
+ if format_defined?
7
+ render render_assets
8
+ else
9
+ render text: 'Undefined format', status: 500
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def initialize
16
+ # read assets/models to get formats
17
+ @formats = {}
18
+ Dir[File.dirname(__FILE__) << '/../models/asset_format/*.rb', Rails.root.to_s + '/app/assets/asset_format/*.rb'].each do |path|
19
+ @formats[File.basename(path, '.rb')] = path
20
+ end
21
+ end
22
+
23
+ def format_defined?
24
+ @formats.has_key?(params[:format])
25
+ end
26
+
27
+ def render_assets
28
+ require @formats[params[:format]]
29
+ asset = AssetFormat.const_get(params[:format].capitalize).new("#{params[:file]}.#{params[:format]}")
30
+ { text: asset.text, content_type: asset.content_type, status: asset.status }
31
+ end
32
+ end
@@ -0,0 +1,64 @@
1
+ module AssetsHelper
2
+ VER = Time.now.to_i.to_s
3
+
4
+ def assets *opts
5
+ return '' if opts.blank?
6
+ html = ''
7
+ opts.each do |name|
8
+ name = name.to_s
9
+ if name.end_with?('.css')
10
+ html << assets_css(name)
11
+ elsif name.end_with?('.js')
12
+ html << assets_js(name)
13
+ else
14
+ path = Rails.root.to_s + '/app/assets/' + name
15
+ css = Dir.glob(([:css] + AssetFormat::Css::EXTEND_FORMATS).map{ |f| path + '.' + f.to_s })
16
+ js = Dir.glob(([:js] + AssetFormat::Js::EXTEND_FORMATS).map{ |f| path + '.' + f.to_s })
17
+ html << assets(name + '.css') if css.length > 0
18
+ html << assets(name + '.js') if js.length > 0
19
+ end
20
+ end
21
+ html
22
+ end
23
+
24
+ private
25
+
26
+ def assets_js url
27
+ "<script src=\"#{asset_host}/#{url}\"></script>"
28
+ end
29
+
30
+ def assets_css url
31
+ "<link rel=\"stylesheet\" href=\"#{asset_host}/#{url}\" />"
32
+ end
33
+
34
+ def asset_host
35
+ unless Rails.configuration.action_controller[:asset_host].nil?
36
+ host = Rails.configuration.action_controller[:asset_host].clone
37
+ unless request.nil?
38
+ host << (request.port == 80 ? '' : (':' << request.port.to_s))
39
+ end
40
+ else
41
+ host = ''
42
+ end
43
+
44
+ unless Rails.configuration.action_controller[:asset_path].nil?
45
+ host << ('/' + Rails.configuration.action_controller[:asset_path])
46
+ else
47
+ host << '/assets'
48
+ end
49
+
50
+ if Rails.env.production? && Rails.configuration.action_controller[:asset_version].nil?
51
+ Rails.configuration.action_controller[:asset_version] = :now
52
+ end
53
+
54
+ unless Rails.configuration.action_controller[:asset_version].nil?
55
+ if Rails.configuration.action_controller[:asset_version] == :now
56
+ host << '/' << VER
57
+ else
58
+ host << '/' << Rails.configuration.action_controller[:asset_version].to_s
59
+ end
60
+ end
61
+
62
+ host
63
+ end
64
+ end
@@ -0,0 +1,103 @@
1
+ class AssetFormat
2
+ def content_type
3
+ self.class::CONTENT_TYPE || 'text/plain'
4
+ end
5
+
6
+ def text
7
+ if defined?(@path)
8
+ File.read(@path)
9
+ else
10
+ @text || ''
11
+ end
12
+ end
13
+
14
+ def status
15
+ @status || 200
16
+ end
17
+
18
+ def log
19
+ status == 200 ? ('read ' + @path) : ('error: ' + @text || '')
20
+ end
21
+
22
+ private
23
+
24
+ def not_found path
25
+ @text = 'File not found: ' + path
26
+ @status = 404
27
+ end
28
+
29
+ def no_error?
30
+ @status.nil? || 200
31
+ end
32
+
33
+ def initialize file
34
+ @option = file.split('.')
35
+ @format = @option.last
36
+ path = find_file(@option[0] + '.' + @option.last)
37
+ unless path.nil?
38
+ text = read_file path
39
+ if defined?(self.class::IMPORT)
40
+ regexp = self.class::IMPORT
41
+ text = import_file regexp, text
42
+ end
43
+ if no_error?
44
+ if @option.include?('min') && self.respond_to?(:minify)
45
+ text = minify(text)
46
+ end
47
+ @path = write_file file, text
48
+ end
49
+ else
50
+ not_found file
51
+ end
52
+ end
53
+
54
+ def find_file filename
55
+ path = Rails.root.to_s + '/app/assets/' + filename
56
+ if File.exist?(path)
57
+ return path
58
+ else
59
+ path = path.gsub('.' + @format, '')
60
+ formats = [@format]
61
+ if defined?(self.class::EXTEND_FORMATS)
62
+ formats = formats + self.class::EXTEND_FORMATS
63
+ end
64
+ list = Dir.glob(formats.map{ |f| path + '.' + f.to_s })
65
+ if list.length > 0
66
+ return list[0]
67
+ else
68
+ return nil
69
+ end
70
+ end
71
+ end
72
+
73
+ def read_file file
74
+ text = File.read file
75
+ format = File.extname(file).gsub('.', '').to_sym
76
+ if self.respond_to?(format)
77
+ text = self.method(format).call(text)
78
+ end
79
+ text
80
+ end
81
+
82
+ def write_file name, text
83
+ dir = Rails.root.to_s + '/tmp/assets/'
84
+ unless File.exist?(dir)
85
+ FileUtils.mkdir(dir)
86
+ end
87
+ path = dir + File.basename(name)
88
+ File.open(path, 'w'){ |f| f.write text }
89
+ path
90
+ end
91
+
92
+ def import_file regexp, text
93
+ text.gsub(regexp){ |s|
94
+ file = find_file(regexp.match(s)[1])
95
+ unless file.nil?
96
+ "\n/* #{file} */\n" << import_file(regexp, read_file(file))
97
+ else
98
+ not_found s
99
+ break
100
+ end
101
+ }
102
+ end
103
+ end
@@ -0,0 +1,19 @@
1
+ require 'sass/css'
2
+
3
+ class AssetFormat::Css < AssetFormat
4
+ CONTENT_TYPE = 'text/css'
5
+ IMPORT = /[\/\* ]*@import[ "'\(]+([^\s"'\);]+)[ "'\);\*\/]*/
6
+ EXTEND_FORMATS = [:sass, :scss]
7
+
8
+ def minify text
9
+ ::Sass::Engine.new(::Sass::CSS.new(text).render(:sass), { syntax: :sass, style: :compressed }).render
10
+ end
11
+
12
+ def sass text
13
+ ::Sass::Engine.new(text, { syntax: :sass, style: :expanded }).render
14
+ end
15
+
16
+ def scss text
17
+ ::Sass::Engine.new(text, { syntax: :scss, style: :expanded }).render
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ class AssetFormat::Js < AssetFormat
2
+ CONTENT_TYPE = 'text/javascript'
3
+ IMPORT = /[\/\*]{2} *@import[ "'\(]+([^\s"'\);]+)[ "'\)\/\*]*/
4
+ EXTEND_FORMATS = [:coffee]
5
+
6
+ def minify text
7
+ Uglifier.compile text, copyright: false
8
+ end
9
+
10
+ def coffee text
11
+ CoffeeScript.compile text
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ unless Rails.configuration.action_controller[:asset_path].nil?
2
+ path = '/' + Rails.configuration.action_controller[:asset_path]
3
+ else
4
+ path = '/assets'
5
+ end
6
+
7
+ Rails.application.routes.draw do
8
+ get (path + '/:version/*file') => 'assets#index'
9
+ get (path + '/*file') => 'assets#index'
10
+ end
@@ -1,12 +1,6 @@
1
- require "zfben_rails_assets/version"
2
- ZfbenRailsAssetsPath = File.join File.dirname(__FILE__), 'zfben_rails_assets'
3
-
4
1
  module ZfbenRailsAssets
5
- class Railtie < Rails::Railtie
6
- railtie_name :zfben_rails_assets
7
-
8
- rake_tasks do
9
- load File.join(ZfbenRailsAssetsPath, 'tasks.rb')
10
- end
2
+ class Engine < Rails::Engine
3
+ engine_name :zfben_rails_assets
4
+ isolate_namespace ZfbenRailsAssets
11
5
  end
12
6
  end
@@ -0,0 +1,145 @@
1
+ require 'test_helper'
2
+
3
+ class ModuleTest < ActiveSupport::TestCase
4
+ test 'ModuleTest' do
5
+ assert_kind_of Module, ZfbenRailsAssets
6
+ end
7
+ end
8
+
9
+ class CssTest < ActiveSupport::TestCase
10
+ ["@import file\n", '@import(file)', '@import("file")', '@import "file"', '@import file;', '/* @import file */'].each do |test|
11
+ test('import regex: ' + test)do
12
+ assert_equal AssetFormat::Css::IMPORT.match(test)[1], 'file'
13
+ end
14
+ end
15
+ end
16
+
17
+ class JsTest < ActiveSupport::TestCase
18
+ ["// @import file\n", '//@import(file)', '//@import("file")', '//@import "file"', '//@import file;', '/* @import file */'].each do |test|
19
+ test('import regex: ' + test)do
20
+ assert_equal AssetFormat::Js::IMPORT.match(test)[1], 'file'
21
+ end
22
+ end
23
+ end
24
+
25
+ class RoutesTest < ActionController::TestCase
26
+ test '/assets/file.format' do
27
+ assert_routing '/assets/file.format', { controller: 'assets', action: 'index', file: 'file', format: 'format' }
28
+ end
29
+
30
+ test '/assets/version/file.format' do
31
+ assert_routing '/assets/version/file.format', { controller: 'assets', action: 'index', file: 'file', format: 'format', version: 'version' }
32
+ end
33
+
34
+ test '/assets/file.option.format' do
35
+ assert_routing '/assets/file.option.format', { controller: 'assets', action: 'index', file: 'file.option', format: 'format' }
36
+ end
37
+
38
+ test '/assets/version/file.option.format' do
39
+ assert_routing '/assets/version/file.option.format', { controller: 'assets', action: 'index', file: 'file.option', format: 'format', version: 'version' }
40
+ end
41
+ end
42
+
43
+ class ControllerTest < ActionController::TestCase
44
+ setup do
45
+ @controller = AssetsController.new
46
+ end
47
+
48
+ test 'undefined format' do
49
+ get :index, file: 'file', format: 'undefined'
50
+ assert_response 500
51
+ end
52
+
53
+ test 'not found file' do
54
+ get :index, file: 'notfound', format: 'css'
55
+ assert_response 404
56
+ end
57
+
58
+ ['css', 'js'].each do |format|
59
+ test('blank.' + format)do
60
+ get :index, file: 'blank', format: format
61
+ assert_response :success
62
+ assert_equal @response.body, File.read(Rails.root.to_s + '/app/assets/blank.' + format)
63
+ end
64
+
65
+ test('import.' + format)do
66
+ get :index, file: 'import', format: format
67
+ assert_response :success
68
+ assert @response.body.include?(File.read(Rails.root.to_s + '/app/assets/blank.' + format))
69
+ end
70
+
71
+ test('import_twice.' + format)do
72
+ get :index, file: 'import_twice', format: format
73
+ assert_response :success
74
+ count = 0
75
+ @response.body.gsub(File.read(Rails.root.to_s + '/app/assets/blank.' + format)){ count = count + 1 }
76
+ assert count == 2
77
+ end
78
+
79
+ test('import_iteration.' + format)do
80
+ get :index, file: 'import_iteration', format: format
81
+ assert_response :success
82
+ count = 0
83
+ @response.body.gsub(File.read(Rails.root.to_s + '/app/assets/blank.' + format)){ count = count + 1 }
84
+ assert count == 2
85
+ end
86
+
87
+ test('import_iteration.min.' + format)do
88
+ get :index, file: 'import_iteration.min', format: format
89
+ assert_response :success
90
+ assert_equal @response.body, ''
91
+ end
92
+
93
+ test('import_404.' + format)do
94
+ get :index, file: 'import_404', format: format
95
+ assert_response 404
96
+ end
97
+ end
98
+
99
+ test 'sass.css' do
100
+ get :index, file: 'sass', format: 'css'
101
+ assert_response :success
102
+ assert_equal @response.body, ::Sass::Engine.new(File.read(Rails.root.to_s + '/app/assets/sass.sass'), { syntax: :sass, style: :expanded }).render
103
+ end
104
+
105
+ test 'scss.css' do
106
+ get :index, file: 'scss', format: 'css'
107
+ assert_response :success
108
+ assert_equal @response.body, ::Sass::Engine.new(File.read(Rails.root.to_s + '/app/assets/scss.scss'), { syntax: :scss, style: :expanded }).render
109
+ end
110
+
111
+ test 'coffee.js' do
112
+ get :index, file: 'coffee', format: 'js'
113
+ assert_response :success
114
+ assert_equal @response.body, CoffeeScript.compile(File.read(Rails.root.to_s + '/app/assets/coffee.coffee'))
115
+ end
116
+ end
117
+
118
+ class AssetsHelperTest < ActionView::TestCase
119
+ setup do
120
+ Rails.configuration.action_controller[:asset_host] = nil
121
+ Rails.configuration.action_controller[:asset_path] = nil
122
+ Rails.configuration.action_controller[:asset_version] = nil
123
+ end
124
+
125
+ test 'assets blank.css' do
126
+ assert_equal assets('blank.css'), '<link rel="stylesheet" href="/assets/blank.css" />'
127
+ end
128
+
129
+ test 'assets blank.js' do
130
+ assert_equal assets('blank.js'), '<script src="/assets/blank.js"></script>'
131
+ end
132
+
133
+ test 'assets blank' do
134
+ assert_equal assets('blank'), assets('blank.css') << assets('blank.js')
135
+ end
136
+
137
+ test 'assets in production' do
138
+ Rails.configuration.action_controller[:asset_host] = 'http://assets.com'
139
+ Rails.configuration.action_controller[:asset_path] = 'assets_path'
140
+ Rails.configuration.action_controller[:asset_version] = 'version'
141
+ assert_equal assets('blank.css'), '<link rel="stylesheet" href="http://assets.com/assets_path/version/blank.css" />'
142
+ assert_equal assets('blank.js'), '<script src="http://assets.com/assets_path/version/blank.js"></script>'
143
+ assert_equal assets('blank'), assets('blank.css') << assets('blank.js')
144
+ end
145
+ end