jsmestad-compass 0.4.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/Manifest +175 -0
  2. data/README.markdown +17 -0
  3. data/Rakefile +125 -0
  4. data/VERSION +1 -0
  5. data/bin/compass +8 -0
  6. data/compass.gemspec +37 -0
  7. data/examples/blueprint_default/index.html +73 -0
  8. data/examples/blueprint_default/parts/elements.html +246 -0
  9. data/examples/blueprint_default/parts/forms.html +100 -0
  10. data/examples/blueprint_default/parts/grid.html +206 -0
  11. data/examples/blueprint_default/parts/test-small.jpg +0 -0
  12. data/examples/blueprint_default/parts/test.jpg +0 -0
  13. data/examples/blueprint_default/parts/valid.png +0 -0
  14. data/examples/blueprint_default/stylesheets/ie.sass +3 -0
  15. data/examples/blueprint_default/stylesheets/images/grid.png +0 -0
  16. data/examples/blueprint_default/stylesheets/print.sass +3 -0
  17. data/examples/blueprint_default/stylesheets/screen.sass +8 -0
  18. data/examples/blueprint_plugins/index.html +60 -0
  19. data/examples/blueprint_plugins/parts/fancy_type.html +84 -0
  20. data/examples/blueprint_plugins/parts/test-small.jpg +0 -0
  21. data/examples/blueprint_plugins/parts/test.jpg +0 -0
  22. data/examples/blueprint_plugins/parts/valid.png +0 -0
  23. data/examples/blueprint_plugins/stylesheets/ie.sass +3 -0
  24. data/examples/blueprint_plugins/stylesheets/images/grid.png +0 -0
  25. data/examples/blueprint_plugins/stylesheets/print.sass +3 -0
  26. data/examples/blueprint_plugins/stylesheets/screen.sass +11 -0
  27. data/examples/blueprint_scoped/stylesheets/ie.sass +3 -0
  28. data/examples/blueprint_scoped/stylesheets/print.sass +3 -0
  29. data/examples/blueprint_scoped/stylesheets/screen.sass +4 -0
  30. data/examples/blueprint_scoped_form/stylesheets/ie.sass +3 -0
  31. data/examples/blueprint_scoped_form/stylesheets/print.sass +3 -0
  32. data/examples/blueprint_scoped_form/stylesheets/screen.sass +10 -0
  33. data/examples/blueprint_semantic/index.html +68 -0
  34. data/examples/blueprint_semantic/parts/fancy_type.html +84 -0
  35. data/examples/blueprint_semantic/parts/liquid.html +84 -0
  36. data/examples/blueprint_semantic/parts/test-small.jpg +0 -0
  37. data/examples/blueprint_semantic/parts/test.jpg +0 -0
  38. data/examples/blueprint_semantic/parts/valid.png +0 -0
  39. data/examples/blueprint_semantic/stylesheets/ie.sass +3 -0
  40. data/examples/blueprint_semantic/stylesheets/images/grid.png +0 -0
  41. data/examples/blueprint_semantic/stylesheets/liquid.sass +70 -0
  42. data/examples/blueprint_semantic/stylesheets/print.sass +3 -0
  43. data/examples/blueprint_semantic/stylesheets/screen.sass +69 -0
  44. data/examples/compass/compass.html +19 -0
  45. data/examples/compass/sticky_footer.html.haml +14 -0
  46. data/examples/compass/stylesheets/compass.sass +47 -0
  47. data/examples/compass/stylesheets/images/blue_arrow.gif +0 -0
  48. data/examples/compass/stylesheets/sticky_footer.sass +11 -0
  49. data/examples/compass/stylesheets/utilities.sass +65 -0
  50. data/examples/compass/utilities.html.haml +136 -0
  51. data/examples/yui/divisions.html.haml +179 -0
  52. data/examples/yui/index.html.haml +19 -0
  53. data/examples/yui/stylesheets/screen.sass +13 -0
  54. data/examples/yui/sub_divisions.html.haml +169 -0
  55. data/examples/yui/templates.html.haml +54 -0
  56. data/examples/yui/test.jpg +0 -0
  57. data/examples/yui/typography.html.haml +132 -0
  58. data/frameworks/blueprint.rb +2 -0
  59. data/frameworks/blueprint/lib/blueprint/constants.rb +17 -0
  60. data/frameworks/blueprint/lib/blueprint/grid_builder.rb +54 -0
  61. data/frameworks/blueprint/stylesheets/_blueprint.sass +3 -0
  62. data/frameworks/blueprint/stylesheets/blueprint/_ie.sass +49 -0
  63. data/frameworks/blueprint/stylesheets/blueprint/_print.sass +82 -0
  64. data/frameworks/blueprint/stylesheets/blueprint/_screen.sass +15 -0
  65. data/frameworks/blueprint/stylesheets/blueprint/modules/_colors.sass +30 -0
  66. data/frameworks/blueprint/stylesheets/blueprint/modules/_debug.sass +9 -0
  67. data/frameworks/blueprint/stylesheets/blueprint/modules/_fancy_type.sass +81 -0
  68. data/frameworks/blueprint/stylesheets/blueprint/modules/_form.sass +43 -0
  69. data/frameworks/blueprint/stylesheets/blueprint/modules/_grid.sass +141 -0
  70. data/frameworks/blueprint/stylesheets/blueprint/modules/_interaction.sass +58 -0
  71. data/frameworks/blueprint/stylesheets/blueprint/modules/_liquid.sass +137 -0
  72. data/frameworks/blueprint/stylesheets/blueprint/modules/_scaffolding.sass +46 -0
  73. data/frameworks/blueprint/stylesheets/blueprint/modules/_typography.sass +153 -0
  74. data/frameworks/blueprint/stylesheets/blueprint/modules/_utilities.sass +37 -0
  75. data/frameworks/blueprint/templates/project/grid.png +0 -0
  76. data/frameworks/blueprint/templates/project/ie.sass +3 -0
  77. data/frameworks/blueprint/templates/project/manifest.rb +5 -0
  78. data/frameworks/blueprint/templates/project/print.sass +3 -0
  79. data/frameworks/blueprint/templates/project/screen.sass +8 -0
  80. data/frameworks/compass.rb +2 -0
  81. data/frameworks/compass/stylesheets/_compass.sass +1 -0
  82. data/frameworks/compass/stylesheets/compass/_layout.sass +1 -0
  83. data/frameworks/compass/stylesheets/compass/_reset.sass +3 -0
  84. data/frameworks/compass/stylesheets/compass/_utilities.sass +5 -0
  85. data/frameworks/compass/stylesheets/compass/layout/_sticky_footer.sass +17 -0
  86. data/frameworks/compass/stylesheets/compass/utilities/_general.sass +4 -0
  87. data/frameworks/compass/stylesheets/compass/utilities/_links.sass +3 -0
  88. data/frameworks/compass/stylesheets/compass/utilities/_lists.sass +3 -0
  89. data/frameworks/compass/stylesheets/compass/utilities/_print.sass +24 -0
  90. data/frameworks/compass/stylesheets/compass/utilities/_tables.sass +1 -0
  91. data/frameworks/compass/stylesheets/compass/utilities/_text.sass +2 -0
  92. data/frameworks/compass/stylesheets/compass/utilities/general/_clearfix.sass +11 -0
  93. data/frameworks/compass/stylesheets/compass/utilities/general/_inline_block.sass +6 -0
  94. data/frameworks/compass/stylesheets/compass/utilities/general/_reset.sass +58 -0
  95. data/frameworks/compass/stylesheets/compass/utilities/general/_tabs.sass +0 -0
  96. data/frameworks/compass/stylesheets/compass/utilities/general/_tag_cloud.sass +19 -0
  97. data/frameworks/compass/stylesheets/compass/utilities/links/_hover_link.sass +5 -0
  98. data/frameworks/compass/stylesheets/compass/utilities/links/_link_colors.sass +24 -0
  99. data/frameworks/compass/stylesheets/compass/utilities/links/_unstyled_link.sass +5 -0
  100. data/frameworks/compass/stylesheets/compass/utilities/lists/_bullets.sass +21 -0
  101. data/frameworks/compass/stylesheets/compass/utilities/lists/_horizontal_list.sass +20 -0
  102. data/frameworks/compass/stylesheets/compass/utilities/lists/_inline_list.sass +29 -0
  103. data/frameworks/compass/stylesheets/compass/utilities/tables/_alternating_rows_and_columns.sass +25 -0
  104. data/frameworks/compass/stylesheets/compass/utilities/text/_nowrap.sass +3 -0
  105. data/frameworks/compass/stylesheets/compass/utilities/text/_replacement.sass +10 -0
  106. data/frameworks/compass/templates/project/ie.sass +6 -0
  107. data/frameworks/compass/templates/project/manifest.rb +3 -0
  108. data/frameworks/compass/templates/project/print.sass +6 -0
  109. data/frameworks/compass/templates/project/screen.sass +7 -0
  110. data/frameworks/yui.rb +2 -0
  111. data/frameworks/yui/COPYRIGHT +15 -0
  112. data/frameworks/yui/stylesheets/_yui.sass +7 -0
  113. data/frameworks/yui/stylesheets/yui/modules/_base.sass +60 -0
  114. data/frameworks/yui/stylesheets/yui/modules/_fonts.sass +38 -0
  115. data/frameworks/yui/stylesheets/yui/modules/_grids.sass +341 -0
  116. data/frameworks/yui/templates/project/manifest.rb +1 -0
  117. data/frameworks/yui/templates/project/screen.sass +4 -0
  118. data/lib/compass.rb +39 -0
  119. data/lib/compass/actions.rb +92 -0
  120. data/lib/compass/commands/base.rb +26 -0
  121. data/lib/compass/commands/create_project.rb +41 -0
  122. data/lib/compass/commands/list_frameworks.rb +16 -0
  123. data/lib/compass/commands/print_version.rb +23 -0
  124. data/lib/compass/commands/project_base.rb +74 -0
  125. data/lib/compass/commands/update_project.rb +61 -0
  126. data/lib/compass/commands/watch_project.rb +53 -0
  127. data/lib/compass/compiler.rb +40 -0
  128. data/lib/compass/configuration.rb +92 -0
  129. data/lib/compass/core_ext.rb +12 -0
  130. data/lib/compass/errors.rb +7 -0
  131. data/lib/compass/exec.rb +184 -0
  132. data/lib/compass/frameworks.rb +29 -0
  133. data/lib/compass/installers.rb +5 -0
  134. data/lib/compass/installers/base.rb +135 -0
  135. data/lib/compass/installers/manifest.rb +57 -0
  136. data/lib/compass/installers/rails.rb +125 -0
  137. data/lib/compass/installers/stand_alone.rb +76 -0
  138. data/lib/compass/logger.rb +34 -0
  139. data/lib/compass/merb.rb +43 -0
  140. data/lib/compass/test_case.rb +37 -0
  141. data/lib/compass/validate.rb +13 -0
  142. data/lib/compass/validate/COPYRIGHT.html +93 -0
  143. data/lib/compass/validate/JIGSAW_COPYRIGHT +64 -0
  144. data/lib/compass/validate/README.html +83 -0
  145. data/lib/compass/validate/XERCES_COPYING.txt +56 -0
  146. data/lib/compass/validate/css-validator-javadoc.jar +0 -0
  147. data/lib/compass/validate/css-validator.jar +0 -0
  148. data/lib/compass/validate/jigsaw.jar +0 -0
  149. data/lib/compass/validate/xerces.jar +0 -0
  150. data/lib/compass/validator.rb +59 -0
  151. data/lib/compass/version.rb +66 -0
  152. data/lib/sass_extensions.rb +13 -0
  153. data/test/command_line_test.rb +147 -0
  154. data/test/compass_test.rb +148 -0
  155. data/test/configuration_test.rb +28 -0
  156. data/test/fixtures/stylesheets/blueprint/css/typography.css +158 -0
  157. data/test/fixtures/stylesheets/blueprint/sass/ie.sass +3 -0
  158. data/test/fixtures/stylesheets/blueprint/sass/print.sass +3 -0
  159. data/test/fixtures/stylesheets/blueprint/sass/screen.sass +17 -0
  160. data/test/fixtures/stylesheets/blueprint/sass/typography.sass +3 -0
  161. data/test/fixtures/stylesheets/compass/css/layout.css +14 -0
  162. data/test/fixtures/stylesheets/compass/css/print.css +19 -0
  163. data/test/fixtures/stylesheets/compass/css/reset.css +69 -0
  164. data/test/fixtures/stylesheets/compass/css/utilities.css +21 -0
  165. data/test/fixtures/stylesheets/compass/sass/layout.sass +3 -0
  166. data/test/fixtures/stylesheets/compass/sass/print.sass +5 -0
  167. data/test/fixtures/stylesheets/compass/sass/reset.sass +1 -0
  168. data/test/fixtures/stylesheets/compass/sass/utilities.sass +5 -0
  169. data/test/fixtures/stylesheets/yui/css/mixins.css +16 -0
  170. data/test/fixtures/stylesheets/yui/sass/base.sass +3 -0
  171. data/test/fixtures/stylesheets/yui/sass/fonts.sass +3 -0
  172. data/test/fixtures/stylesheets/yui/sass/grids.sass +3 -0
  173. data/test/fixtures/stylesheets/yui/sass/mixins.sass +16 -0
  174. data/test/sass_extensions_test.rb +26 -0
  175. data/test/test_helper.rb +47 -0
  176. metadata +291 -0
