compass 0.8.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. data/CHANGELOG.markdown +551 -0
  2. data/LICENSE.markdown +29 -0
  3. data/README.markdown +44 -0
  4. data/REVISION +1 -0
  5. data/Rakefile +127 -0
  6. data/VERSION.yml +4 -0
  7. data/bin/compass +8 -0
  8. data/deps.rip +1 -0
  9. data/examples/README.markdown +4 -0
  10. data/examples/blueprint_default/config.rb +7 -0
  11. data/examples/blueprint_default/images/grid.png +0 -0
  12. data/examples/blueprint_default/index.html.haml +85 -0
  13. data/examples/blueprint_default/parts/elements.html.haml +282 -0
  14. data/examples/blueprint_default/parts/forms.html.haml +190 -0
  15. data/examples/blueprint_default/parts/grid.html.haml +274 -0
  16. data/examples/blueprint_default/parts/test-small.jpg +0 -0
  17. data/examples/blueprint_default/parts/test.jpg +0 -0
  18. data/examples/blueprint_default/parts/valid.png +0 -0
  19. data/examples/blueprint_default/src/ie.sass +3 -0
  20. data/examples/blueprint_default/src/images/grid.png +0 -0
  21. data/examples/blueprint_default/src/print.sass +3 -0
  22. data/examples/blueprint_default/src/screen.sass +8 -0
  23. data/examples/blueprint_plugins/config.rb +8 -0
  24. data/examples/blueprint_plugins/images/buttons/cross.png +0 -0
  25. data/examples/blueprint_plugins/images/buttons/key.png +0 -0
  26. data/examples/blueprint_plugins/images/buttons/tick.png +0 -0
  27. data/examples/blueprint_plugins/images/grid.png +0 -0
  28. data/examples/blueprint_plugins/images/link_icons/doc.png +0 -0
  29. data/examples/blueprint_plugins/images/link_icons/email.png +0 -0
  30. data/examples/blueprint_plugins/images/link_icons/external.png +0 -0
  31. data/examples/blueprint_plugins/images/link_icons/feed.png +0 -0
  32. data/examples/blueprint_plugins/images/link_icons/im.png +0 -0
  33. data/examples/blueprint_plugins/images/link_icons/pdf.png +0 -0
  34. data/examples/blueprint_plugins/images/link_icons/visited.png +0 -0
  35. data/examples/blueprint_plugins/images/link_icons/xls.png +0 -0
  36. data/examples/blueprint_plugins/images/test-small.jpg +0 -0
  37. data/examples/blueprint_plugins/images/test.jpg +0 -0
  38. data/examples/blueprint_plugins/images/valid.png +0 -0
  39. data/examples/blueprint_plugins/index.html.haml +96 -0
  40. data/examples/blueprint_plugins/plugins/buttons.html.haml +67 -0
  41. data/examples/blueprint_plugins/plugins/fancy_type.html.haml +100 -0
  42. data/examples/blueprint_plugins/plugins/link_icons.html.haml +61 -0
  43. data/examples/blueprint_plugins/plugins/rtl.html.haml +100 -0
  44. data/examples/blueprint_plugins/src/buttons.sass +49 -0
  45. data/examples/blueprint_plugins/src/ie.sass +3 -0
  46. data/examples/blueprint_plugins/src/images/grid.png +0 -0
  47. data/examples/blueprint_plugins/src/link_icons.sass +13 -0
  48. data/examples/blueprint_plugins/src/print.sass +3 -0
  49. data/examples/blueprint_plugins/src/rtl_screen.sass +13 -0
  50. data/examples/blueprint_plugins/src/screen.sass +11 -0
  51. data/examples/blueprint_scoped/images/grid.png +0 -0
  52. data/examples/blueprint_scoped/src/ie.sass +3 -0
  53. data/examples/blueprint_scoped/src/print.sass +3 -0
  54. data/examples/blueprint_scoped/src/screen.sass +4 -0
  55. data/examples/blueprint_scoped_form/images/grid.png +0 -0
  56. data/examples/blueprint_scoped_form/src/ie.sass +3 -0
  57. data/examples/blueprint_scoped_form/src/print.sass +3 -0
  58. data/examples/blueprint_scoped_form/src/screen.sass +10 -0
  59. data/examples/blueprint_semantic/config.rb +7 -0
  60. data/examples/blueprint_semantic/images/grid.png +0 -0
  61. data/examples/blueprint_semantic/index.html.haml +86 -0
  62. data/examples/blueprint_semantic/parts/fancy_type.html.haml +100 -0
  63. data/examples/blueprint_semantic/parts/liquid.html.haml +100 -0
  64. data/examples/blueprint_semantic/parts/test-small.jpg +0 -0
  65. data/examples/blueprint_semantic/parts/test.jpg +0 -0
  66. data/examples/blueprint_semantic/parts/valid.png +0 -0
  67. data/examples/blueprint_semantic/src/ie.sass +3 -0
  68. data/examples/blueprint_semantic/src/images/grid.png +0 -0
  69. data/examples/blueprint_semantic/src/liquid.sass +70 -0
  70. data/examples/blueprint_semantic/src/print.sass +3 -0
  71. data/examples/blueprint_semantic/src/screen.sass +71 -0
  72. data/examples/compass/compass.html.haml +39 -0
  73. data/examples/compass/config.rb +7 -0
  74. data/examples/compass/images/blue_arrow.gif +0 -0
  75. data/examples/compass/src/compass.sass +47 -0
  76. data/examples/compass/src/images/blue_arrow.gif +0 -0
  77. data/examples/compass/src/sticky_footer.sass +11 -0
  78. data/examples/compass/src/utilities.sass +108 -0
  79. data/examples/compass/sticky_footer.html.haml +14 -0
  80. data/examples/compass/utilities.html.haml +189 -0
  81. data/examples/logo/logo.html.haml +40 -0
  82. data/examples/logo/src/ie.sass +6 -0
  83. data/examples/logo/src/print.sass +6 -0
  84. data/examples/logo/src/screen.sass +29 -0
  85. data/examples/yui/divisions.html.haml +179 -0
  86. data/examples/yui/index.html.haml +19 -0
  87. data/examples/yui/src/screen.sass +13 -0
  88. data/examples/yui/sub_divisions.html.haml +169 -0
  89. data/examples/yui/templates.html.haml +54 -0
  90. data/examples/yui/test.jpg +0 -0
  91. data/examples/yui/typography.html.haml +132 -0
  92. data/frameworks/blueprint.rb +2 -0
  93. data/frameworks/blueprint/stylesheets/_blueprint.sass +3 -0
  94. data/frameworks/blueprint/stylesheets/blueprint/_ie.sass +93 -0
  95. data/frameworks/blueprint/stylesheets/blueprint/_print.sass +83 -0
  96. data/frameworks/blueprint/stylesheets/blueprint/_reset.sass +3 -0
  97. data/frameworks/blueprint/stylesheets/blueprint/_screen.sass +15 -0
  98. data/frameworks/blueprint/stylesheets/blueprint/modules/_buttons.sass +84 -0
  99. data/frameworks/blueprint/stylesheets/blueprint/modules/_colors.sass +33 -0
  100. data/frameworks/blueprint/stylesheets/blueprint/modules/_debug.sass +9 -0
  101. data/frameworks/blueprint/stylesheets/blueprint/modules/_fancy_type.sass +82 -0
  102. data/frameworks/blueprint/stylesheets/blueprint/modules/_form.sass +55 -0
  103. data/frameworks/blueprint/stylesheets/blueprint/modules/_grid.sass +178 -0
  104. data/frameworks/blueprint/stylesheets/blueprint/modules/_interaction.sass +58 -0
  105. data/frameworks/blueprint/stylesheets/blueprint/modules/_link_icons.sass +44 -0
  106. data/frameworks/blueprint/stylesheets/blueprint/modules/_liquid.sass +141 -0
  107. data/frameworks/blueprint/stylesheets/blueprint/modules/_reset.sass +56 -0
  108. data/frameworks/blueprint/stylesheets/blueprint/modules/_rtl.sass +104 -0
  109. data/frameworks/blueprint/stylesheets/blueprint/modules/_scaffolding.sass +47 -0
  110. data/frameworks/blueprint/stylesheets/blueprint/modules/_typography.sass +155 -0
  111. data/frameworks/blueprint/stylesheets/blueprint/modules/_utilities.sass +37 -0
  112. data/frameworks/blueprint/templates/buttons/buttons.sass +49 -0
  113. data/frameworks/blueprint/templates/buttons/buttons/cross.png +0 -0
  114. data/frameworks/blueprint/templates/buttons/buttons/key.png +0 -0
  115. data/frameworks/blueprint/templates/buttons/buttons/tick.png +0 -0
  116. data/frameworks/blueprint/templates/buttons/manifest.rb +5 -0
  117. data/frameworks/blueprint/templates/link_icons/link_icons.sass +13 -0
  118. data/frameworks/blueprint/templates/link_icons/link_icons/doc.png +0 -0
  119. data/frameworks/blueprint/templates/link_icons/link_icons/email.png +0 -0
  120. data/frameworks/blueprint/templates/link_icons/link_icons/external.png +0 -0
  121. data/frameworks/blueprint/templates/link_icons/link_icons/feed.png +0 -0
  122. data/frameworks/blueprint/templates/link_icons/link_icons/im.png +0 -0
  123. data/frameworks/blueprint/templates/link_icons/link_icons/pdf.png +0 -0
  124. data/frameworks/blueprint/templates/link_icons/link_icons/visited.png +0 -0
  125. data/frameworks/blueprint/templates/link_icons/link_icons/xls.png +0 -0
  126. data/frameworks/blueprint/templates/link_icons/manifest.rb +10 -0
  127. data/frameworks/blueprint/templates/project/grid.png +0 -0
  128. data/frameworks/blueprint/templates/project/ie.sass +15 -0
  129. data/frameworks/blueprint/templates/project/manifest.rb +6 -0
  130. data/frameworks/blueprint/templates/project/partials/_base.sass +11 -0
  131. data/frameworks/blueprint/templates/project/print.sass +3 -0
  132. data/frameworks/blueprint/templates/project/screen.sass +40 -0
  133. data/frameworks/compass.rb +2 -0
  134. data/frameworks/compass/stylesheets/_compass.sass +1 -0
  135. data/frameworks/compass/stylesheets/compass/_layout.sass +1 -0
  136. data/frameworks/compass/stylesheets/compass/_misc.sass +24 -0
  137. data/frameworks/compass/stylesheets/compass/_reset.sass +3 -0
  138. data/frameworks/compass/stylesheets/compass/_utilities.sass +6 -0
  139. data/frameworks/compass/stylesheets/compass/layout/_sticky_footer.sass +17 -0
  140. data/frameworks/compass/stylesheets/compass/utilities/_general.sass +6 -0
  141. data/frameworks/compass/stylesheets/compass/utilities/_links.sass +3 -0
  142. data/frameworks/compass/stylesheets/compass/utilities/_lists.sass +3 -0
  143. data/frameworks/compass/stylesheets/compass/utilities/_print.sass +24 -0
  144. data/frameworks/compass/stylesheets/compass/utilities/_sprites.sass +1 -0
  145. data/frameworks/compass/stylesheets/compass/utilities/_tables.sass +3 -0
  146. data/frameworks/compass/stylesheets/compass/utilities/_text.sass +2 -0
  147. data/frameworks/compass/stylesheets/compass/utilities/general/_clearfix.sass +24 -0
  148. data/frameworks/compass/stylesheets/compass/utilities/general/_float.sass +17 -0
  149. data/frameworks/compass/stylesheets/compass/utilities/general/_hacks.sass +6 -0
  150. data/frameworks/compass/stylesheets/compass/utilities/general/_inline_block.sass +6 -0
  151. data/frameworks/compass/stylesheets/compass/utilities/general/_reset.sass +134 -0
  152. data/frameworks/compass/stylesheets/compass/utilities/general/_tabs.sass +0 -0
  153. data/frameworks/compass/stylesheets/compass/utilities/general/_tag_cloud.sass +19 -0
  154. data/frameworks/compass/stylesheets/compass/utilities/links/_hover_link.sass +5 -0
  155. data/frameworks/compass/stylesheets/compass/utilities/links/_link_colors.sass +24 -0
  156. data/frameworks/compass/stylesheets/compass/utilities/links/_unstyled_link.sass +5 -0
  157. data/frameworks/compass/stylesheets/compass/utilities/lists/_bullets.sass +21 -0
  158. data/frameworks/compass/stylesheets/compass/utilities/lists/_horizontal_list.sass +52 -0
  159. data/frameworks/compass/stylesheets/compass/utilities/lists/_inline_list.sass +29 -0
  160. data/frameworks/compass/stylesheets/compass/utilities/sprites/_sprite_img.sass +12 -0
  161. data/frameworks/compass/stylesheets/compass/utilities/tables/_alternating_rows_and_columns.sass +20 -0
  162. data/frameworks/compass/stylesheets/compass/utilities/tables/_borders.sass +27 -0
  163. data/frameworks/compass/stylesheets/compass/utilities/tables/_scaffolding.sass +9 -0
  164. data/frameworks/compass/stylesheets/compass/utilities/text/_ellipsis.sass +13 -0
  165. data/frameworks/compass/stylesheets/compass/utilities/text/_nowrap.sass +3 -0
  166. data/frameworks/compass/stylesheets/compass/utilities/text/_replacement.sass +17 -0
  167. data/frameworks/compass/templates/ellipsis/ellipsis.sass +6 -0
  168. data/frameworks/compass/templates/ellipsis/manifest.rb +2 -0
  169. data/frameworks/compass/templates/ellipsis/xml/ellipsis.xml +14 -0
  170. data/frameworks/compass/templates/project/ie.sass +6 -0
  171. data/frameworks/compass/templates/project/manifest.rb +3 -0
  172. data/frameworks/compass/templates/project/print.sass +6 -0
  173. data/frameworks/compass/templates/project/screen.sass +13 -0
  174. data/frameworks/yui.rb +2 -0
  175. data/frameworks/yui/stylesheets/_yui.sass +7 -0
  176. data/frameworks/yui/stylesheets/yui/modules/_base.sass +60 -0
  177. data/frameworks/yui/stylesheets/yui/modules/_fonts.sass +38 -0
  178. data/frameworks/yui/stylesheets/yui/modules/_grids.sass +341 -0
  179. data/frameworks/yui/stylesheets/yui/modules/_reset.sass +61 -0
  180. data/frameworks/yui/templates/project/manifest.rb +1 -0
  181. data/frameworks/yui/templates/project/screen.sass +4 -0
  182. data/lib/compass.rb +23 -0
  183. data/lib/compass/actions.rb +110 -0
  184. data/lib/compass/app_integration.rb +5 -0
  185. data/lib/compass/app_integration/merb.rb +43 -0
  186. data/lib/compass/app_integration/rails.rb +12 -0
  187. data/lib/compass/app_integration/rails/action_controller.rb +15 -0
  188. data/lib/compass/app_integration/rails/sass_plugin.rb +5 -0
  189. data/lib/compass/app_integration/rails/templates/compass-install-rails.rb +80 -0
  190. data/lib/compass/app_integration/rails/urls.rb +14 -0
  191. data/lib/compass/commands/base.rb +33 -0
  192. data/lib/compass/commands/create_project.rb +19 -0
  193. data/lib/compass/commands/generate_grid_background.rb +24 -0
  194. data/lib/compass/commands/installer_command.rb +31 -0
  195. data/lib/compass/commands/list_frameworks.rb +16 -0
  196. data/lib/compass/commands/print_version.rb +23 -0
  197. data/lib/compass/commands/project_base.rb +112 -0
  198. data/lib/compass/commands/stamp_pattern.rb +33 -0
  199. data/lib/compass/commands/update_project.rb +34 -0
  200. data/lib/compass/commands/validate_project.rb +21 -0
  201. data/lib/compass/commands/watch_project.rb +64 -0
  202. data/lib/compass/commands/write_configuration.rb +28 -0
  203. data/lib/compass/compiler.rb +54 -0
  204. data/lib/compass/configuration.rb +324 -0
  205. data/lib/compass/core_ext.rb +14 -0
  206. data/lib/compass/dependencies.rb +10 -0
  207. data/lib/compass/errors.rb +7 -0
  208. data/lib/compass/exec.rb +251 -0
  209. data/lib/compass/frameworks.rb +29 -0
  210. data/lib/compass/grid_builder.rb +72 -0
  211. data/lib/compass/installers.rb +5 -0
  212. data/lib/compass/installers/base.rb +158 -0
  213. data/lib/compass/installers/manifest.rb +58 -0
  214. data/lib/compass/installers/rails.rb +135 -0
  215. data/lib/compass/installers/stand_alone.rb +60 -0
  216. data/lib/compass/logger.rb +42 -0
  217. data/lib/compass/sass_extensions.rb +5 -0
  218. data/lib/compass/sass_extensions/functions.rb +19 -0
  219. data/lib/compass/sass_extensions/functions/display.rb +22 -0
  220. data/lib/compass/sass_extensions/functions/enumerate.rb +6 -0
  221. data/lib/compass/sass_extensions/functions/inline_image.rb +35 -0
  222. data/lib/compass/sass_extensions/functions/selectors.rb +39 -0
  223. data/lib/compass/sass_extensions/functions/urls.rb +105 -0
  224. data/lib/compass/sass_extensions/monkey_patches.rb +3 -0
  225. data/lib/compass/sass_extensions/monkey_patches/stylesheet_updating.rb +23 -0
  226. data/lib/compass/test_case.rb +38 -0
  227. data/lib/compass/validator.rb +10 -0
  228. data/lib/compass/version.rb +57 -0
  229. data/lib/vendor/fssm.rb +41 -0
  230. data/lib/vendor/fssm/backends/fsevents.rb +37 -0
  231. data/lib/vendor/fssm/backends/polling.rb +26 -0
  232. data/lib/vendor/fssm/cache.rb +193 -0
  233. data/lib/vendor/fssm/ext.rb +37 -0
  234. data/lib/vendor/fssm/fsevents.rb +129 -0
  235. data/lib/vendor/fssm/monitor.rb +25 -0
  236. data/lib/vendor/fssm/path.rb +91 -0
  237. data/lib/vendor/fssm/state.rb +54 -0
  238. data/lib/vendor/fssm/support.rb +22 -0
  239. data/lib/vendor/fssm/tree.rb +176 -0
  240. data/test/command_line_helper.rb +102 -0
  241. data/test/command_line_test.rb +66 -0
  242. data/test/compass_test.rb +141 -0
  243. data/test/configuration_test.rb +118 -0
  244. data/test/fixtures/stylesheets/blueprint/config.rb +9 -0
  245. data/test/fixtures/stylesheets/blueprint/css/typography.css +158 -0
  246. data/test/fixtures/stylesheets/blueprint/images/grid.png +0 -0
  247. data/test/fixtures/stylesheets/blueprint/sass/ie.sass +3 -0
  248. data/test/fixtures/stylesheets/blueprint/sass/print.sass +3 -0
  249. data/test/fixtures/stylesheets/blueprint/sass/screen.sass +17 -0
  250. data/test/fixtures/stylesheets/blueprint/sass/typography.sass +3 -0
  251. data/test/fixtures/stylesheets/compass/config.rb +9 -0
  252. data/test/fixtures/stylesheets/compass/css/layout.css +13 -0
  253. data/test/fixtures/stylesheets/compass/css/print.css +18 -0
  254. data/test/fixtures/stylesheets/compass/css/reset.css +60 -0
  255. data/test/fixtures/stylesheets/compass/css/utilities.css +17 -0
  256. data/test/fixtures/stylesheets/compass/sass/layout.sass +3 -0
  257. data/test/fixtures/stylesheets/compass/sass/print.sass +5 -0
  258. data/test/fixtures/stylesheets/compass/sass/reset.sass +10 -0
  259. data/test/fixtures/stylesheets/compass/sass/utilities.sass +6 -0
  260. data/test/fixtures/stylesheets/image_urls/config.rb +17 -0
  261. data/test/fixtures/stylesheets/image_urls/css/screen.css +3 -0
  262. data/test/fixtures/stylesheets/image_urls/images/grid.png +0 -0
  263. data/test/fixtures/stylesheets/image_urls/sass/screen.sass +6 -0
  264. data/test/fixtures/stylesheets/yui/config.rb +9 -0
  265. data/test/fixtures/stylesheets/yui/css/mixins.css +13 -0
  266. data/test/fixtures/stylesheets/yui/sass/base.sass +3 -0
  267. data/test/fixtures/stylesheets/yui/sass/fonts.sass +3 -0
  268. data/test/fixtures/stylesheets/yui/sass/grids.sass +3 -0
  269. data/test/fixtures/stylesheets/yui/sass/mixins.sass +16 -0
  270. data/test/rails_integration_test.rb +83 -0
  271. data/test/sass_extensions_test.rb +31 -0
  272. data/test/test_case_helper.rb +13 -0
  273. data/test/test_helper.rb +21 -0
  274. data/test/test_rails_helper.rb +20 -0
  275. metadata +372 -0
