haml-more 0.4.0.a
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +79 -0
- data/lib/haml/more/coffee_script.rb +137 -0
- data/lib/haml/more/content_for.rb +25 -0
- data/lib/haml/more.rb +45 -0
- data/lib/haml-more.rb +1 -0
- data/lib/sass/more.rb +16 -0
- data/lib/sass-more.rb +1 -0
- data/spec/sass/more_spec.rb +21 -0
- data/vendor/coffee-script/Cakefile +57 -0
- data/vendor/coffee-script/LICENSE +22 -0
- data/vendor/coffee-script/README +41 -0
- data/vendor/coffee-script/Rakefile +20 -0
- data/vendor/coffee-script/bin/cake +7 -0
- data/vendor/coffee-script/bin/coffee +7 -0
- data/vendor/coffee-script/documentation/coffee/aliases.coffee +9 -0
- data/vendor/coffee-script/documentation/coffee/arguments.coffee +4 -0
- data/vendor/coffee-script/documentation/coffee/array_comprehensions.coffee +7 -0
- data/vendor/coffee-script/documentation/coffee/assignment.coffee +2 -0
- data/vendor/coffee-script/documentation/coffee/cake_tasks.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/comparisons.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/conditionals.coffee +9 -0
- data/vendor/coffee-script/documentation/coffee/embedded.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/existence.coffee +8 -0
- data/vendor/coffee-script/documentation/coffee/expressions.coffee +9 -0
- data/vendor/coffee-script/documentation/coffee/expressions_assignment.coffee +1 -0
- data/vendor/coffee-script/documentation/coffee/expressions_comprehension.coffee +3 -0
- data/vendor/coffee-script/documentation/coffee/expressions_try.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/fat_arrow.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/functions.coffee +2 -0
- data/vendor/coffee-script/documentation/coffee/heredocs.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/multiple_return_values.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/object_comprehensions.coffee +4 -0
- data/vendor/coffee-script/documentation/coffee/object_extraction.coffee +13 -0
- data/vendor/coffee-script/documentation/coffee/objects_and_arrays.coffee +13 -0
- data/vendor/coffee-script/documentation/coffee/overview.coffee +29 -0
- data/vendor/coffee-script/documentation/coffee/parallel_assignment.coffee +4 -0
- data/vendor/coffee-script/documentation/coffee/range_comprehensions.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/scope.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/slices.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/soaks.coffee +1 -0
- data/vendor/coffee-script/documentation/coffee/splats.coffee +25 -0
- data/vendor/coffee-script/documentation/coffee/splices.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/strings.coffee +8 -0
- data/vendor/coffee-script/documentation/coffee/super.coffee +34 -0
- data/vendor/coffee-script/documentation/coffee/switch.coffee +10 -0
- data/vendor/coffee-script/documentation/coffee/try.coffee +7 -0
- data/vendor/coffee-script/documentation/coffee/while.coffee +10 -0
- data/vendor/coffee-script/documentation/css/docs.css +213 -0
- data/vendor/coffee-script/documentation/css/idle.css +63 -0
- data/vendor/coffee-script/documentation/css/logo.png +0 -0
- data/vendor/coffee-script/documentation/index.html.erb +967 -0
- data/vendor/coffee-script/documentation/js/aliases.js +14 -0
- data/vendor/coffee-script/documentation/js/arguments.js +8 -0
- data/vendor/coffee-script/documentation/js/array_comprehensions.js +26 -0
- data/vendor/coffee-script/documentation/js/assignment.js +5 -0
- data/vendor/coffee-script/documentation/js/cake_tasks.js +14 -0
- data/vendor/coffee-script/documentation/js/comparisons.js +5 -0
- data/vendor/coffee-script/documentation/js/conditionals.js +12 -0
- data/vendor/coffee-script/documentation/js/embedded.js +6 -0
- data/vendor/coffee-script/documentation/js/existence.js +7 -0
- data/vendor/coffee-script/documentation/js/expressions.js +13 -0
- data/vendor/coffee-script/documentation/js/expressions_assignment.js +4 -0
- data/vendor/coffee-script/documentation/js/expressions_comprehension.js +12 -0
- data/vendor/coffee-script/documentation/js/expressions_try.js +9 -0
- data/vendor/coffee-script/documentation/js/fat_arrow.js +15 -0
- data/vendor/coffee-script/documentation/js/functions.js +9 -0
- data/vendor/coffee-script/documentation/js/heredocs.js +4 -0
- data/vendor/coffee-script/documentation/js/intro.js +7 -0
- data/vendor/coffee-script/documentation/js/multiple_return_values.js +11 -0
- data/vendor/coffee-script/documentation/js/object_comprehensions.js +17 -0
- data/vendor/coffee-script/documentation/js/object_extraction.js +17 -0
- data/vendor/coffee-script/documentation/js/objects_and_arrays.js +10 -0
- data/vendor/coffee-script/documentation/js/overview.js +43 -0
- data/vendor/coffee-script/documentation/js/parallel_assignment.js +8 -0
- data/vendor/coffee-script/documentation/js/punctuation.js +8 -0
- data/vendor/coffee-script/documentation/js/range_comprehensions.js +21 -0
- data/vendor/coffee-script/documentation/js/scope.js +10 -0
- data/vendor/coffee-script/documentation/js/slices.js +6 -0
- data/vendor/coffee-script/documentation/js/soaks.js +4 -0
- data/vendor/coffee-script/documentation/js/splats.js +16 -0
- data/vendor/coffee-script/documentation/js/splices.js +5 -0
- data/vendor/coffee-script/documentation/js/strings.js +9 -0
- data/vendor/coffee-script/documentation/js/super.js +37 -0
- data/vendor/coffee-script/documentation/js/switch.js +18 -0
- data/vendor/coffee-script/documentation/js/try.js +10 -0
- data/vendor/coffee-script/documentation/js/while.js +22 -0
- data/vendor/coffee-script/documentation/underscore.html +627 -0
- data/vendor/coffee-script/examples/beautiful_code/binary_search.coffee +16 -0
- data/vendor/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +13 -0
- data/vendor/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +34 -0
- data/vendor/coffee-script/examples/blocks.coffee +57 -0
- data/vendor/coffee-script/examples/code.coffee +173 -0
- data/vendor/coffee-script/examples/computer_science/README +4 -0
- data/vendor/coffee-script/examples/computer_science/binary_search.coffee +25 -0
- data/vendor/coffee-script/examples/computer_science/bubble_sort.coffee +11 -0
- data/vendor/coffee-script/examples/computer_science/linked_list.coffee +106 -0
- data/vendor/coffee-script/examples/computer_science/luhn_algorithm.coffee +36 -0
- data/vendor/coffee-script/examples/computer_science/merge_sort.coffee +19 -0
- data/vendor/coffee-script/examples/computer_science/selection_sort.coffee +23 -0
- data/vendor/coffee-script/examples/poignant.coffee +186 -0
- data/vendor/coffee-script/examples/potion.coffee +205 -0
- data/vendor/coffee-script/examples/underscore.coffee +603 -0
- data/vendor/coffee-script/examples/web_server.coffee +12 -0
- data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Preferences/CoffeeScript.tmPreferences +24 -0
- data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +361 -0
- data/vendor/coffee-script/extras/CoffeeScript.tmbundle/info.plist +10 -0
- data/vendor/coffee-script/extras/EXTRAS +20 -0
- data/vendor/coffee-script/extras/coffee.vim +117 -0
- data/vendor/coffee-script/index.html +1847 -0
- data/vendor/coffee-script/lib/bin/cake +7 -0
- data/vendor/coffee-script/lib/bin/coffee +7 -0
- data/vendor/coffee-script/lib/cake.js +80 -0
- data/vendor/coffee-script/lib/coffee-script.js +61 -0
- data/vendor/coffee-script/lib/command_line.js +201 -0
- data/vendor/coffee-script/lib/grammar.js +564 -0
- data/vendor/coffee-script/lib/lexer.js +405 -0
- data/vendor/coffee-script/lib/narwhal.js +44 -0
- data/vendor/coffee-script/lib/nodes.js +1328 -0
- data/vendor/coffee-script/lib/optparse.js +117 -0
- data/vendor/coffee-script/lib/parser.js +536 -0
- data/vendor/coffee-script/lib/repl.js +32 -0
- data/vendor/coffee-script/lib/rewriter.js +383 -0
- data/vendor/coffee-script/lib/scope.js +114 -0
- data/vendor/coffee-script/package.json +7 -0
- data/vendor/coffee-script/src/cake.coffee +45 -0
- data/vendor/coffee-script/src/coffee-script.coffee +45 -0
- data/vendor/coffee-script/src/command_line.coffee +130 -0
- data/vendor/coffee-script/src/grammar.coffee +456 -0
- data/vendor/coffee-script/src/lexer.coffee +327 -0
- data/vendor/coffee-script/src/narwhal.coffee +42 -0
- data/vendor/coffee-script/src/nodes.coffee +1045 -0
- data/vendor/coffee-script/src/optparse.coffee +79 -0
- data/vendor/coffee-script/src/repl.coffee +23 -0
- data/vendor/coffee-script/src/rewriter.coffee +253 -0
- data/vendor/coffee-script/src/scope.coffee +75 -0
- data/vendor/coffee-script/test/test_arguments.coffee +34 -0
- data/vendor/coffee-script/test/test_array_comprehension.coffee +42 -0
- data/vendor/coffee-script/test/test_assignment.coffee +26 -0
- data/vendor/coffee-script/test/test_blocks.coffee +4 -0
- data/vendor/coffee-script/test/test_calling_super.coffee +42 -0
- data/vendor/coffee-script/test/test_chained_calls.coffee +25 -0
- data/vendor/coffee-script/test/test_destructuring_assignment.coffee +62 -0
- data/vendor/coffee-script/test/test_everything.coffee +29 -0
- data/vendor/coffee-script/test/test_exceptions.coffee +2 -0
- data/vendor/coffee-script/test/test_existence.coffee +81 -0
- data/vendor/coffee-script/test/test_expressions.coffee +30 -0
- data/vendor/coffee-script/test/test_fancy_if_statement.coffee +26 -0
- data/vendor/coffee-script/test/test_functions.coffee +80 -0
- data/vendor/coffee-script/test/test_funky_comments.coffee +25 -0
- data/vendor/coffee-script/test/test_heredocs.coffee +46 -0
- data/vendor/coffee-script/test/test_lexical_scope.coffee +10 -0
- data/vendor/coffee-script/test/test_literals.coffee +56 -0
- data/vendor/coffee-script/test/test_nested_comprehensions.coffee +11 -0
- data/vendor/coffee-script/test/test_newline_escaping.coffee +6 -0
- data/vendor/coffee-script/test/test_operations.coffee +18 -0
- data/vendor/coffee-script/test/test_range_comprehension.coffee +20 -0
- data/vendor/coffee-script/test/test_ranges_and_slices.coffee +16 -0
- data/vendor/coffee-script/test/test_splats.coffee +47 -0
- data/vendor/coffee-script/test/test_splices.coffee +5 -0
- data/vendor/coffee-script/test/test_switch.coffee +64 -0
- data/vendor/coffee-script/test/test_while.coffee +30 -0
- data/vendor/coffee-script/vendor/jison/Jakefile +31 -0
- data/vendor/coffee-script/vendor/jison/README.md +347 -0
- data/vendor/coffee-script/vendor/jison/bin/jison +3 -0
- data/vendor/coffee-script/vendor/jison/bin/json2jison +3 -0
- data/vendor/coffee-script/vendor/jison/examples/ansic.jison +415 -0
- data/vendor/coffee-script/vendor/jison/examples/basic.json +8 -0
- data/vendor/coffee-script/vendor/jison/examples/basic2.json +9 -0
- data/vendor/coffee-script/vendor/jison/examples/basic2_lex.json +16 -0
- data/vendor/coffee-script/vendor/jison/examples/basic_lex.json +15 -0
- data/vendor/coffee-script/vendor/jison/examples/calculator.jison +38 -0
- data/vendor/coffee-script/vendor/jison/examples/calculator.jisonlex +14 -0
- data/vendor/coffee-script/vendor/jison/examples/calculator.json +42 -0
- data/vendor/coffee-script/vendor/jison/examples/classy.json +105 -0
- data/vendor/coffee-script/vendor/jison/examples/classy_ast.json +126 -0
- data/vendor/coffee-script/vendor/jison/examples/dism.json +25 -0
- data/vendor/coffee-script/vendor/jison/examples/dism_lr0.json +26 -0
- data/vendor/coffee-script/vendor/jison/examples/json.js +80 -0
- data/vendor/coffee-script/vendor/jison/examples/json_ast.js +83 -0
- data/vendor/coffee-script/vendor/jison/examples/precedence.json +26 -0
- data/vendor/coffee-script/vendor/jison/examples/reduce_conflict.json +13 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/bnf.js +43 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/jisonlex.js +18 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/json2jison.js +146 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/lexer.js +224 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/bnf-parser.js +383 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/lex-parser.js +407 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/set.js +94 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/typal.js +90 -0
- data/vendor/coffee-script/vendor/jison/lib/jison.js +1414 -0
- data/vendor/coffee-script/vendor/jison/package.json +14 -0
- data/vendor/coffee-script/vendor/jison/src/bnf.jison +110 -0
- data/vendor/coffee-script/vendor/jison/src/bnf.jisonlex +25 -0
- data/vendor/coffee-script/vendor/jison/src/bnf.lex.json +24 -0
- data/vendor/coffee-script/vendor/jison/src/jisonlex.jison +129 -0
- data/vendor/coffee-script/vendor/jison/src/jisonlex.jisonlex +31 -0
- data/vendor/coffee-script/vendor/jison/src/jisonlex.lex.json +30 -0
- data/vendor/coffee-script/vendor/jison/tests/all-tests.js +8 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/bnf.js +91 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/bnf_parse.js +65 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/grammar-tests.js +10 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/json2jison.js +24 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/ansic.jisonlex +115 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.jisonlex +25 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.lex.json +24 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.jisonlex +31 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.lex.json +30 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex.jison +119 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex.js +58 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex_parse.js +117 -0
- data/vendor/coffee-script/vendor/jison/tests/lexer/lexer-tests.js +6 -0
- data/vendor/coffee-script/vendor/jison/tests/lexer/regexplexer.js +417 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/actions.js +311 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/api.js +236 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/generator.js +196 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/lalr.js +183 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/lr0.js +72 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/lr1.js +119 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/parser-tests.js +14 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/precedence.js +237 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/slr.js +52 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/tables.js +126 -0
- data/vendor/coffee-script/vendor/jison/tests/performance.js +110 -0
- data/vendor/coffee-script/vendor/jison/tests/setup.js +3 -0
- 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
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 @@
|
|
1
|
+
six: (one: 1) + (two: 2) + (three: 3)
|