lib/flok/user_compiler.rb in flok-0.0.38 vs lib/flok/user_compiler.rb in flok-0.0.39
- old
+ new
@@ -12,11 +12,11 @@
@src = ""
ctable_erb = File.read File.join(File.dirname(__FILE__), "./user_compiler_templates/ctable.js.erb")
ctable_renderer = ERB.new(ctable_erb)
@src << ctable_renderer.result(context.get_binding)
-
+
return @src
end
end
end
@@ -167,11 +167,10 @@
var vcs = __info__.embeds[#{spot_index-1}];
for (var i = 0; i < vcs.length; ++i) {
int_event(vcs[i], #{event_name}, #{info});
}
}
-
#GOTO(action_name)
elsif l =~ /Goto/
l.strip!
l.gsub!(/Goto\(/, "")
l.gsub! /\)$/, ""
@@ -238,14 +237,142 @@
o = l.split(",").map{|e| e.strip}
name = o.shift.gsub(/"/, "")
ename = o.shift.gsub(/"/, "")
info = o.shift.gsub(/"/, "")
-
raise "You tried to Request the service #{name.inspect}, but you haven't added that to your 'services' for this controller (#{@controller.name.inspect})" unless @controller._services.include? name
-
out << %{
#{name}_on_#{ename}(__base__, #{info});
+ }
+ #VM Page macros
+ elsif l =~ /NewPage/
+ le = (l.split /NewPage/)
+ lvar = le[0].strip #Probably var x =
+ exp = le[1].strip
+
+ #For CopyPage(original_page), page_var is original_page
+ #This only supports variable names at this time
+ exp.match /\((.*)\);?/
+
+ #Get the id value the user wants, but we have to be careful
+ #because if nothing is passed, then we need to set it to null
+ id_var = $1.strip
+ if id_var == ""
+ id_var = "null"
+ end
+
+ out << %{
+ #{lvar} {
+ _head: null,
+ _next: null,
+ entries: [],
+ _id: #{id_var},
+ }
+ }
+ elsif l =~ /CopyPage/
+ le = (l.split /CopyPage/)
+ lvar = le[0].strip #Probably var x =
+ exp = le[1].strip
+
+ #For CopyPage(original_page), page_var is original_page
+ #This only supports variable names at this time
+ exp.match /\((.*)\);?/
+ page_var = $1
+
+ out << %{
+ var __page__ = {
+ _head: #{page_var}._head,
+ _next: #{page_var}._next,
+ _id: #{page_var}._id,
+ entries: [],
+ }
+
+ //This is a shallow clone, but we own this array
+ //When a mutable entry needs to be created, an entry will be cloned
+ //and swappend out
+ for (var i = 0; i < #{page_var}.entries.length; ++i) {
+ __page__.entries.push(#{page_var}.entries[i]);
+ }
+
+ #{lvar} __page__;
+ }
+ elsif l =~ /EntryDel/
+ le = (l.split /EntryDel/)
+ lvar = le[0].strip #Probably var x =
+ exp = le[1].strip
+
+ #For CopyPage(original_page), page_var is original_page
+ #This only supports variable names at this time
+ exp.match /\((.*?),(.*)\);?/
+ page_var = $1
+ index_var = $2
+
+ out << %{
+ #{page_var}.entries.splice(#{index_var}, 1);
+ }
+
+ elsif l =~ /EntryInsert/
+ le = (l.split /EntryInsert/)
+ lvar = le[0].strip #Probably var x =
+ exp = le[1].strip
+
+ #For CopyPage(original_page), page_var is original_page
+ #This only supports variable names at this time
+ exp.match /\((.*?),(.*),(.*)\);?/
+ page_var = $1
+ index_var = $2
+ entry_var = $3
+
+ out << %{
+ #{entry_var}._id = gen_id();
+ #{entry_var}._sig = gen_id();
+ #{page_var}.entries.splice(#{index_var}, 0, #{entry_var});
+ }
+
+ elsif l =~ /SetPageNext/
+ le = (l.split /SetPageNext/)
+ lvar = le[0].strip #Probably var x =
+ exp = le[1].strip
+
+ #For CopyPage(original_page), page_var is original_page
+ #This only supports variable names at this time
+ exp.match /\((.*?),(.*)\);?/
+ page_var = $1
+ value_var = $2
+
+ out << %{
+ #{page_var}._next = #{value_var};
+ }
+
+ elsif l =~ /SetPageHead/
+ le = (l.split /SetPageHead/)
+ lvar = le[0].strip #Probably var x =
+ exp = le[1].strip
+
+ #For CopyPage(original_page), page_var is original_page
+ #This only supports variable names at this time
+ exp.match /\((.*?),(.*)\);?/
+ page_var = $1
+ value_var = $2
+
+ out << %{
+ #{page_var}._head = #{value_var};
+ }
+
+ elsif l =~ /EntryMutable/
+ le = (l.split /EntryMutable/)
+ lvar = le[0].strip #Probably var x =
+ exp = le[1].strip
+
+ #For CopyPage(original_page), page_var is original_page
+ #This only supports variable names at this time
+ exp.match /\((.*?),(.*)\);?/
+ page_var = $1
+ index_var = $2
+
+ out << %{
+ //Duplicate entry
+ #{page_var}.entries.splice(#{index_var}, 1, JSON.parse(JSON.stringify(#{page_var}.entries[#{index_var}])));
}
else
out.puts l
end
end