haml-more 0.4.0.a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. data/README.md +79 -0
  2. data/lib/haml/more/coffee_script.rb +137 -0
  3. data/lib/haml/more/content_for.rb +25 -0
  4. data/lib/haml/more.rb +45 -0
  5. data/lib/haml-more.rb +1 -0
  6. data/lib/sass/more.rb +16 -0
  7. data/lib/sass-more.rb +1 -0
  8. data/spec/sass/more_spec.rb +21 -0
  9. data/vendor/coffee-script/Cakefile +57 -0
  10. data/vendor/coffee-script/LICENSE +22 -0
  11. data/vendor/coffee-script/README +41 -0
  12. data/vendor/coffee-script/Rakefile +20 -0
  13. data/vendor/coffee-script/bin/cake +7 -0
  14. data/vendor/coffee-script/bin/coffee +7 -0
  15. data/vendor/coffee-script/documentation/coffee/aliases.coffee +9 -0
  16. data/vendor/coffee-script/documentation/coffee/arguments.coffee +4 -0
  17. data/vendor/coffee-script/documentation/coffee/array_comprehensions.coffee +7 -0
  18. data/vendor/coffee-script/documentation/coffee/assignment.coffee +2 -0
  19. data/vendor/coffee-script/documentation/coffee/cake_tasks.coffee +5 -0
  20. data/vendor/coffee-script/documentation/coffee/comparisons.coffee +5 -0
  21. data/vendor/coffee-script/documentation/coffee/conditionals.coffee +9 -0
  22. data/vendor/coffee-script/documentation/coffee/embedded.coffee +5 -0
  23. data/vendor/coffee-script/documentation/coffee/existence.coffee +8 -0
  24. data/vendor/coffee-script/documentation/coffee/expressions.coffee +9 -0
  25. data/vendor/coffee-script/documentation/coffee/expressions_assignment.coffee +1 -0
  26. data/vendor/coffee-script/documentation/coffee/expressions_comprehension.coffee +3 -0
  27. data/vendor/coffee-script/documentation/coffee/expressions_try.coffee +6 -0
  28. data/vendor/coffee-script/documentation/coffee/fat_arrow.coffee +6 -0
  29. data/vendor/coffee-script/documentation/coffee/functions.coffee +2 -0
  30. data/vendor/coffee-script/documentation/coffee/heredocs.coffee +5 -0
  31. data/vendor/coffee-script/documentation/coffee/multiple_return_values.coffee +5 -0
  32. data/vendor/coffee-script/documentation/coffee/object_comprehensions.coffee +4 -0
  33. data/vendor/coffee-script/documentation/coffee/object_extraction.coffee +13 -0
  34. data/vendor/coffee-script/documentation/coffee/objects_and_arrays.coffee +13 -0
  35. data/vendor/coffee-script/documentation/coffee/overview.coffee +29 -0
  36. data/vendor/coffee-script/documentation/coffee/parallel_assignment.coffee +4 -0
  37. data/vendor/coffee-script/documentation/coffee/range_comprehensions.coffee +6 -0
  38. data/vendor/coffee-script/documentation/coffee/scope.coffee +5 -0
  39. data/vendor/coffee-script/documentation/coffee/slices.coffee +6 -0
  40. data/vendor/coffee-script/documentation/coffee/soaks.coffee +1 -0
  41. data/vendor/coffee-script/documentation/coffee/splats.coffee +25 -0
  42. data/vendor/coffee-script/documentation/coffee/splices.coffee +5 -0
  43. data/vendor/coffee-script/documentation/coffee/strings.coffee +8 -0
  44. data/vendor/coffee-script/documentation/coffee/super.coffee +34 -0
  45. data/vendor/coffee-script/documentation/coffee/switch.coffee +10 -0
  46. data/vendor/coffee-script/documentation/coffee/try.coffee +7 -0
  47. data/vendor/coffee-script/documentation/coffee/while.coffee +10 -0
  48. data/vendor/coffee-script/documentation/css/docs.css +213 -0
  49. data/vendor/coffee-script/documentation/css/idle.css +63 -0
  50. data/vendor/coffee-script/documentation/css/logo.png +0 -0
  51. data/vendor/coffee-script/documentation/index.html.erb +967 -0
  52. data/vendor/coffee-script/documentation/js/aliases.js +14 -0
  53. data/vendor/coffee-script/documentation/js/arguments.js +8 -0
  54. data/vendor/coffee-script/documentation/js/array_comprehensions.js +26 -0
  55. data/vendor/coffee-script/documentation/js/assignment.js +5 -0
  56. data/vendor/coffee-script/documentation/js/cake_tasks.js +14 -0
  57. data/vendor/coffee-script/documentation/js/comparisons.js +5 -0
  58. data/vendor/coffee-script/documentation/js/conditionals.js +12 -0
  59. data/vendor/coffee-script/documentation/js/embedded.js +6 -0
  60. data/vendor/coffee-script/documentation/js/existence.js +7 -0
  61. data/vendor/coffee-script/documentation/js/expressions.js +13 -0
  62. data/vendor/coffee-script/documentation/js/expressions_assignment.js +4 -0
  63. data/vendor/coffee-script/documentation/js/expressions_comprehension.js +12 -0
  64. data/vendor/coffee-script/documentation/js/expressions_try.js +9 -0
  65. data/vendor/coffee-script/documentation/js/fat_arrow.js +15 -0
  66. data/vendor/coffee-script/documentation/js/functions.js +9 -0
  67. data/vendor/coffee-script/documentation/js/heredocs.js +4 -0
  68. data/vendor/coffee-script/documentation/js/intro.js +7 -0
  69. data/vendor/coffee-script/documentation/js/multiple_return_values.js +11 -0
  70. data/vendor/coffee-script/documentation/js/object_comprehensions.js +17 -0
  71. data/vendor/coffee-script/documentation/js/object_extraction.js +17 -0
  72. data/vendor/coffee-script/documentation/js/objects_and_arrays.js +10 -0
  73. data/vendor/coffee-script/documentation/js/overview.js +43 -0
  74. data/vendor/coffee-script/documentation/js/parallel_assignment.js +8 -0
  75. data/vendor/coffee-script/documentation/js/punctuation.js +8 -0
  76. data/vendor/coffee-script/documentation/js/range_comprehensions.js +21 -0
  77. data/vendor/coffee-script/documentation/js/scope.js +10 -0
  78. data/vendor/coffee-script/documentation/js/slices.js +6 -0
  79. data/vendor/coffee-script/documentation/js/soaks.js +4 -0
  80. data/vendor/coffee-script/documentation/js/splats.js +16 -0
  81. data/vendor/coffee-script/documentation/js/splices.js +5 -0
  82. data/vendor/coffee-script/documentation/js/strings.js +9 -0
  83. data/vendor/coffee-script/documentation/js/super.js +37 -0
  84. data/vendor/coffee-script/documentation/js/switch.js +18 -0
  85. data/vendor/coffee-script/documentation/js/try.js +10 -0
  86. data/vendor/coffee-script/documentation/js/while.js +22 -0
  87. data/vendor/coffee-script/documentation/underscore.html +627 -0
  88. data/vendor/coffee-script/examples/beautiful_code/binary_search.coffee +16 -0
  89. data/vendor/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +13 -0
  90. data/vendor/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +34 -0
  91. data/vendor/coffee-script/examples/blocks.coffee +57 -0
  92. data/vendor/coffee-script/examples/code.coffee +173 -0
  93. data/vendor/coffee-script/examples/computer_science/README +4 -0
  94. data/vendor/coffee-script/examples/computer_science/binary_search.coffee +25 -0
  95. data/vendor/coffee-script/examples/computer_science/bubble_sort.coffee +11 -0
  96. data/vendor/coffee-script/examples/computer_science/linked_list.coffee +106 -0
  97. data/vendor/coffee-script/examples/computer_science/luhn_algorithm.coffee +36 -0
  98. data/vendor/coffee-script/examples/computer_science/merge_sort.coffee +19 -0
  99. data/vendor/coffee-script/examples/computer_science/selection_sort.coffee +23 -0
  100. data/vendor/coffee-script/examples/poignant.coffee +186 -0
  101. data/vendor/coffee-script/examples/potion.coffee +205 -0
  102. data/vendor/coffee-script/examples/underscore.coffee +603 -0
  103. data/vendor/coffee-script/examples/web_server.coffee +12 -0
  104. data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Preferences/CoffeeScript.tmPreferences +24 -0
  105. data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +361 -0
  106. data/vendor/coffee-script/extras/CoffeeScript.tmbundle/info.plist +10 -0
  107. data/vendor/coffee-script/extras/EXTRAS +20 -0
  108. data/vendor/coffee-script/extras/coffee.vim +117 -0
  109. data/vendor/coffee-script/index.html +1847 -0
  110. data/vendor/coffee-script/lib/bin/cake +7 -0
  111. data/vendor/coffee-script/lib/bin/coffee +7 -0
  112. data/vendor/coffee-script/lib/cake.js +80 -0
  113. data/vendor/coffee-script/lib/coffee-script.js +61 -0
  114. data/vendor/coffee-script/lib/command_line.js +201 -0
  115. data/vendor/coffee-script/lib/grammar.js +564 -0
  116. data/vendor/coffee-script/lib/lexer.js +405 -0
  117. data/vendor/coffee-script/lib/narwhal.js +44 -0
  118. data/vendor/coffee-script/lib/nodes.js +1328 -0
  119. data/vendor/coffee-script/lib/optparse.js +117 -0
  120. data/vendor/coffee-script/lib/parser.js +536 -0
  121. data/vendor/coffee-script/lib/repl.js +32 -0
  122. data/vendor/coffee-script/lib/rewriter.js +383 -0
  123. data/vendor/coffee-script/lib/scope.js +114 -0
  124. data/vendor/coffee-script/package.json +7 -0
  125. data/vendor/coffee-script/src/cake.coffee +45 -0
  126. data/vendor/coffee-script/src/coffee-script.coffee +45 -0
  127. data/vendor/coffee-script/src/command_line.coffee +130 -0
  128. data/vendor/coffee-script/src/grammar.coffee +456 -0
  129. data/vendor/coffee-script/src/lexer.coffee +327 -0
  130. data/vendor/coffee-script/src/narwhal.coffee +42 -0
  131. data/vendor/coffee-script/src/nodes.coffee +1045 -0
  132. data/vendor/coffee-script/src/optparse.coffee +79 -0
  133. data/vendor/coffee-script/src/repl.coffee +23 -0
  134. data/vendor/coffee-script/src/rewriter.coffee +253 -0
  135. data/vendor/coffee-script/src/scope.coffee +75 -0
  136. data/vendor/coffee-script/test/test_arguments.coffee +34 -0
  137. data/vendor/coffee-script/test/test_array_comprehension.coffee +42 -0
  138. data/vendor/coffee-script/test/test_assignment.coffee +26 -0
  139. data/vendor/coffee-script/test/test_blocks.coffee +4 -0
  140. data/vendor/coffee-script/test/test_calling_super.coffee +42 -0
  141. data/vendor/coffee-script/test/test_chained_calls.coffee +25 -0
  142. data/vendor/coffee-script/test/test_destructuring_assignment.coffee +62 -0
  143. data/vendor/coffee-script/test/test_everything.coffee +29 -0
  144. data/vendor/coffee-script/test/test_exceptions.coffee +2 -0
  145. data/vendor/coffee-script/test/test_existence.coffee +81 -0
  146. data/vendor/coffee-script/test/test_expressions.coffee +30 -0
  147. data/vendor/coffee-script/test/test_fancy_if_statement.coffee +26 -0
  148. data/vendor/coffee-script/test/test_functions.coffee +80 -0
  149. data/vendor/coffee-script/test/test_funky_comments.coffee +25 -0
  150. data/vendor/coffee-script/test/test_heredocs.coffee +46 -0
  151. data/vendor/coffee-script/test/test_lexical_scope.coffee +10 -0
  152. data/vendor/coffee-script/test/test_literals.coffee +56 -0
  153. data/vendor/coffee-script/test/test_nested_comprehensions.coffee +11 -0
  154. data/vendor/coffee-script/test/test_newline_escaping.coffee +6 -0
  155. data/vendor/coffee-script/test/test_operations.coffee +18 -0
  156. data/vendor/coffee-script/test/test_range_comprehension.coffee +20 -0
  157. data/vendor/coffee-script/test/test_ranges_and_slices.coffee +16 -0
  158. data/vendor/coffee-script/test/test_splats.coffee +47 -0
  159. data/vendor/coffee-script/test/test_splices.coffee +5 -0
  160. data/vendor/coffee-script/test/test_switch.coffee +64 -0
  161. data/vendor/coffee-script/test/test_while.coffee +30 -0
  162. data/vendor/coffee-script/vendor/jison/Jakefile +31 -0
  163. data/vendor/coffee-script/vendor/jison/README.md +347 -0
  164. data/vendor/coffee-script/vendor/jison/bin/jison +3 -0
  165. data/vendor/coffee-script/vendor/jison/bin/json2jison +3 -0
  166. data/vendor/coffee-script/vendor/jison/examples/ansic.jison +415 -0
  167. data/vendor/coffee-script/vendor/jison/examples/basic.json +8 -0
  168. data/vendor/coffee-script/vendor/jison/examples/basic2.json +9 -0
  169. data/vendor/coffee-script/vendor/jison/examples/basic2_lex.json +16 -0
  170. data/vendor/coffee-script/vendor/jison/examples/basic_lex.json +15 -0
  171. data/vendor/coffee-script/vendor/jison/examples/calculator.jison +38 -0
  172. data/vendor/coffee-script/vendor/jison/examples/calculator.jisonlex +14 -0
  173. data/vendor/coffee-script/vendor/jison/examples/calculator.json +42 -0
  174. data/vendor/coffee-script/vendor/jison/examples/classy.json +105 -0
  175. data/vendor/coffee-script/vendor/jison/examples/classy_ast.json +126 -0
  176. data/vendor/coffee-script/vendor/jison/examples/dism.json +25 -0
  177. data/vendor/coffee-script/vendor/jison/examples/dism_lr0.json +26 -0
  178. data/vendor/coffee-script/vendor/jison/examples/json.js +80 -0
  179. data/vendor/coffee-script/vendor/jison/examples/json_ast.js +83 -0
  180. data/vendor/coffee-script/vendor/jison/examples/precedence.json +26 -0
  181. data/vendor/coffee-script/vendor/jison/examples/reduce_conflict.json +13 -0
  182. data/vendor/coffee-script/vendor/jison/lib/jison/bnf.js +43 -0
  183. data/vendor/coffee-script/vendor/jison/lib/jison/jisonlex.js +18 -0
  184. data/vendor/coffee-script/vendor/jison/lib/jison/json2jison.js +146 -0
  185. data/vendor/coffee-script/vendor/jison/lib/jison/lexer.js +224 -0
  186. data/vendor/coffee-script/vendor/jison/lib/jison/util/bnf-parser.js +383 -0
  187. data/vendor/coffee-script/vendor/jison/lib/jison/util/lex-parser.js +407 -0
  188. data/vendor/coffee-script/vendor/jison/lib/jison/util/set.js +94 -0
  189. data/vendor/coffee-script/vendor/jison/lib/jison/util/typal.js +90 -0
  190. data/vendor/coffee-script/vendor/jison/lib/jison.js +1414 -0
  191. data/vendor/coffee-script/vendor/jison/package.json +14 -0
  192. data/vendor/coffee-script/vendor/jison/src/bnf.jison +110 -0
  193. data/vendor/coffee-script/vendor/jison/src/bnf.jisonlex +25 -0
  194. data/vendor/coffee-script/vendor/jison/src/bnf.lex.json +24 -0
  195. data/vendor/coffee-script/vendor/jison/src/jisonlex.jison +129 -0
  196. data/vendor/coffee-script/vendor/jison/src/jisonlex.jisonlex +31 -0
  197. data/vendor/coffee-script/vendor/jison/src/jisonlex.lex.json +30 -0
  198. data/vendor/coffee-script/vendor/jison/tests/all-tests.js +8 -0
  199. data/vendor/coffee-script/vendor/jison/tests/grammar/bnf.js +91 -0
  200. data/vendor/coffee-script/vendor/jison/tests/grammar/bnf_parse.js +65 -0
  201. data/vendor/coffee-script/vendor/jison/tests/grammar/grammar-tests.js +10 -0
  202. data/vendor/coffee-script/vendor/jison/tests/grammar/json2jison.js +24 -0
  203. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/ansic.jisonlex +115 -0
  204. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.jisonlex +25 -0
  205. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.lex.json +24 -0
  206. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.jisonlex +31 -0
  207. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.lex.json +30 -0
  208. data/vendor/coffee-script/vendor/jison/tests/grammar/lex.jison +119 -0
  209. data/vendor/coffee-script/vendor/jison/tests/grammar/lex.js +58 -0
  210. data/vendor/coffee-script/vendor/jison/tests/grammar/lex_parse.js +117 -0
  211. data/vendor/coffee-script/vendor/jison/tests/lexer/lexer-tests.js +6 -0
  212. data/vendor/coffee-script/vendor/jison/tests/lexer/regexplexer.js +417 -0
  213. data/vendor/coffee-script/vendor/jison/tests/parser/actions.js +311 -0
  214. data/vendor/coffee-script/vendor/jison/tests/parser/api.js +236 -0
  215. data/vendor/coffee-script/vendor/jison/tests/parser/generator.js +196 -0
  216. data/vendor/coffee-script/vendor/jison/tests/parser/lalr.js +183 -0
  217. data/vendor/coffee-script/vendor/jison/tests/parser/lr0.js +72 -0
  218. data/vendor/coffee-script/vendor/jison/tests/parser/lr1.js +119 -0
  219. data/vendor/coffee-script/vendor/jison/tests/parser/parser-tests.js +14 -0
  220. data/vendor/coffee-script/vendor/jison/tests/parser/precedence.js +237 -0
  221. data/vendor/coffee-script/vendor/jison/tests/parser/slr.js +52 -0
  222. data/vendor/coffee-script/vendor/jison/tests/parser/tables.js +126 -0
  223. data/vendor/coffee-script/vendor/jison/tests/performance.js +110 -0
  224. data/vendor/coffee-script/vendor/jison/tests/setup.js +3 -0
  225. metadata +324 -0
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ Haml::More and Sass::More
2
+ =========================
3
+
4
+ Adds more functionality to Haml and Sass.
5
+
6
+ BigBand
7
+ -------
8
+
9
+ Haml::More and Sass::More are part of the [BigBand](http://github.com/rkh/big_band) stack.
10
+ Check it out if you are looking for fancy Sinatra extensions.
11
+
12
+ Haml extensions
13
+ ---------------
14
+
15
+ * `content_for` and `yield_content` (like in Rails, you know?)
16
+
17
+ // some_file.haml
18
+ = yield_content(:foo)
19
+ .content
20
+ = haml :another_file
21
+
22
+ // another_file.haml
23
+ - content_for(:foo)
24
+ %b bar
25
+ .something
26
+ %h1 cool, huh?
27
+
28
+ * adds `:coffee_script` for inline [CoffeeScript](http://jashkenas.github.com/coffee-script/)
29
+
30
+ %head
31
+ %title CoffeScript example
32
+ :coffee_script
33
+ if happy and knows_it
34
+ claps_hands()
35
+ cha_cha_cha()
36
+ %body
37
+ content
38
+
39
+ SassScript extensions
40
+ ---------------------
41
+
42
+ * `min` and `max`
43
+
44
+ .someClass
45
+ width = max(100px, !someSize * 3)
46
+ height = min(!a, !b, 20%)
47
+
48
+ Usage with Sinatra
49
+ ------------------
50
+
51
+ Classic style:
52
+
53
+ require "sinatra"
54
+ require "haml/more"
55
+
56
+ Modular:
57
+
58
+ require "sinatra/base"
59
+ require "haml/more"
60
+
61
+ class Foo < Sinatra::Base
62
+ helpers Haml::More
63
+ end
64
+
65
+
66
+ Usage without Sinatra
67
+ ---------------------
68
+
69
+ Using just Sass::More (if you're in Merb or Rails):
70
+
71
+ # in some initializer or something
72
+ require "sass/more"
73
+
74
+ Without anything:
75
+
76
+ require "haml/more"
77
+ scope = Object.new
78
+ scope.extend Haml::More
79
+ puts Haml::Engine.new("%p some haml code").render(scope)
@@ -0,0 +1,137 @@
1
+ require "haml/more"
2
+ require "monkey"
3
+
4
+ module Haml::More::CoffeeScript
5
+ include Haml::Filters::Base
6
+
7
+ # Also allow :coffee_script besides :coffeescript
8
+ Haml::Filters.defined["coffee_script"] = self
9
+
10
+ class Compiler
11
+ attr_accessor :coffee_directory, :coffee_url
12
+
13
+ def self.available_compilers
14
+ @available_compilers ||= []
15
+ end
16
+
17
+ def self.inherited(klass)
18
+ Compiler.available_compilers << klass
19
+ end
20
+
21
+ def self.new(*args)
22
+ return super unless self == Compiler
23
+ available_compilers.each do |klass|
24
+ klass.new(*args).tap { |c| return c if c.available? }
25
+ end
26
+ raise RuntimeError, "no compiler available (should not happen!)"
27
+ end
28
+
29
+ def initialize(*args)
30
+ @available = true
31
+ @coffee_directory = File.expand_path "../../../../vendor/coffee-script", __FILE__
32
+ @coffee_url = "http://jashkenas.github.com/coffee-script"
33
+ end
34
+
35
+ def dependencies(prefix = nil)
36
+ @dependencies ||= %w[rewriter lexer parser scope nodes coffee-script].map { |l| "lib/#{l}.js" }
37
+ prefix ? @dependencies.map { |file| prefix / file } : @dependencies
38
+ end
39
+
40
+ def files
41
+ dependencies coffee_directory
42
+ end
43
+
44
+ def urls
45
+ dependencies coffee_url
46
+ end
47
+
48
+ def javascript(text)
49
+ Haml::Filters::Javascript.render_with_options text, :attr_wrapper => "'"
50
+ end
51
+
52
+ def compile_statement(text)
53
+ "CoffeeScript.compile(#{text.inspect}, {no_wrap: true})"
54
+ end
55
+
56
+ def available?
57
+ !!@available
58
+ end
59
+
60
+ def not_available!
61
+ @available = false
62
+ end
63
+ end
64
+
65
+ class JohnsonCompiler < Compiler
66
+ attr_accessor :runtime
67
+ def initialize(runtime = nil)
68
+ super
69
+ require "johnson"
70
+ @runtime = runtime || Johnson::Runtime.new
71
+ prepare_runtime
72
+ rescue LoadError, Johnson::Error
73
+ not_available!
74
+ end
75
+
76
+ def available?
77
+ # CoffeeScript currently not working properly on Spidermonkey
78
+ false
79
+ end
80
+
81
+ def prepare_runtime
82
+ runtime.load(*files)
83
+ end
84
+
85
+ def render(text)
86
+ runtime.evaluate compile_statement(text)
87
+ end
88
+ end
89
+
90
+ class NodeCompiler < Compiler
91
+ attr_accessor :command
92
+ def initialize(command = nil)
93
+ super
94
+ @command = `which #{command || "node"}`.strip
95
+ not_available! if @command.empty?
96
+ end
97
+
98
+ def render(text)
99
+ sanitized = text.inspect.gsub("\\n", "\n").gsub("\\r", "\r")
100
+ javascript `#{command} #{coffee_directory}/bin/coffee -p -e #{sanitized}`
101
+ end
102
+ end
103
+
104
+ class ClientCompiler < Compiler
105
+ def initialize
106
+ @script_tag = "<script type=\"text/javascript\" src=%s></script>\n"
107
+ super
108
+ end
109
+
110
+ attr_accessor :skip_scripts, :script_tag
111
+ def skip_scripts?
112
+ !!@skip_scripts
113
+ end
114
+
115
+ def render(text)
116
+ result = ""
117
+ urls.each { |u| result << (script_tag % u.inspect) } unless skip_scripts?
118
+ result << javascript("eval(#{compile_statement(text)})")
119
+ end
120
+ end
121
+
122
+ class << self
123
+ attr_writer :compiler
124
+ def compiler
125
+ @compiler ||= Compiler.new
126
+ end
127
+
128
+ def activate
129
+ compiler
130
+ true
131
+ end
132
+ end
133
+
134
+ def render(text)
135
+ Haml::More::CoffeeScript.compiler.render text
136
+ end
137
+ end
@@ -0,0 +1,25 @@
1
+ require "haml/more"
2
+
3
+ module Haml::More::ContentFor
4
+ include Haml::More::AbstractHelper
5
+
6
+ def content_for(name, &block)
7
+ name = name.to_s
8
+ @content_for ||= Hash.new {|h,k| h[k] = [] }
9
+ @content_for[name] << block if block
10
+ @content_for[name]
11
+ end
12
+
13
+ def yield_content(name, *args)
14
+ haml_helper do
15
+ content_for(name).each do |block|
16
+ result = block.call(*args)
17
+ haml_concat result unless block_is_haml? block
18
+ end
19
+ end
20
+ end
21
+
22
+ def get_content(name, *args)
23
+ non_haml { yield_content(name, *args) }
24
+ end
25
+ end
data/lib/haml/more.rb ADDED
@@ -0,0 +1,45 @@
1
+ require "haml"
2
+ require "sass/more"
3
+ require "monkey"
4
+
5
+ module Haml
6
+ module More
7
+
8
+ # skip autoload lines
9
+ extend Monkey::Autoloader
10
+
11
+ # Base class for all all Haml helper
12
+ module AbstractHelper
13
+ module ClassMethods
14
+ def registered(klass)
15
+ klass.helpers self
16
+ end
17
+ end
18
+
19
+ def self.included(klass)
20
+ klass.extend ClassMethods
21
+ super
22
+ end
23
+
24
+ include Haml::Helpers
25
+
26
+ # Will make use of capture_haml depending on whether it is called from
27
+ # within Haml code or not. Thus helpers may be shared between Haml and
28
+ # others (like ERB), but still enjoy all the fancy Haml::Helpers tools.
29
+ def haml_helper(&block)
30
+ return capture_haml(&block) unless is_haml?
31
+ yield
32
+ end
33
+
34
+ end
35
+
36
+ def self.included(klass)
37
+ Haml::More::CoffeeScript.activate
38
+ klass.send :include, Haml::More::ContentFor
39
+ super
40
+ end
41
+
42
+ ::Sinatra.helpers self if defined? ::Sinatra
43
+
44
+ end
45
+ end
data/lib/haml-more.rb ADDED
@@ -0,0 +1 @@
1
+ require "haml/more"
data/lib/sass/more.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "sass"
2
+
3
+ module Sass
4
+ module More
5
+ ::Sass::Script::Functions.send :include, self
6
+
7
+ def min(*args)
8
+ args.min { |a, b| a.value <=> b.value }
9
+ end
10
+
11
+ def max(*args)
12
+ args.max { |a, b| a.value <=> b.value }
13
+ end
14
+
15
+ end
16
+ end
data/lib/sass-more.rb ADDED
@@ -0,0 +1 @@
1
+ require "sass/more"
@@ -0,0 +1,21 @@
1
+ require "sass/more"
2
+
3
+ describe Sass::More do
4
+
5
+ def evaluate_sass(value)
6
+ Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
7
+ end
8
+
9
+ it "returns the smaller value for min" do
10
+ evaluate_sass("min(10px, 20px)").should == evaluate_sass("10px")
11
+ evaluate_sass("min(50%, 10%)").should == evaluate_sass("10%")
12
+ evaluate_sass("min(42, 42)").should == evaluate_sass("42")
13
+ end
14
+
15
+ it "returns the greater value for max" do
16
+ evaluate_sass("max(10px, 20px)").should == evaluate_sass("20px")
17
+ evaluate_sass("max(50%, 10%)").should == evaluate_sass("50%")
18
+ evaluate_sass("max(42, 42)").should == evaluate_sass("42")
19
+ end
20
+
21
+ end
@@ -0,0 +1,57 @@
1
+ fs: require 'fs'
2
+ coffee: require 'coffee-script'
3
+
4
+ # Run a CoffeeScript through our node/coffee interpreter.
5
+ run: (args) ->
6
+ proc: process.createChildProcess 'bin/coffee', args
7
+ proc.addListener 'error', (err) -> if err then puts err
8
+
9
+
10
+ task 'install', 'install CoffeeScript into /usr/local', ->
11
+ exec([
12
+ 'mkdir -p /usr/local/lib/coffee-script'
13
+ 'cp -rf bin lib LICENSE README package.json src vendor /usr/local/lib/coffee-script'
14
+ 'ln -sf /usr/local/lib/coffee-script/lib/bin/coffee /usr/local/bin/coffee'
15
+ 'ln -sf /usr/local/lib/coffee-script/lib/bin/cake /usr/local/bin/cake'
16
+ ].join(' && '))
17
+
18
+
19
+ task 'build', 'build the CoffeeScript language from source', ->
20
+ fs.readdir 'src', (err, files) ->
21
+ files: 'src/' + file for file in files when file.match(/\.coffee$/)
22
+ run ['-o', 'lib'].concat(files)
23
+
24
+
25
+ task 'build:parser', 'rebuild the Jison parser (run build first)', ->
26
+ parser: require('grammar').parser
27
+ js: parser.generate()
28
+ parser_path: 'lib/parser.js'
29
+ fs.writeFile parser_path, js
30
+
31
+
32
+ task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter', ->
33
+ exec 'plist2syntax extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage', (err) ->
34
+ exec 'sudo mv coffeescript.yaml /usr/local/lib/ruby/gems/1.8/gems/ultraviolet-0.10.2/syntax/coffeescript.syntax'
35
+
36
+
37
+ task 'build:underscore', 'rebuild the Underscore.coffee documentation page', ->
38
+ exec 'uv -s coffeescript -t idle -h examples/underscore.coffee > documentation/underscore.html'
39
+
40
+
41
+ task 'test', 'run the CoffeeScript language test suite', ->
42
+ process.mixin require 'assert'
43
+ test_count: 0
44
+ start_time: new Date()
45
+ [original_ok, original_throws]: [ok, throws]
46
+ process.mixin {
47
+ ok: (args...) -> test_count += 1; original_ok(args...)
48
+ throws: (args...) -> test_count += 1; original_throws(args...)
49
+ }
50
+ process.addListener 'exit', ->
51
+ time: ((new Date() - start_time) / 1000).toFixed(2)
52
+ puts '\033[0;32mpassed ' + test_count + ' tests in ' + time + ' seconds\033[0m'
53
+ fs.readdir 'test', (err, files) ->
54
+ for file in files
55
+ fs.readFile 'test/' + file, (err, source) ->
56
+ js: coffee.compile source
57
+ process.compile js, file
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2010 Jeremy Ashkenas
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ =
2
+ {
3
+ } } {
4
+ { { } }
5
+ } }{ {
6
+ { }{ } } _____ __ __
7
+ ( }{ }{ { ) / ____| / _|/ _|
8
+ .- { { } { }} -. | | ___ | |_| |_ ___ ___
9
+ ( ( } { } { } } ) | | / _ \| _| _/ _ \/ _ \
10
+ |`-..________ ..-'| | |___| (_) | | | || __/ __/
11
+ | | \_____\___/|_| |_| \___|\___|
12
+ | ;--.
13
+ | (__ \ _____ _ _
14
+ | | ) ) / ____| (_) | |
15
+ | |/ / | (___ ___ _ __ _ _ __ | |_
16
+ | ( / \___ \ / __| '__| | '_ \| __|
17
+ | |/ ____) | (__| | | | |_) | |_
18
+ | | |_____/ \___|_| |_| .__/ \__|
19
+ `-.._________..-' | |
20
+ |_|
21
+
22
+
23
+ CoffeeScript is a little language that compiles into JavaScript.
24
+
25
+ Install Node.js, and then the CoffeeScript compiler:
26
+ sudo bin/cake install
27
+
28
+ Compile a script:
29
+ coffee /path/to/script.coffee
30
+
31
+ For documentation, usage, and examples, see:
32
+ http://coffeescript.org/
33
+
34
+ To suggest a feature, report a bug, or general discussion:
35
+ http://github.com/jashkenas/coffee-script/issues/
36
+
37
+ If you'd like to chat, drop by #coffeescript on Freenode.
38
+
39
+ The source repository:
40
+ git://github.com/jashkenas/coffee-script.git
41
+
@@ -0,0 +1,20 @@
1
+ require 'erb'
2
+ require 'fileutils'
3
+ require 'rake/testtask'
4
+
5
+ desc "Build the documentation page"
6
+ task :doc do
7
+ source = 'documentation/index.html.erb'
8
+ child = fork { exec "bin/coffee documentation/coffee/*.coffee -o documentation/js -w" }
9
+ at_exit { Process.kill("INT", child) }
10
+ Signal.trap("INT") { exit }
11
+ loop do
12
+ mtime = File.stat(source).mtime
13
+ if !@mtime || mtime > @mtime
14
+ rendered = ERB.new(File.read(source)).result(binding)
15
+ File.open('index.html', 'w+') {|f| f.write(rendered) }
16
+ end
17
+ @mtime = mtime
18
+ sleep 1
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+
3
+ process.mixin(require('sys'));
4
+
5
+ require.paths.unshift(__dirname + '/../lib');
6
+
7
+ require('cake').run();
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+
3
+ process.mixin(require('sys'));
4
+
5
+ require.paths.unshift(__dirname + '/../lib');
6
+
7
+ require('command_line').run();
@@ -0,0 +1,9 @@
1
+ launch() if ignition is on
2
+
3
+ volume: 10 if band isnt spinal_tap
4
+
5
+ let_the_wild_rumpus_begin() unless answer is no
6
+
7
+ if car.speed < speed_limit then accelerate()
8
+
9
+ print "My name is " + @name
@@ -0,0 +1,4 @@
1
+ backwards: ->
2
+ alert arguments.reverse()
3
+
4
+ backwards "stairway", "to", "heaven"
@@ -0,0 +1,7 @@
1
+ # Eat lunch.
2
+ lunch: eat(food) for food in ['toast', 'cheese', 'wine']
3
+
4
+ # Naive collision detection.
5
+ for roid in asteroids
6
+ for roid2 in asteroids when roid isnt roid2
7
+ roid.explode() if roid.overlaps roid2
@@ -0,0 +1,2 @@
1
+ greeting: "Hello CoffeeScript"
2
+ difficulty: 0.5
@@ -0,0 +1,5 @@
1
+ process.mixin require 'assert'
2
+
3
+ task 'test', 'run each of the unit tests', ->
4
+ for test in test_files
5
+ fs.readFile test, (err, code) -> eval coffee.compile code
@@ -0,0 +1,5 @@
1
+ cholesterol: 127
2
+
3
+ healthy: 200 > cholesterol > 60
4
+
5
+
@@ -0,0 +1,9 @@
1
+ mood: greatly_improved if singing
2
+
3
+ if happy and knows_it
4
+ claps_hands()
5
+ cha_cha_cha()
6
+
7
+ date: if friday then sue else jill
8
+
9
+ expensive ||= do_the_math()
@@ -0,0 +1,5 @@
1
+ hi: `function() {
2
+ return [document.title, "Hello JavaScript"].join(": ");
3
+ }`
4
+
5
+
@@ -0,0 +1,8 @@
1
+ solipsism: true if mind? and not world?
2
+
3
+ speed ?= 140
4
+
5
+
6
+
7
+
8
+
@@ -0,0 +1,9 @@
1
+ grade: (student) ->
2
+ if student.excellent_work
3
+ "A+"
4
+ else if student.okay_stuff
5
+ if student.tried_hard then "B" else "B-"
6
+ else
7
+ "C"
8
+
9
+ eldest: if 24 > 21 then "Liz" else "Ike"
@@ -0,0 +1 @@
1
+ six: (one: 1) + (two: 2) + (three: 3)
@@ -0,0 +1,3 @@
1
+ # The first ten global properties.
2
+
3
+ globals: (name for name of window)[0...10]
@@ -0,0 +1,6 @@
1
+ alert(
2
+ try
3
+ nonexistent / undefined
4
+ catch error
5
+ "And the error is ... " + error
6
+ )
@@ -0,0 +1,6 @@
1
+ Account: (customer, cart) ->
2
+ @customer: customer
3
+ @cart: cart
4
+
5
+ $('.shopping_cart').bind 'click', (event) =>
6
+ @customer.purchase @cart
@@ -0,0 +1,2 @@
1
+ square: (x) -> x * x
2
+ cube: (x) -> square(x) * x
@@ -0,0 +1,5 @@
1
+ html: '''
2
+ <strong>
3
+ cup of coffeescript
4
+ </strong>
5
+ '''
@@ -0,0 +1,5 @@
1
+ weather_report: (location) ->
2
+ # Make an Ajax request to fetch the weather...
3
+ [location, 72, "Mostly Sunny"]
4
+
5
+ [city, temp, forecast]: weather_report "Berkeley, CA"
@@ -0,0 +1,4 @@
1
+ years_old: {max: 10, ida: 9, tim: 11}
2
+
3
+ ages: for child, age of years_old
4
+ child + " is " + age
@@ -0,0 +1,13 @@
1
+ futurists: {
2
+ sculptor: "Umberto Boccioni"
3
+ painter: "Vladimir Burliuk"
4
+ poet: {
5
+ name: "F.T. Marinetti"
6
+ address: [
7
+ "Via Roma 42R"
8
+ "Bellagio, Italy 22021"
9
+ ]
10
+ }
11
+ }
12
+
13
+ {poet: {name: poet, address: [street, city]}}: futurists
@@ -0,0 +1,13 @@
1
+ song: ["do", "re", "mi", "fa", "so"]
2
+
3
+ ages: {
4
+ max: 10
5
+ ida: 9
6
+ tim: 11
7
+ }
8
+
9
+ matrix: [
10
+ 1, 0, 1
11
+ 0, 0, 1
12
+ 1, 1, 0
13
+ ]