opal 0.3.41 → 0.3.42
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +14 -1
- data/Gemfile +2 -5
- data/Rakefile +41 -3
- data/bin/opal +33 -0
- data/lib/opal.rb +2 -12
- data/lib/opal/core_ext.rb +5 -0
- data/lib/opal/grammar.rb +2207 -2138
- data/lib/opal/grammar.y +21 -0
- data/lib/opal/grammar_helpers.rb +360 -0
- data/lib/opal/lexer.rb +55 -401
- data/lib/opal/lexer_scope.rb +28 -0
- data/lib/opal/parser.rb +155 -171
- data/lib/opal/target_scope.rb +257 -0
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +6 -2
- data/opal/opal-parser.js.erb +3 -2
- data/opal/opal.rb +20 -18
- data/opal/opal/array.rb +21 -12
- data/opal/opal/basic_object.rb +2 -1
- data/opal/opal/boolean.rb +3 -0
- data/opal/opal/browser_loader.js +57 -0
- data/opal/opal/class.rb +51 -13
- data/opal/opal/date.rb +1 -20
- data/opal/opal/enumerable.rb +66 -33
- data/opal/opal/error.rb +2 -0
- data/opal/opal/hash.rb +1 -1
- data/opal/opal/kernel.rb +14 -3
- data/opal/opal/nil_class.rb +4 -0
- data/opal/opal/proc.rb +9 -1
- data/opal/opal/racc.rb +2 -2
- data/opal/opal/regexp.rb +1 -1
- data/opal/opal/runtime.js +14 -4
- data/opal/opal/string.rb +21 -4
- data/opal/opal/time.rb +27 -0
- data/spec/core/array/allocate_spec.rb +7 -1
- data/spec/core/array/append_spec.rb +18 -3
- data/spec/core/array/array_spec.rb +7 -0
- data/spec/core/array/assoc_spec.rb +23 -8
- data/spec/core/array/at_spec.rb +23 -3
- data/spec/core/array/choice_spec.rb +20 -0
- data/spec/core/array/clear_spec.rb +45 -4
- data/spec/core/array/combination_spec.rb +55 -0
- data/spec/core/array/compact_spec.rb +72 -1
- data/spec/core/array/constructor_spec.rb +13 -2
- data/spec/core/array/count_spec.rb +15 -7
- data/spec/core/array/delete_at_spec.rb +44 -1
- data/spec/core/array/delete_if_spec.rb +52 -2
- data/spec/core/array/delete_spec.rb +83 -2
- data/spec/core/array/drop_spec.rb +24 -16
- data/spec/core/array/drop_while_spec.rb +17 -0
- data/spec/core/array/each_index_spec.rb +11 -1
- data/spec/core/array/each_spec.rb +20 -2
- data/spec/core/array/empty_spec.rb +4 -1
- data/spec/core/array/eql_spec.rb +14 -0
- data/spec/core/array/fetch_spec.rb +31 -2
- data/spec/core/array/find_index_spec.rb +8 -0
- data/spec/core/array/first_spec.rb +45 -8
- data/spec/core/array/fixtures/classes.rb +538 -0
- data/spec/core/array/flatten_spec.rb +200 -7
- data/spec/core/array/frozen_spec.rb +32 -0
- data/spec/core/array/include_spec.rb +16 -1
- data/spec/core/array/index_spec.rb +5 -25
- data/spec/core/array/insert_spec.rb +37 -3
- data/spec/core/array/inspect_spec.rb +6 -12
- data/spec/core/array/intersection_spec.rb +55 -4
- data/spec/core/array/join_spec.rb +29 -4
- data/spec/core/array/keep_if_spec.rb +13 -6
- data/spec/core/array/last_spec.rb +35 -1
- data/spec/core/array/length_spec.rb +7 -4
- data/spec/core/array/map_spec.rb +9 -47
- data/spec/core/array/minus_spec.rb +68 -4
- data/spec/core/array/multiply_spec.rb +138 -6
- data/spec/core/array/new_spec.rb +92 -3
- data/spec/core/array/ntimes_spec.rb +26 -0
- data/spec/core/array/plus_spec.rb +48 -2
- data/spec/core/array/pop_spec.rb +159 -39
- data/spec/core/array/push_spec.rb +29 -1
- data/spec/core/array/rassoc_spec.rb +31 -2
- data/spec/core/array/reject_spec.rb +89 -2
- data/spec/core/array/replace_spec.rb +7 -29
- data/spec/core/array/reverse_each_spec.rb +25 -1
- data/spec/core/array/reverse_spec.rb +53 -1
- data/spec/core/array/rindex_spec.rb +55 -5
- data/spec/core/array/select_spec.rb +35 -8
- data/spec/core/array/shared/collect.rb +0 -0
- data/spec/core/array/shared/enumeratorize.rb +12 -0
- data/spec/core/array/shared/eql.rb +95 -0
- data/spec/core/array/shared/index.rb +37 -0
- data/spec/core/array/shared/inspect.rb +3 -0
- data/spec/core/array/shared/join.rb +7 -0
- data/spec/core/array/shared/keep_if.rb +0 -0
- data/spec/core/array/shared/length.rb +0 -0
- data/spec/core/array/shared/replace.rb +0 -0
- data/spec/core/array/shared/slice.rb +0 -0
- data/spec/core/array/shift_spec.rb +132 -23
- data/spec/core/array/shuffle_spec.rb +82 -6
- data/spec/core/array/size_spec.rb +7 -4
- data/spec/core/array/slice_spec.rb +132 -1
- data/spec/core/array/sort_spec.rb +263 -14
- data/spec/core/array/take_spec.rb +24 -16
- data/spec/core/array/take_while_spec.rb +14 -10
- data/spec/core/array/to_a_spec.rb +18 -1
- data/spec/core/array/to_ary_spec.rb +15 -1
- data/spec/core/array/try_convert_spec.rb +39 -2
- data/spec/core/array/uniq_spec.rb +148 -3
- data/spec/core/array/unshift_spec.rb +36 -1
- data/spec/core/array/zip_spec.rb +36 -1
- data/spec/core/class/new_spec.rb +8 -6
- data/spec/core/enumerable/all_spec.rb +37 -9
- data/spec/core/enumerable/any_spec.rb +45 -7
- data/spec/core/enumerable/collect_spec.rb +4 -1
- data/spec/core/enumerable/count_spec.rb +4 -1
- data/spec/core/enumerable/detect_spec.rb +2 -2
- data/spec/core/enumerable/drop_spec.rb +4 -1
- data/spec/core/enumerable/drop_while_spec.rb +4 -1
- data/spec/core/enumerable/each_slice_spec.rb +2 -1
- data/spec/core/enumerable/each_with_index_spec.rb +4 -1
- data/spec/core/enumerable/each_with_object_spec.rb +4 -1
- data/spec/core/enumerable/entries_spec.rb +4 -1
- data/spec/core/enumerable/find_all_spec.rb +4 -1
- data/spec/core/enumerable/find_index_spec.rb +4 -1
- data/spec/core/enumerable/find_spec.rb +5 -2
- data/spec/core/enumerable/first_spec.rb +4 -1
- data/spec/core/enumerable/fixtures/classes.rb +198 -2
- data/spec/core/enumerable/grep_spec.rb +4 -1
- data/spec/core/enumerable/take_spec.rb +4 -1
- data/spec/core/enumerable/to_a_spec.rb +4 -1
- data/spec/core/false/and_spec.rb +11 -0
- data/spec/core/false/inspect_spec.rb +7 -0
- data/spec/core/false/or_spec.rb +11 -0
- data/spec/core/false/to_s_spec.rb +7 -0
- data/spec/core/false/xor_spec.rb +11 -0
- data/spec/core/kernel/rand_spec.rb +5 -5
- data/spec/core/module/const_get_spec.rb +4 -4
- data/spec/core/module/fixtures/classes.rb +434 -0
- data/spec/core/module/method_defined_spec.rb +49 -0
- data/spec/core/module/module_function_spec.rb +28 -0
- data/spec/core/nil/and_spec.rb +3 -1
- data/spec/core/nil/dup_spec.rb +7 -0
- data/spec/core/nil/inspect_spec.rb +3 -1
- data/spec/core/nil/nil_spec.rb +3 -1
- data/spec/core/nil/or_spec.rb +4 -2
- data/spec/core/nil/to_a_spec.rb +3 -1
- data/spec/core/nil/to_f_spec.rb +3 -1
- data/spec/core/nil/to_i_spec.rb +3 -1
- data/spec/core/nil/to_s_spec.rb +3 -1
- data/spec/core/nil/xor_spec.rb +4 -2
- data/spec/core/string/element_reference_spec.rb +14 -1
- data/spec/core/string/fixtures/classes.rb +0 -0
- data/spec/core/true/and_spec.rb +11 -0
- data/spec/core/true/inspect_spec.rb +7 -0
- data/spec/core/true/or_spec.rb +11 -0
- data/spec/core/true/to_s_spec.rb +7 -0
- data/spec/core/true/xor_spec.rb +11 -0
- data/spec/{core → core_ext}/array/element_reference_spec.rb +0 -0
- data/spec/{core → core_ext}/array/equal_value_spec.rb +0 -0
- data/spec/{core → core_ext}/array/fill_spec.rb +0 -0
- data/spec/{core → core_ext}/array/reduce_spec.rb +0 -0
- data/spec/core_ext/basic_object/send_spec.rb +3 -3
- data/spec/{core → core_ext}/boolean/singleton_class_spec.rb +0 -0
- data/spec/{core → core_ext}/boolean/to_json_spec.rb +0 -0
- data/spec/core_ext/class/_inherited_spec.rb +3 -3
- data/spec/core_ext/class/proc_methods_spec.rb +2 -2
- data/spec/core_ext/class/singleton_methods_spec.rb +8 -8
- data/spec/core_ext/method_missing_spec.rb +3 -3
- data/spec/core_ext/native/method_missing_spec.rb +3 -2
- data/spec/core_ext/native/to_native_spec.rb +3 -2
- data/spec/{core → core_ext}/nil/to_json_spec.rb +0 -0
- data/spec/date.rb +0 -0
- data/spec/fileutils.rb +0 -0
- data/spec/filters/ancestors.rb +4 -0
- data/spec/filters/array_delete.rb +3 -0
- data/spec/filters/array_fetch.rb +3 -0
- data/spec/filters/array_first.rb +3 -0
- data/spec/filters/array_flatten.rb +14 -0
- data/spec/filters/array_intersection.rb +5 -0
- data/spec/filters/array_join.rb +6 -0
- data/spec/filters/array_subclasses.rb +4 -0
- data/spec/filters/block_args.rb +3 -0
- data/spec/filters/coerce_integer.rb +9 -0
- data/spec/filters/frozen.rb +4 -0
- data/spec/filters/mocks.rb +3 -0
- data/spec/filters/should_receive.rb +4 -0
- data/spec/filters/tainted.rb +7 -0
- data/spec/fixtures/class.rb +124 -0
- data/spec/fixtures/class_variables.rb +0 -0
- data/spec/fixtures/constants.rb +0 -0
- data/spec/grammar/alias_spec.rb +1 -1
- data/spec/grammar/def_spec.rb +1 -0
- data/spec/grammar/lvar_spec.rb +1 -2
- data/spec/grammar/nth_ref_spec.rb +13 -0
- data/spec/grammar/sclass_spec.rb +6 -7
- data/spec/grammar/str_spec.rb +4 -4
- data/spec/grammar/string_spec.rb +8 -0
- data/spec/grammar/xstr_spec.rb +4 -4
- data/spec/iconv.rb +0 -0
- data/spec/language/alias_spec.rb +140 -3
- data/spec/language/and_spec.rb +14 -7
- data/spec/language/array_spec.rb +57 -5
- data/spec/language/block_spec.rb +466 -49
- data/spec/language/break_spec.rb +294 -44
- data/spec/language/case_spec.rb +151 -3
- data/spec/language/class_spec.rb +196 -0
- data/spec/language/class_variable_spec.rb +56 -0
- data/spec/language/def_spec.rb +507 -4
- data/spec/language/defined_spec.rb +19 -7
- data/spec/language/ensure_spec.rb +26 -39
- data/spec/language/execution_spec.rb +15 -0
- data/spec/language/fixtures/array.rb +11 -0
- data/spec/language/fixtures/block.rb +57 -0
- data/spec/language/fixtures/break.rb +240 -0
- data/spec/language/fixtures/ensure.rb +72 -0
- data/spec/language/fixtures/literal_lambda.rb +7 -0
- data/spec/language/fixtures/metaclass.rb +33 -0
- data/spec/language/fixtures/module.rb +24 -0
- data/spec/language/fixtures/next.rb +78 -12
- data/spec/language/fixtures/return.rb +118 -0
- data/spec/language/fixtures/send.rb +110 -0
- data/spec/language/fixtures/send_1.9.rb +22 -0
- data/spec/language/fixtures/super.rb +308 -0
- data/spec/language/fixtures/variables.rb +58 -0
- data/spec/language/fixtures/yield.rb +5 -0
- data/spec/language/for_spec.rb +192 -0
- data/spec/language/hash_spec.rb +29 -5
- data/spec/language/if_spec.rb +90 -9
- data/spec/language/literal_lambda_spec.rb +1 -47
- data/spec/language/loop_spec.rb +39 -2
- data/spec/language/metaclass_spec.rb +151 -5
- data/spec/language/module_spec.rb +56 -0
- data/spec/language/next_spec.rb +370 -12
- data/spec/language/not_spec.rb +55 -0
- data/spec/language/numbers_spec.rb +56 -0
- data/spec/language/or_spec.rb +31 -3
- data/spec/language/order_spec.rb +79 -0
- data/spec/language/precedence_spec.rb +483 -0
- data/spec/language/proc_spec.rb +249 -21
- data/spec/language/redo_spec.rb +67 -0
- data/spec/language/rescue_spec.rb +121 -0
- data/spec/language/retry_spec.rb +56 -0
- data/spec/language/return_spec.rb +281 -0
- data/spec/language/send_spec.rb +141 -48
- data/spec/language/singleton_class_spec.rb +1 -1
- data/spec/language/string_spec.rb +11 -0
- data/spec/language/super_spec.rb +213 -133
- data/spec/language/symbol_spec.rb +2 -1
- data/spec/language/undef_spec.rb +3 -1
- data/spec/language/unless_spec.rb +6 -2
- data/spec/language/until_spec.rb +102 -3
- data/spec/language/variables_spec.rb +1212 -16
- data/spec/language/versions/array_1.9.rb +39 -0
- data/spec/language/versions/case_1.9.rb +20 -0
- data/spec/language/versions/hash_1.9.rb +18 -0
- data/spec/language/versions/literal_lambda_1.9.rb +143 -0
- data/spec/language/versions/not_1.9.rb +22 -0
- data/spec/language/versions/send_1.9.rb +241 -0
- data/spec/language/versions/symbol_1.9.rb +15 -0
- data/spec/language/versions/variables_1.9.rb +8 -0
- data/spec/language/while_spec.rb +70 -5
- data/spec/language/yield_spec.rb +32 -6
- data/spec/mspec/guards/block_device.rb +0 -0
- data/spec/mspec/guards/endian.rb +0 -0
- data/spec/mspec/helpers/environment.rb +0 -0
- data/spec/mspec/helpers/language_version.rb +0 -0
- data/spec/mspec/helpers/tmp.rb +0 -0
- data/spec/ospec/filter.rb +32 -0
- data/spec/ospec/main.rb.erb +18 -0
- data/spec/ospec/phantom.rb +97 -0
- data/spec/ospec/runner.rb +95 -0
- data/spec/ospec/sprockets.js +40 -0
- data/spec/pp.rb +3 -0
- data/spec/rbconfig.rb +5 -0
- data/spec/spec_helper.rb +53 -26
- data/spec/yaml.rb +0 -0
- metadata +275 -31
- data/config.ru +0 -8
- data/lib/opal/processor.rb +0 -47
- data/lib/opal/scope.rb +0 -236
- data/lib/opal/server.rb +0 -94
- data/spec/core/boolean/and_spec.rb +0 -17
- data/spec/core/boolean/inspect_spec.rb +0 -9
- data/spec/core/boolean/or_spec.rb +0 -17
- data/spec/core/boolean/to_s_spec.rb +0 -9
- data/spec/core/boolean/xor_spec.rb +0 -17
data/config.ru
DELETED
data/lib/opal/processor.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'opal'
|
2
|
-
require 'sprockets'
|
3
|
-
|
4
|
-
module Opal
|
5
|
-
class Processor < Tilt::Template
|
6
|
-
self.default_mime_type = 'application/javascript'
|
7
|
-
|
8
|
-
def self.engine_initialized?
|
9
|
-
true
|
10
|
-
end
|
11
|
-
|
12
|
-
class << self
|
13
|
-
attr_accessor :method_missing_enabled
|
14
|
-
attr_accessor :optimized_operators_enabled
|
15
|
-
attr_accessor :arity_check_enabled
|
16
|
-
end
|
17
|
-
|
18
|
-
self.method_missing_enabled = true
|
19
|
-
self.optimized_operators_enabled = true
|
20
|
-
self.arity_check_enabled = false
|
21
|
-
|
22
|
-
def initialize_engine
|
23
|
-
require_template_library 'opal'
|
24
|
-
end
|
25
|
-
|
26
|
-
def prepare
|
27
|
-
end
|
28
|
-
|
29
|
-
def evaluate(context, locals, &block)
|
30
|
-
options = { :method_missing => self.class.method_missing_enabled,
|
31
|
-
:optimized_operators => self.class.optimized_operators_enabled,
|
32
|
-
:arity_check => self.class.arity_check_enabled }
|
33
|
-
|
34
|
-
parser = Opal::Parser.new
|
35
|
-
result = parser.parse data, options
|
36
|
-
|
37
|
-
parser.requires.each { |r| context.require_asset r }
|
38
|
-
result
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
Tilt.register 'rb', Opal::Processor
|
44
|
-
Sprockets.register_engine '.rb', Opal::Processor
|
45
|
-
|
46
|
-
Tilt.register 'opal', Opal::Processor
|
47
|
-
Sprockets.register_engine '.opal', Opal::Processor
|
data/lib/opal/scope.rb
DELETED
@@ -1,236 +0,0 @@
|
|
1
|
-
module Opal
|
2
|
-
class Parser
|
3
|
-
# Instances of Scope are used by the parser when a new scope is
|
4
|
-
# being processed. It is used to keep track of used variables,
|
5
|
-
# temp variables and ivars so they can be processed and output
|
6
|
-
# along with the scope implementation.
|
7
|
-
class Scope
|
8
|
-
attr_accessor :parent
|
9
|
-
|
10
|
-
attr_accessor :name
|
11
|
-
|
12
|
-
attr_accessor :block_name
|
13
|
-
|
14
|
-
attr_reader :scope_name
|
15
|
-
attr_reader :ivars
|
16
|
-
|
17
|
-
attr_reader :type
|
18
|
-
|
19
|
-
attr_accessor :defines_defn
|
20
|
-
attr_accessor :defines_defs
|
21
|
-
|
22
|
-
attr_accessor :mid
|
23
|
-
|
24
|
-
# true if singleton def, false otherwise
|
25
|
-
attr_accessor :defs
|
26
|
-
|
27
|
-
# used by modules to know what methods to donate to includees
|
28
|
-
attr_reader :methods
|
29
|
-
|
30
|
-
# uses parents super method
|
31
|
-
attr_accessor :uses_super
|
32
|
-
|
33
|
-
def initialize(type, parser)
|
34
|
-
@parser = parser
|
35
|
-
@type = type
|
36
|
-
@locals = []
|
37
|
-
@temps = []
|
38
|
-
@args = []
|
39
|
-
@ivars = []
|
40
|
-
@parent = nil
|
41
|
-
@queue = []
|
42
|
-
@unique = "a"
|
43
|
-
@while_stack = []
|
44
|
-
|
45
|
-
@defines_defs = false
|
46
|
-
@defines_defn = false
|
47
|
-
|
48
|
-
@methods = []
|
49
|
-
|
50
|
-
@uses_block = false
|
51
|
-
|
52
|
-
# used by classes to store all ivars used in direct def methods
|
53
|
-
@proto_ivars = []
|
54
|
-
end
|
55
|
-
|
56
|
-
# Returns true if this scope is a class/module body scope
|
57
|
-
def class_scope?
|
58
|
-
@type == :class or @type == :module
|
59
|
-
end
|
60
|
-
|
61
|
-
def class?
|
62
|
-
@type == :class
|
63
|
-
end
|
64
|
-
|
65
|
-
def module?
|
66
|
-
@type == :module
|
67
|
-
end
|
68
|
-
|
69
|
-
def top?
|
70
|
-
@type == :top
|
71
|
-
end
|
72
|
-
|
73
|
-
def iter?
|
74
|
-
@type == :iter
|
75
|
-
end
|
76
|
-
|
77
|
-
# Is this a normal def method directly inside a class? This is
|
78
|
-
# used for optimizing ivars as we can set them to nil in the
|
79
|
-
# class body
|
80
|
-
def def_in_class?
|
81
|
-
!@defs && @type == :def && @parent && @parent.class?
|
82
|
-
end
|
83
|
-
|
84
|
-
def proto
|
85
|
-
"def"
|
86
|
-
end
|
87
|
-
|
88
|
-
def should_donate?
|
89
|
-
@type == :module or @name.to_s == 'Object'
|
90
|
-
end
|
91
|
-
|
92
|
-
##
|
93
|
-
# Vars to use inside each scope
|
94
|
-
def to_vars
|
95
|
-
vars = @locals.map { |l| "#{l} = nil" }
|
96
|
-
vars.push *@temps
|
97
|
-
current_self = @parser.current_self
|
98
|
-
|
99
|
-
iv = ivars.map do |ivar|
|
100
|
-
"if (#{current_self}#{ivar} == null) #{current_self}#{ivar} = nil;\n"
|
101
|
-
end
|
102
|
-
|
103
|
-
indent = @parser.parser_indent
|
104
|
-
res = vars.empty? ? '' : "var #{vars.join ', '};"
|
105
|
-
str = ivars.empty? ? res : "#{res}\n#{indent}#{iv.join indent}"
|
106
|
-
|
107
|
-
if class? and !@proto_ivars.empty?
|
108
|
-
pvars = @proto_ivars.map { |i| "#{proto}#{i}"}.join(' = ')
|
109
|
-
"%s\n%s%s = nil;" % [str, indent, pvars]
|
110
|
-
else
|
111
|
-
str
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Generates code for this module to donate methods
|
116
|
-
def to_donate_methods
|
117
|
-
if should_donate? and !@methods.empty?
|
118
|
-
"%s;#{@name}._donate([%s]);" % [@parser.parser_indent, @methods.map(&:inspect).join(', ')]
|
119
|
-
else
|
120
|
-
""
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def add_ivar(ivar)
|
125
|
-
if def_in_class?
|
126
|
-
@parent.add_proto_ivar ivar
|
127
|
-
else
|
128
|
-
@ivars << ivar unless @ivars.include? ivar
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def add_proto_ivar(ivar)
|
133
|
-
@proto_ivars << ivar unless @proto_ivars.include? ivar
|
134
|
-
end
|
135
|
-
|
136
|
-
def add_arg(arg)
|
137
|
-
@args << arg unless @args.include? arg
|
138
|
-
end
|
139
|
-
|
140
|
-
def add_local(local)
|
141
|
-
return if has_local? local
|
142
|
-
|
143
|
-
@locals << local
|
144
|
-
end
|
145
|
-
|
146
|
-
def has_local?(local)
|
147
|
-
return true if @locals.include? local or @args.include? local
|
148
|
-
return @parent.has_local?(local) if @parent and @type == :iter
|
149
|
-
|
150
|
-
false
|
151
|
-
end
|
152
|
-
|
153
|
-
def add_temp(*tmps)
|
154
|
-
@temps.push *tmps
|
155
|
-
end
|
156
|
-
|
157
|
-
def has_temp?(tmp)
|
158
|
-
@temps.include? tmp
|
159
|
-
end
|
160
|
-
|
161
|
-
def new_temp
|
162
|
-
return @queue.pop unless @queue.empty?
|
163
|
-
|
164
|
-
tmp = "_#{@unique}"
|
165
|
-
@unique = @unique.succ
|
166
|
-
@temps << tmp
|
167
|
-
tmp
|
168
|
-
end
|
169
|
-
|
170
|
-
def queue_temp(name)
|
171
|
-
@queue << name
|
172
|
-
end
|
173
|
-
|
174
|
-
def push_while
|
175
|
-
info = {}
|
176
|
-
@while_stack.push info
|
177
|
-
info
|
178
|
-
end
|
179
|
-
|
180
|
-
def pop_while
|
181
|
-
@while_stack.pop
|
182
|
-
end
|
183
|
-
|
184
|
-
def in_while?
|
185
|
-
!@while_stack.empty?
|
186
|
-
end
|
187
|
-
|
188
|
-
def uses_block!
|
189
|
-
if @type == :iter && @parent
|
190
|
-
@parent.uses_block!
|
191
|
-
else
|
192
|
-
@uses_block = true
|
193
|
-
# identify!
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def identify!
|
198
|
-
return @identity if @identity
|
199
|
-
|
200
|
-
@identity = @parser.unique_temp
|
201
|
-
@parent.add_temp @identity if @parent
|
202
|
-
|
203
|
-
@identity
|
204
|
-
end
|
205
|
-
|
206
|
-
def identity
|
207
|
-
@identity
|
208
|
-
end
|
209
|
-
|
210
|
-
def get_super_chain
|
211
|
-
chain, scope, defn, mid = [], self, 'null', 'null'
|
212
|
-
|
213
|
-
while scope
|
214
|
-
if scope.type == :iter
|
215
|
-
chain << scope.identify!
|
216
|
-
scope = scope.parent if scope.parent
|
217
|
-
|
218
|
-
elsif scope.type == :def
|
219
|
-
defn = scope.identify!
|
220
|
-
mid = "'$#{scope.mid}'"
|
221
|
-
break
|
222
|
-
|
223
|
-
else
|
224
|
-
break
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
[chain, defn, mid]
|
229
|
-
end
|
230
|
-
|
231
|
-
def uses_block?
|
232
|
-
@uses_block
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
data/lib/opal/server.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'opal'
|
2
|
-
require 'erb'
|
3
|
-
|
4
|
-
module Opal
|
5
|
-
class Server
|
6
|
-
|
7
|
-
attr_accessor :debug, :index_path, :main, :public_dir, :sprockets
|
8
|
-
|
9
|
-
def initialize(debug = true)
|
10
|
-
@sprockets = Sprockets::Environment.new
|
11
|
-
Opal.paths.each { |p| @sprockets.append_path p }
|
12
|
-
|
13
|
-
@public_dir = '.'
|
14
|
-
@debug = debug
|
15
|
-
|
16
|
-
yield self if block_given?
|
17
|
-
create_app
|
18
|
-
end
|
19
|
-
|
20
|
-
def append_path(path)
|
21
|
-
@sprockets.append_path path
|
22
|
-
end
|
23
|
-
|
24
|
-
def create_app
|
25
|
-
server, sprockets = self, @sprockets
|
26
|
-
|
27
|
-
@app = Rack::Builder.app do
|
28
|
-
map('/assets') { run sprockets }
|
29
|
-
use Index, server
|
30
|
-
run Rack::Directory.new(server.public_dir)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def call(env)
|
35
|
-
@app.call env
|
36
|
-
end
|
37
|
-
|
38
|
-
class Index
|
39
|
-
|
40
|
-
def initialize(app, server)
|
41
|
-
@app = app
|
42
|
-
@server = server
|
43
|
-
@index_path = server.index_path
|
44
|
-
end
|
45
|
-
|
46
|
-
def call(env)
|
47
|
-
if %w[/ /index.html].include? env['PATH_INFO']
|
48
|
-
[200, { 'Content-Type' => 'text/html' }, [html]]
|
49
|
-
else
|
50
|
-
@app.call env
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def html
|
55
|
-
source = if @index_path
|
56
|
-
raise "index does not exist: #{@index_path}" unless File.exist?(@index_path)
|
57
|
-
File.read @index_path
|
58
|
-
else
|
59
|
-
SOURCE
|
60
|
-
end
|
61
|
-
|
62
|
-
ERB.new(source).result binding
|
63
|
-
end
|
64
|
-
|
65
|
-
def javascript_include_tag(source)
|
66
|
-
if @server.debug
|
67
|
-
assets = @server.sprockets[source].to_a
|
68
|
-
|
69
|
-
raise "Cannot find asset: #{source}" if assets.empty?
|
70
|
-
|
71
|
-
scripts = assets.map do |a|
|
72
|
-
%Q{<script src="/assets/#{ a.logical_path }?body=1"></script>}
|
73
|
-
end
|
74
|
-
|
75
|
-
scripts.join "\n"
|
76
|
-
else
|
77
|
-
"<script src=\"/assets/#{source}.js\"></script>"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
SOURCE = <<-HTML
|
82
|
-
<!DOCTYPE html>
|
83
|
-
<html>
|
84
|
-
<head>
|
85
|
-
<title>Opal Server</title>
|
86
|
-
</head>
|
87
|
-
<body>
|
88
|
-
<%= javascript_include_tag @server.main %>
|
89
|
-
</body>
|
90
|
-
</html>
|
91
|
-
HTML
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
describe "Boolean#&" do
|
2
|
-
it "when false returns false" do
|
3
|
-
(false & true).should == false
|
4
|
-
(false & false).should == false
|
5
|
-
(false & nil).should == false
|
6
|
-
(false & "").should == false
|
7
|
-
(false & mock('x')).should == false
|
8
|
-
end
|
9
|
-
|
10
|
-
it "when true returns false if other is nil or false, otherwise true" do
|
11
|
-
(true & true).should == true
|
12
|
-
(true & false).should == false
|
13
|
-
(true & nil).should == false
|
14
|
-
(true & "").should == true
|
15
|
-
(true & mock('x')).should == true
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
describe "Boolean#|" do
|
2
|
-
it "when false returns false if other is nil or false, otherwise true" do
|
3
|
-
(false | false).should == false
|
4
|
-
(false | true).should == true
|
5
|
-
(false | nil).should == false
|
6
|
-
(false | "").should == true
|
7
|
-
(false | mock('x')).should == true
|
8
|
-
end
|
9
|
-
|
10
|
-
it "when true returns true" do
|
11
|
-
(true | true).should == true
|
12
|
-
(true | false).should == true
|
13
|
-
(true | nil).should == true
|
14
|
-
(true | "").should == true
|
15
|
-
(true | mock('x')).should == true
|
16
|
-
end
|
17
|
-
end
|