@@ -0,0 +1,56 @@
1
+ /*
2
+ * The Apache Software License, Version 1.1
3
+ *
4
+ *
5
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
6
+ * reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without
9
+ * modification, are permitted provided that the following conditions
10
+ * are met:
11
+ *
12
+ * 1. Redistributions of source code must retain the above copyright
13
+ * notice, this list of conditions and the following disclaimer.
14
+ *
15
+ * 2. Redistributions in binary form must reproduce the above copyright
16
+ * notice, this list of conditions and the following disclaimer in
17
+ * the documentation and/or other materials provided with the
18
+ * distribution.
19
+ *
20
+ * 3. The end-user documentation included with the redistribution,
21
+ * if any, must include the following acknowledgment:
22
+ * "This product includes software developed by the
23
+ * Apache Software Foundation (http://www.apache.org/)."
24
+ * Alternately, this acknowledgment may appear in the software itself,
25
+ * if and wherever such third-party acknowledgments normally appear.
26
+ *
27
+ * 4. The names "Xerces" and "Apache Software Foundation" must
28
+ * not be used to endorse or promote products derived from this
29
+ * software without prior written permission. For written
30
+ * permission, please contact apache@apache.org.
31
+ *
32
+ * 5. Products derived from this software may not be called "Apache",
33
+ * nor may "Apache" appear in their name, without prior written
34
+ * permission of the Apache Software Foundation.
35
+ *
36
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47
+ * SUCH DAMAGE.
48
+ * ====================================================================
49
+ *
50
+ * This software consists of voluntary contributions made by many
51
+ * individuals on behalf of the Apache Software Foundation and was
52
+ * originally based on software copyright (c) 1999, International
53
+ * Business Machines, Inc., http://www.ibm.com. For more
54
+ * information on the Apache Software Foundation, please see
55
+ * <http://www.apache.org/>.
56
+ */
Binary file
Binary file
@@ -0,0 +1,59 @@
1
+ require File.join(File.dirname(__FILE__), 'core_ext')
2
+ require File.join(File.dirname(__FILE__), 'constants')
3
+
4
+ module Compass
5
+ # Validates generated CSS against the W3 using Java
6
+ class Validator
7
+ VALIDATOR_FILE = File.join(File.dirname(__FILE__), 'validate', 'css-validator.jar')
8
+ attr_reader :error_count
9
+
10
+ def initialize
11
+ @error_count = 0
12
+ end
13
+
14
+ # Validates all three CSS files
15
+ def validate
16
+ java_path = `which java`.rstrip
17
+ raise "You do not have a Java installed, but it is required." if java_path.blank?
18
+
19
+ output_header
20
+
21
+ Dir.new(Compass::Constants::BLUEPRINT_ROOT_PATH).each do |file_name|
22
+ puts "#{file_name}"
23
+ if file_name =~ /\.css$/
24
+ css_file = File.join(Compass::Constants::BLUEPRINT_ROOT_PATH, file_name)
25
+ @error_count += 1 if !validate_css_file(java_path, css_file)
26
+ end
27
+ end
28
+
29
+ output_footer
30
+ end
31
+
32
+ private
33
+ def validate_css_file(java_path, css_file)
34
+ puts "\n\n Testing #{css_file}"
35
+ puts " Output ============================================================\n\n"
36
+ system("#{java_path} -jar '#{VALIDATOR_FILE}' -e '#{css_file}'")
37
+ end
38
+
39
+ def output_header
40
+ puts "\n\n"
41
+ puts " ************************************************************"
42
+ puts " **"
43
+ puts " ** Compass CSS Validator"
44
+ puts " ** Validates output CSS files"
45
+ puts " **"
46
+ puts " ************************************************************"
47
+ end
48
+
49
+ def output_footer
50
+ puts "\n\n"
51
+ puts " ************************************************************"
52
+ puts " **"
53
+ puts " ** Done!"
54
+ puts " ** Your CSS files are#{" not" if error_count > 0} valid.#{" You had #{error_count} error(s) within your files" if error_count > 0}"
55
+ puts " **"
56
+ puts " ************************************************************"
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,66 @@
1
+ module Compass
2
+ module Version
3
+ # Returns a hash representing the version.
4
+ # The :major, :minor, and :teeny keys have their respective numbers.
5
+ # The :string key contains a human-readable string representation of the version.
6
+ # If checked out from Git,
7
+ # the :rev key will have the revision hash.
8
+ #
9
+ # This method swiped from Haml and then modified, some credit goes to Nathan Weizenbaum
10
+ attr_writer :version
11
+ def version
12
+ return @version if defined?(@version)
13
+
14
+ read_version_file
15
+ parse_version
16
+
17
+ if r = revision
18
+ @version[:rev] = r
19
+ @version[:string] << " [#{r[0...7]}]"
20
+ end
21
+
22
+ @version
23
+ end
24
+
25
+ protected
26
+
27
+ def scope(file) # :nodoc:
28
+ File.join(File.dirname(__FILE__), '..', '..', file)
29
+ end
30
+
31
+ def read_version_file
32
+ @version = {
33
+ :string => File.read(scope('VERSION')).strip
34
+ }
35
+ end
36
+
37
+ def parse_version
38
+ dotted_string, @version[:label] = @version[:string].split(/-/, 2)
39
+ numbers = dotted_string.split('.').map { |n| n.to_i }
40
+ [:major, :minor, :teeny].zip(numbers).each do |attr, value|
41
+ @version[attr] = value
42
+ end
43
+ end
44
+
45
+ def revision
46
+ revision_from_git || revision_from_file
47
+ end
48
+
49
+ def revision_from_file
50
+ if File.exists?(scope('REVISION'))
51
+ rev = File.read(scope('REVISION')).strip
52
+ rev = nil if rev !~ /[a-f0-9]+/
53
+ end
54
+ end
55
+
56
+ def revision_from_git
57
+ if File.exists?(scope('.git/HEAD'))
58
+ rev = File.read(scope('.git/HEAD')).strip
59
+ if rev =~ /^ref: (.*)$/
60
+ rev = File.read(scope(".git/#{$1}")).strip
61
+ end
62
+ end
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,13 @@
1
+ require 'sass'
2
+
3
+ module Sass::Script::Functions
4
+ COMMA_SEPARATOR = /\s*,\s*/
5
+ def nest(*arguments)
6
+ nested = arguments.map{|a| a.value}.inject do |memo,arg|
7
+ ancestors = memo.split(COMMA_SEPARATOR)
8
+ descendants = arg.split(COMMA_SEPARATOR)
9
+ ancestors.map{|a| descendants.map{|d| "#{a} #{d}"}.join(", ")}.join(", ")
10
+ end
11
+ Sass::Script::String.new(nested)
12
+ end
13
+ end
@@ -0,0 +1,147 @@
1
+ require File.dirname(__FILE__)+'/test_helper'
2
+ require 'fileutils'
3
+ require 'compass'
4
+ require 'compass/exec'
5
+ require 'timeout'
6
+
7
+ class CommandLineTest < Test::Unit::TestCase
8
+ include Compass::TestCaseHelper
9
+
10
+ def teardown
11
+ Compass.configuration.reset!
12
+ end
13
+
14
+ def test_basic_install
15
+ within_tmp_directory do
16
+ compass "basic"
17
+ assert File.exists?("basic/src/screen.sass")
18
+ assert File.exists?("basic/stylesheets/screen.css")
19
+ assert_action_performed :directory, "basic/"
20
+ assert_action_performed :create, "basic/src/screen.sass"
21
+ assert_action_performed :compile, "basic/src/screen.sass"
22
+ assert_action_performed :create, "basic/stylesheets/screen.css"
23
+ end
24
+ end
25
+
26
+ def test_framework_installs
27
+ Compass::Frameworks::ALL.each do |framework|
28
+ within_tmp_directory do
29
+ compass *%W(--framework #{framework.name} #{framework.name}_project)
30
+ assert File.exists?("#{framework.name}_project/src/screen.sass")
31
+ assert File.exists?("#{framework.name}_project/stylesheets/screen.css")
32
+ assert_action_performed :directory, "#{framework.name}_project/"
33
+ assert_action_performed :create, "#{framework.name}_project/src/screen.sass"
34
+ assert_action_performed :compile, "#{framework.name}_project/src/screen.sass"
35
+ assert_action_performed :create, "#{framework.name}_project/stylesheets/screen.css"
36
+ end
37
+ end
38
+ end
39
+
40
+ def test_basic_update
41
+ within_tmp_directory do
42
+ compass "basic"
43
+ Dir.chdir "basic" do
44
+ compass
45
+ assert_action_performed :compile, "src/screen.sass"
46
+ assert_action_performed :identical, "stylesheets/screen.css"
47
+ end
48
+ end
49
+ end
50
+
51
+ def test_rails_install
52
+ within_tmp_directory do
53
+ generate_rails_app("compass_rails")
54
+ Dir.chdir "compass_rails" do
55
+ compass("--rails", ".") do |responder|
56
+ responder.respond_to "Is this OK? (Y/n) ", :with => "Y"
57
+ responder.respond_to "Emit compiled stylesheets to public/stylesheets/compiled/? (Y/n) ", :with => "Y"
58
+ end
59
+ # puts @last_result
60
+ assert_action_performed :create, "./app/stylesheets/screen.sass"
61
+ assert_action_performed :create, "./config/initializers/compass.rb"
62
+ end
63
+ end
64
+ rescue LoadError
65
+ puts "Skipping rails test. Couldn't Load rails"
66
+ end
67
+
68
+ protected
69
+ def compass(*arguments)
70
+ if block_given?
71
+ responder = Responder.new
72
+ yield responder
73
+ IO.popen("-", "w+") do |io|
74
+ if io
75
+ #parent process
76
+ output = ""
77
+ while !io.eof?
78
+ timeout(1) do
79
+ output << io.readpartial(512)
80
+ end
81
+ prompt = output.split("\n").last
82
+ if response = responder.response_for(prompt)
83
+ io.puts response
84
+ end
85
+ end
86
+ @last_result = output
87
+ else
88
+ #child process
89
+ execute *arguments
90
+ end
91
+ end
92
+ else
93
+ @last_result = capture_output do
94
+ execute *arguments
95
+ end
96
+ end
97
+ rescue Timeout::Error
98
+ fail "Read from child process timed out"
99
+ end
100
+
101
+ class Responder
102
+ def initialize
103
+ @responses = []
104
+ end
105
+ def respond_to(prompt, options = {})
106
+ @responses << [prompt, options[:with]]
107
+ end
108
+ def response_for(prompt)
109
+ pair = @responses.detect{|r| r.first == prompt}
110
+ pair.last if pair
111
+ end
112
+ end
113
+
114
+ def assert_action_performed(action, path)
115
+ @last_result.split("\n").each do |line|
116
+ line = line.split
117
+ return if line.first == action.to_s && line.last == path
118
+ end
119
+ fail "Action #{action.inspect} was not performed on: #{path}"
120
+ end
121
+
122
+ def within_tmp_directory(dir = "tmp")
123
+ d = absolutize(dir)
124
+ FileUtils.mkdir_p(d)
125
+ Dir.chdir(d) do
126
+ yield
127
+ end
128
+ ensure
129
+ FileUtils.rm_r(d)
130
+ end
131
+
132
+ def capture_output
133
+ real_stdout, $stdout = $stdout, StringIO.new
134
+ yield
135
+ $stdout.string
136
+ ensure
137
+ $stdout = real_stdout
138
+ end
139
+
140
+ def execute(*arguments)
141
+ Compass::Exec::Compass.new(arguments).run!
142
+ end
143
+
144
+ def generate_rails_app(name)
145
+ `rails #{name}`
146
+ end
147
+ end
@@ -0,0 +1,148 @@
1
+ require File.dirname(__FILE__)+'/test_helper'
2
+ require 'fileutils'
3
+ require 'compass'
4
+
5
+ class CompassTest < Test::Unit::TestCase
6
+ include Compass::TestCaseHelper
7
+ def setup
8
+ setup_fixtures :blueprint, :yui, :empty
9
+ @original_options = Sass::Plugin.options
10
+ end
11
+
12
+ def setup_fixtures(*folders)
13
+ folders.each do |folder|
14
+ FileUtils.mkdir_p stylesheet_fixtures(folder)
15
+ mkdir_clean tempfile_loc(folder)
16
+ end
17
+ end
18
+
19
+ def teardown
20
+ teardown_fixtures :blueprint, :yui, :empty
21
+ Sass::Plugin.options = @original_options
22
+ end
23
+
24
+ def teardown_fixtures(*folders)
25
+ folders.each do |folder|
26
+ FileUtils.rm_rf tempfile_loc(folder)
27
+ end
28
+ end
29
+
30
+ def test_blueprint_generates_no_files
31
+ with_templates(:empty) do
32
+ Dir.new(tempfile_loc(:empty)).each do |f|
33
+ fail "This file should not have been generated: #{f}" unless f == "." || f == ".."
34
+ end
35
+ end
36
+ end
37
+
38
+ def test_blueprint
39
+ with_templates(:blueprint) do
40
+ each_css_file(tempfile_loc(:blueprint)) do |css_file|
41
+ assert_no_errors css_file, :blueprint
42
+ end
43
+ assert_renders_correctly :typography
44
+ end
45
+ end
46
+ def test_yui
47
+ with_templates('yui') do
48
+ each_css_file(tempfile_loc('yui')) do |css_file|
49
+ assert_no_errors css_file, 'yui'
50
+ end
51
+ assert_renders_correctly :mixins
52
+ end
53
+ end
54
+ def test_compass
55
+ with_templates('compass') do
56
+ each_css_file(tempfile_loc('compass')) do |css_file|
57
+ assert_no_errors css_file, 'compass'
58
+ end
59
+ assert_renders_correctly :reset, :layout, :utilities
60
+ end
61
+ end
62
+ private
63
+ def assert_no_errors(css_file, folder)
64
+ file = css_file[(tempfile_loc(folder).size+1)..-1]
65
+ msg = "Syntax Error found in #{file}. Results saved into #{save_loc(folder)}/#{file}"
66
+ assert_equal 0, open(css_file).readlines.grep(/Sass::SyntaxError/).size, msg
67
+ end
68
+ def assert_renders_correctly(*arguments)
69
+ options = arguments.last.is_a?(Hash) ? arguments.pop : {}
70
+ for name in arguments
71
+ actual_result_file = "#{tempfile_loc(@current_template_folder)}/#{name}.css"
72
+ expected_result_file = "#{result_loc(@current_template_folder)}/#{name}.css"
73
+ actual_lines = File.read(actual_result_file).split("\n")
74
+ expected_lines = File.read(expected_result_file).split("\n")
75
+ expected_lines.zip(actual_lines).each_with_index do |pair, line|
76
+ message = "template: #{name}\nline: #{line + 1}"
77
+ assert_equal(pair.first, pair.last, message)
78
+ end
79
+ if expected_lines.size < actual_lines.size
80
+ assert(false, "#{actual_lines.size - expected_lines.size} Trailing lines found in #{actual_result_file}.css: #{actual_lines[expected_lines.size..-1].join('\n')}")
81
+ end
82
+ end
83
+ end
84
+ def with_templates(folder)
85
+ old_template_loc = Sass::Plugin.options[:template_location]
86
+ Sass::Plugin.options[:template_location] = if old_template_loc.is_a?(Hash)
87
+ old_template_loc.dup
88
+ else
89
+ Hash.new
90
+ end
91
+ @current_template_folder = folder
92
+ begin
93
+ Sass::Plugin.options[:template_location][template_loc(folder)] = tempfile_loc(folder)
94
+ Compass::Frameworks::ALL.each do |framework|
95
+ Sass::Plugin.options[:template_location][framework.stylesheets_directory] = tempfile_loc(folder)
96
+ end
97
+ Sass::Plugin.update_stylesheets
98
+ yield
99
+ ensure
100
+ @current_template_folder = nil
101
+ Sass::Plugin.options[:template_location] = old_template_loc
102
+ end
103
+ rescue
104
+ save_output(folder)
105
+ raise
106
+ end
107
+
108
+ def each_css_file(dir)
109
+ Dir.glob("#{dir}/**/*.css").each do |css_file|
110
+ yield css_file
111
+ end
112
+ end
113
+
114
+ def save_output(dir)
115
+ FileUtils.rm_rf(save_loc(dir))
116
+ FileUtils.cp_r(tempfile_loc(dir), save_loc(dir))
117
+ end
118
+
119
+ def mkdir_clean(dir)
120
+ begin
121
+ FileUtils.mkdir dir
122
+ rescue Errno::EEXIST
123
+ FileUtils.rm_r dir
124
+ FileUtils.mkdir dir
125
+ end
126
+ end
127
+
128
+ def stylesheet_fixtures(folder)
129
+ absolutize("fixtures/stylesheets/#{folder}")
130
+ end
131
+
132
+ def tempfile_loc(folder)
133
+ "#{stylesheet_fixtures(folder)}/tmp"
134
+ end
135
+
136
+ def template_loc(folder)
137
+ "#{stylesheet_fixtures(folder)}/sass"
138
+ end
139
+
140
+ def result_loc(folder)
141
+ "#{stylesheet_fixtures(folder)}/css"
142
+ end
143
+
144
+ def save_loc(folder)
145
+ "#{stylesheet_fixtures(folder)}/saved"
146
+ end
147
+
148
+ end