Class: Jabs::Precompiler
- Inherits:
-
Fold::Precompiler
- Object
- Fold::Precompiler
- Jabs::Precompiler
- Defined in:
- lib/jabs.rb
Class Attribute Summary collapse
-
.spot_replacements ⇒ Object
Returns the value of attribute spot_replacements.
Instance Attribute Summary collapse
-
#current_sexp ⇒ Object
readonly
Returns the value of attribute current_sexp.
-
#sexp ⇒ Object
readonly
Returns the value of attribute sexp.
Class Method Summary collapse
- .compile_arguments(expression, call, real, args) ⇒ Object
- .do_spot_replace(expression, precompiler = nil) ⇒ Object
- .spot_replace(key, &block) ⇒ Object
Instance Method Summary collapse
- #access(left, right) ⇒ Object
- #call(*args) ⇒ Object
- #event_bind(event, binds_to, function_sexp = nil) ⇒ Object
- #function(name = nil, args = [], function_sexp = nil) ⇒ Object
-
#initialize ⇒ Precompiler
constructor
A new instance of Precompiler.
- #johnsonize(sexp) ⇒ Object
- #jquery(*jquery_arg) ⇒ Object
- #onready(function_sexp = nil) ⇒ Object
- #parse(expression) ⇒ Object
- #source(block = nil) ⇒ Object
Constructor Details
#initialize ⇒ Precompiler
Returns a new instance of Precompiler.
79 80 81 82 83 84 85 |
# File 'lib/jabs.rb', line 79 def initialize super @ready = false @current_sexp = [] @full_sexp = [:source_elements, @current_sexp] end |
Class Attribute Details
.spot_replacements ⇒ Object
Returns the value of attribute spot_replacements.
68 69 70 |
# File 'lib/jabs.rb', line 68 def spot_replacements @spot_replacements end |
Instance Attribute Details
#current_sexp ⇒ Object (readonly)
Returns the value of attribute current_sexp.
77 78 79 |
# File 'lib/jabs.rb', line 77 def current_sexp @current_sexp end |
#sexp ⇒ Object (readonly)
Returns the value of attribute sexp.
77 78 79 |
# File 'lib/jabs.rb', line 77 def sexp @sexp end |
Class Method Details
.compile_arguments(expression, call, real, args) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/jabs.rb', line 223 def self.compile_arguments expression, call, real, args return real if expression[Regexp.new("^\\#{call}\\(")] arguments = [] if args[/^\./] "#{call}()#{do_spot_replace(args).gsub("$this", "")}" else args.split(/\s|,/).each do |arg| arg.gsub!(/:(\w+)/) {%{"#{$1}"}} next if arg[/\s/] next if arg == "" arguments << arg end "#{call}(#{arguments.join(', ')})" end end |
.do_spot_replace(expression, precompiler = nil) ⇒ Object
216 217 218 219 220 221 |
# File 'lib/jabs.rb', line 216 def self.do_spot_replace expression, precompiler=nil spot_replacements.each do |block| expression = block.call(expression, precompiler) end expression end |
.spot_replace(key, &block) ⇒ Object
73 74 75 |
# File 'lib/jabs.rb', line 73 def self.spot_replace key, &block spot_replacements << block if block_given? end |
Instance Method Details
#access(left, right) ⇒ Object
262 263 264 |
# File 'lib/jabs.rb', line 262 def access left, right [:dot_accessor, right, left] end |
#call(*args) ⇒ Object
254 255 256 |
# File 'lib/jabs.rb', line 254 def call *args [:function_call, args] end |
#event_bind(event, binds_to, function_sexp = nil) ⇒ Object
250 251 252 |
# File 'lib/jabs.rb', line 250 def event_bind event, binds_to, function_sexp=nil call(access(binds_to, [:name, "live"]), [:string, event], function(nil, ["e"], function_sexp)) end |
#function(name = nil, args = [], function_sexp = nil) ⇒ Object
266 267 268 |
# File 'lib/jabs.rb', line 266 def function name=nil, args=[], function_sexp=nil [:function, name, args, function_sexp] end |
#johnsonize(sexp) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/jabs.rb', line 277 def johnsonize(sexp) return sexp if sexp.is_a?(Johnson::Nodes::Node) return sexp if sexp.class.to_s == "String" return [] if sexp === [] return nil if sexp === nil unless sexp.first.class.to_s == "Array" if sexp.first.class.to_s == "Symbol" klass = eval("Johnson::Nodes::#{sexp.shift.to_s.camelcase}") klass.new 0,0, *sexp.map{|n|johnsonize(n)} elsif sexp.is_a? Array sexp.map{|n|johnsonize(n)} else sexp end else sexp.map{|n|johnsonize(n)} end end |
#jquery(*jquery_arg) ⇒ Object
270 271 272 273 274 275 |
# File 'lib/jabs.rb', line 270 def jquery *jquery_arg [:function_call, [ [:name, 'jQuery'], *jquery_arg ]] end |
#onready(function_sexp = nil) ⇒ Object
258 259 260 |
# File 'lib/jabs.rb', line 258 def onready function_sexp=nil event_bind('ready', jquery([:name, "document"]), function_sexp) end |
#parse(expression) ⇒ Object
239 240 241 242 |
# File 'lib/jabs.rb', line 239 def parse expression self.class.do_spot_replace expression, self Johnson::Parser.parse(expression).value.first end |
#source(block = nil) ⇒ Object
244 245 246 247 248 |
# File 'lib/jabs.rb', line 244 def source block=nil source = [:source_elements] source << [block] unless(block.nil? or block.empty?) source end |