@@ -0,0 +1,3 @@
1
+ ['stylesheet_updating'].each do |patch|
2
+ require File.join(File.dirname(__FILE__), 'monkey_patches', patch)
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'sass/plugin'
2
+
3
+ # XXX: We can remove this monkeypatch once Sass 2.2 is released.
4
+ module Sass::Plugin
5
+ class << self
6
+ unless method_defined?(:exact_stylesheet_needs_update?)
7
+ def stylesheet_needs_update?(name, template_path, css_path)
8
+ css_file = css_filename(name, css_path)
9
+ template_file = template_filename(name, template_path)
10
+ exact_stylesheet_needs_update?(css_file, template_file)
11
+ end
12
+ def exact_stylesheet_needs_update?(css_file, template_file)
13
+ if !File.exists?(css_file)
14
+ return true
15
+ else
16
+ css_mtime = File.mtime(css_file)
17
+ File.mtime(template_file) > css_mtime ||
18
+ dependencies(template_file).any?(&dependency_updated?(css_mtime))
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ module Compass
2
+ # Write your unit test like this if you want to make sure all your stylesheets compile.
3
+ #
4
+ # require 'compass/test_case'
5
+ # class StylesheetsTest < Compass::TestCase
6
+ # def test_stylesheets
7
+ # my_sass_files.each do |sass_file|
8
+ # assert_compiles(sass_file) do |result|
9
+ # assert_not_blank result
10
+ # end
11
+ # end
12
+ # end
13
+ # protected
14
+ # def my_sass_files
15
+ # Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), "../..", "app/stylesheets/**/[^_]*.sass")))
16
+ # end
17
+ # end
18
+ class TestCase < (defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase)
19
+
20
+ def setup
21
+ super
22
+ @last_compile = nil
23
+ end
24
+
25
+ def compile(stylesheet)
26
+ input = open(stylesheet)
27
+ template = input.read()
28
+ input.close()
29
+ @last_compile = ::Sass::Engine.new(template, ::Sass::Plugin.engine_options(:filename => stylesheet)).render
30
+ yield @last_compile if block_given?
31
+ end
32
+
33
+ def assert_compiles(stylesheet, &block)
34
+ compile(stylesheet, &block)
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'rubygems'
3
+ require 'compass-validator'
4
+ rescue LoadError
5
+ puts %Q{The Compass CSS Validator could not be loaded. Please install it:
6
+
7
+ sudo gem install chriseppstein-compass-validator --source http://gems.github.com/
8
+ }
9
+ exit(1)
10
+ end
@@ -0,0 +1,57 @@
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
+ # The :rev key will have the current revision hash.
7
+ #
8
+ # This method swiped from Haml and then modified, some credit goes to Nathan Weizenbaum
9
+ attr_writer :version
10
+ def version
11
+ return @version if defined?(@version)
12
+
13
+ read_version_file
14
+
15
+ if r = revision
16
+ @version[:rev] = r
17
+ @version[:string] << " [#{r[0...7]}]"
18
+ end
19
+
20
+ @version
21
+ end
22
+
23
+ protected
24
+
25
+ def scope(file) # :nodoc:
26
+ File.join(File.dirname(__FILE__), '..', '..', file)
27
+ end
28
+
29
+ def read_version_file
30
+ require 'yaml'
31
+ @version = YAML::load(File.read(scope('VERSION.yml')))
32
+ @version[:string] = "#{@version[:major]}.#{@version[:minor]}.#{@version[:patch]}"
33
+ @version[:teeny] = @version[:patch]
34
+ end
35
+
36
+ def revision
37
+ revision_from_git || revision_from_file
38
+ end
39
+
40
+ def revision_from_file
41
+ if File.exists?(scope('REVISION'))
42
+ rev = File.read(scope('REVISION')).strip
43
+ rev if rev =~ /[a-f0-9]+/
44
+ end
45
+ end
46
+
47
+ def revision_from_git
48
+ if File.exists?(scope('.git/HEAD'))
49
+ rev = File.read(scope('.git/HEAD')).strip
50
+ if rev =~ /^ref: (.*)$/
51
+ rev = File.read(scope(".git/#{$1}")).strip
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,41 @@
1
+ dir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
3
+
4
+ module FSSM
5
+ FileNotFoundError = Class.new(StandardError)
6
+ CallbackError = Class.new(StandardError)
7
+
8
+ class << self
9
+ def dbg(msg=nil)
10
+ STDERR.puts(msg)
11
+ end
12
+
13
+ def monitor(*args, &block)
14
+ monitor = FSSM::Monitor.new
15
+ context = args.empty? ? monitor : monitor.path(*args)
16
+
17
+ if block_given?
18
+ if block.arity == 1
19
+ block.call(context)
20
+ else
21
+ context.instance_eval(&block)
22
+ end
23
+ end
24
+
25
+ monitor.run
26
+ end
27
+ end
28
+ end
29
+
30
+ require 'thread'
31
+ require 'pathname'
32
+
33
+ require 'fssm/ext'
34
+ require 'fssm/support'
35
+ require 'fssm/tree'
36
+ require 'fssm/path'
37
+ require 'fssm/state'
38
+ require 'fssm/monitor'
39
+
40
+ require "fssm/backends/#{FSSM::Support.backend.downcase}"
41
+ FSSM::Backends::Default = FSSM::Backends.const_get(FSSM::Support.backend)
@@ -0,0 +1,37 @@
1
+ require 'fssm/fsevents'
2
+
3
+ module FSSM::Backends
4
+ class FSEvents
5
+ def initialize
6
+ @handlers = {}
7
+ @fsevents = []
8
+ end
9
+
10
+ def add_path(path, preload=true)
11
+ handler = FSSM::State.new(path)
12
+ @handlers["#{path}"] = handler
13
+
14
+ fsevent = Rucola::FSEvents.new("#{path}", {:latency => 0.5}) do |events|
15
+ events.each do |event|
16
+ handler.refresh(event.path)
17
+ end
18
+ end
19
+
20
+ fsevent.create_stream
21
+ handler.refresh(path.to_pathname, true) if preload
22
+ fsevent.start
23
+ @fsevents << fsevent
24
+ end
25
+
26
+ def run
27
+ begin
28
+ OSX.CFRunLoopRun
29
+ rescue Interrupt
30
+ @fsevents.each do |fsev|
31
+ fsev.stop
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ module FSSM::Backends
2
+ class Polling
3
+ def initialize(options={})
4
+ @handlers = []
5
+ @latency = options[:latency] || 1
6
+ end
7
+
8
+ def add_path(path, preload=true)
9
+ handler = FSSM::State.new(path)
10
+ handler.refresh(path.to_pathname, true) if preload
11
+ @handlers << handler
12
+ end
13
+
14
+ def run
15
+ begin
16
+ loop do
17
+ start = Time.now.to_f
18
+ @handlers.each {|handler| handler.refresh}
19
+ nap_time = @latency - (Time.now.to_f - start)
20
+ sleep nap_time if nap_time > 0
21
+ end
22
+ rescue Interrupt
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,193 @@
1
+ class FSSM::Cache
2
+ module Common
3
+ include Enumerable
4
+
5
+ def initialize
6
+ @children = Hash.new
7
+ end
8
+
9
+ def each(prefix='./', &block)
10
+ @children.each do |segment, node|
11
+ cprefix = Pathname.for(prefix.dup).join(segment)
12
+ block.call(cprefix, node)
13
+ node.each(cprefix, &block)
14
+ end
15
+ end
16
+
17
+ protected
18
+
19
+ def with_lock
20
+ @mutex.lock
21
+ yield
22
+ @mutex.unlock
23
+ end
24
+
25
+ def descendant(path)
26
+ recurse_on_key(path, false)
27
+ end
28
+
29
+ def descendant!(path)
30
+ recurse_on_key(path, true)
31
+ end
32
+
33
+ def child(segment)
34
+ has_child?(segment) ? @children["#{segment}"] : nil
35
+ end
36
+
37
+ def child!(segment)
38
+ (@children["#{segment}"] ||= Node.new)
39
+ end
40
+
41
+ def has_child?(segment)
42
+ @children.include?("#{segment}")
43
+ end
44
+
45
+ def remove_child(segment)
46
+ @children.delete("#{segment}")
47
+ end
48
+
49
+ def remove_children
50
+ @children.clear
51
+ end
52
+
53
+ def recurse_on_key(key, create)
54
+ key = sanitize_key(key)
55
+ node = self
56
+
57
+ until key.empty?
58
+ segment = key.shift
59
+ node = create ? node.child!(segment) : node.child(segment)
60
+ return nil unless node
61
+ end
62
+
63
+ node
64
+ end
65
+
66
+ def key_for_path(path)
67
+ Pathname.for(path).names
68
+ end
69
+
70
+ def relative_path(path)
71
+ sanitize_path(path, false)
72
+ end
73
+
74
+ def absolute_path(path)
75
+ sanitize_path(path, true)
76
+ end
77
+
78
+ def sanitize_path(path, absolute)
79
+ if path.is_a?(Array)
80
+ first = absolute ? '/' : path.shift
81
+ path = path.inject(Pathname.new("#{first}")) do |pathname, segment|
82
+ pathname.join("#{segment}")
83
+ end
84
+ path
85
+ else
86
+ path = Pathname.for(path)
87
+ absolute ? path.expand_path : path
88
+ end
89
+ end
90
+ end
91
+
92
+ class Node
93
+ include Common
94
+
95
+ attr_accessor :mtime
96
+ attr_accessor :ftype
97
+
98
+ def <=>(other)
99
+ self.mtime <=> other.mtime
100
+ end
101
+
102
+ def from_path(path)
103
+ path = absolute_path(path)
104
+ @mtime = path.mtime
105
+ @ftype = path.ftype
106
+ end
107
+
108
+ protected
109
+
110
+ def sanitize_key(key)
111
+ key_for_path(relative_path(key))
112
+ end
113
+ end
114
+
115
+ include Common
116
+
117
+ def initialize
118
+ @mutex = Mutex.new
119
+ super
120
+ end
121
+
122
+ def clear
123
+ @mutex.lock
124
+ @children.clear
125
+ @mutex.unlock
126
+ end
127
+
128
+ def set(path)
129
+ unset(path)
130
+ node = descendant!(path)
131
+ node.from_path(path)
132
+ node.mtime
133
+ end
134
+
135
+ def unset(path='/')
136
+ key = sanitize_key(path)
137
+
138
+ if key.empty?
139
+ self.clear
140
+ return nil
141
+ end
142
+
143
+ segment = key.pop
144
+ node = descendant(key)
145
+
146
+ return unless node
147
+
148
+ @mutex.lock
149
+ node.remove_child(segment)
150
+ @mutex.unlock
151
+
152
+ nil
153
+ end
154
+
155
+ def files
156
+ ftype('file')
157
+ end
158
+
159
+ def directories
160
+ ftype('directory')
161
+ end
162
+
163
+ protected
164
+
165
+ def each(&block)
166
+ prefix='/'
167
+ super(prefix, &block)
168
+ end
169
+
170
+ def ftype(ft)
171
+ inject({}) do |hash, entry|
172
+ path, node = entry
173
+ hash["#{path}"] = node.mtime if node.ftype == ft
174
+ hash
175
+ end
176
+ end
177
+
178
+ def descendant(path)
179
+ node = recurse_on_key(path, false)
180
+ node
181
+ end
182
+
183
+ def descendant!(path)
184
+ @mutex.lock
185
+ node = recurse_on_key(path, true)
186
+ @mutex.unlock
187
+ node
188
+ end
189
+
190
+ def sanitize_key(key)
191
+ key_for_path(absolute_path(key))
192
+ end
193
+ end
@@ -0,0 +1,37 @@
1
+ class Pathname
2
+ class << self
3
+ def for(path)
4
+ path.is_a?(Pathname) ? path : new(path)
5
+ end
6
+ end
7
+
8
+ # before overwriting chop_basename:
9
+ # %total - 29.50%
10
+ # %self - 20.50%
11
+ # after overwriting chop_basename:
12
+ # %total - 24.36%
13
+ # %self - 15.47%
14
+ CHOP_PAT = /\A#{SEPARATOR_PAT}?\z/
15
+ def chop_basename(path)
16
+ base = File.basename(path)
17
+ # the original version of this method recalculates this regexp
18
+ # each run, despite the pattern never changing.
19
+ if CHOP_PAT =~ base
20
+ return nil
21
+ else
22
+ return path[0, path.rindex(base)], base
23
+ end
24
+ end
25
+
26
+ def segments
27
+ prefix, names = split_names(@path)
28
+ names.unshift(prefix) unless prefix.empty?
29
+ names.shift if names[0] == '.'
30
+ names
31
+ end
32
+
33
+ def names
34
+ prefix, names = split_names(@path)
35
+ names
36
+ end
37
+ end