[Bps-public-commit] r12667 - in pie/branches/named-params: lib/PIE pieplate/PIE-Plate/lib/PIE/Plate pieplate/PIE-Plate/lib/PIE/Plate/Action

jesse at bestpractical.com jesse at bestpractical.com
Sat May 24 11:53:37 EDT 2008


Author: jesse
Date: Sat May 24 11:53:36 2008
New Revision: 12667

Added:
   pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/Action/RunL.pm
Modified:
   pie/branches/named-params/lib/PIE/Evaluator.pm
   pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/View.pm
   pie/branches/named-params/pieplate/PIE-Plate/share/web/static/js/pieui.js

Log:
* basic run-on-server-from-js

Modified: pie/branches/named-params/lib/PIE/Evaluator.pm
==============================================================================
--- pie/branches/named-params/lib/PIE/Evaluator.pm	(original)
+++ pie/branches/named-params/lib/PIE/Evaluator.pm	Sat May 24 11:53:36 2008
@@ -58,7 +58,7 @@
     my $self       = shift;
     my $expression = shift;
     eval {
-        Carp::confess unless ($expression);
+        Carp::confess unless ($expression && $expression->can('evaluate'));
         my $ret = $expression->evaluate($self);
 
 

Added: pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/Action/RunL.pm
==============================================================================
--- (empty file)
+++ pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/Action/RunL.pm	Sat May 24 11:53:36 2008
@@ -0,0 +1,50 @@
+package PIE::Plate::Action::RunL;
+use PIE::Lambda;
+use PIE::Lambda::Native;
+use PIE::Builder; use PIE::FunctionArgument;
+use PIE::Evaluator; use JSON;
+use Jifty::Param::Schema;
+use PIE::Plate::Action schema {
+    param struct => type is 'text';
+};
+
+
+sub take_action {
+    my $self = shift;
+    warn $self->argument_value('struct');
+    my $tree = JSON::from_json($self->argument_value('struct'));
+    my $builder = PIE::Builder->new();
+    my $eval = PIE::Evaluator->new();
+
+
+my $MATCH_REGEX = PIE::Lambda::Native->new(
+    body => sub {
+        my $args = shift;
+        my $arg = $args->{'tested-string'};
+        my $regex = $args->{'regex'};
+
+        return $arg =~ m/$regex/;
+    },
+
+    signature => {
+           'tested-string' =>  PIE::FunctionArgument->new( name =>              'tested-string' =>  type => 'Str' ),
+           'regexp'=>  PIE::FunctionArgument->new( name =>      'regex', type => 'Str' )
+    }
+
+);
+$eval->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
+
+
+    my $script  = $builder->defun( ops => $tree, signature => {});
+    eval { $eval->apply_script($script, {} )};
+    if (my $msg = $@) { 
+        $self->result->error($msg);
+    }else {
+    warn $eval->result->value, $eval->result->success ;
+
+    $self->result->message($eval->result->value);
+   $eval->result->success ||  $eval->result->error($eval->result->error);
+}
+}
+
+1;

Modified: pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/View.pm
==============================================================================
--- pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/View.pm	(original)
+++ pie/branches/named-params/pieplate/PIE-Plate/lib/PIE/Plate/View.pm	Sat May 24 11:53:36 2008
@@ -4,26 +4,13 @@
 
 template 'index.html' => page {'hey'};
 template 'lorzy' => page { 
-
+    div { { id is 'result' }};
     div { { id is 'wrapper' } };
  outs_raw('<style>#wrapper div { padding-left:1em;} </style>');
 my $ops = [
-            {  name => 'hateyou', args => {}},
-
             {   name => 'IfThen',
                 args => {
-                    'if_true'   =>  { 
-                                    name => 'progn',
-                                    nodes => [
-                                            { name => 'IsTrue', args => {}}, 
-                                            { name => 'IsFalse', args => {}},
-                                            { name => 'IsTrue', args => {}}
-
-
-                                    ]
-
-
-                    },
+                    'if_true'   =>  'hate',
                     'if_false'  => 'love',
                     'condition' => {
                         name => 'match-regexp',

Modified: pie/branches/named-params/pieplate/PIE-Plate/share/web/static/js/pieui.js
==============================================================================
--- pie/branches/named-params/pieplate/PIE-Plate/share/web/static/js/pieui.js	(original)
+++ pie/branches/named-params/pieplate/PIE-Plate/share/web/static/js/pieui.js	Sat May 24 11:53:36 2008
@@ -75,6 +75,21 @@
     jQuery('#wrapper').after(jQuery('<a href="#">Remove</a>').attr('id', 'remove-entry'));
     jQuery('#wrapper').after(jQuery('<a href="#">Add If</a>').attr('id', 'add-entry-if'));
     jQuery('#wrapper').after(jQuery('<a href="#">Traverse</a>').attr('id', 'clicky'));
+    jQuery('#wrapper').after(jQuery('<a href="#">Test</a>').attr('id', 'testy'));
+
+    jQuery('#testy').click(function () {
+        jQuery.ajax({
+    'url': '/=/action/Pie.Plate.Action.RunL.xml',
+    'datatype': 'text/xml',
+    'type': 'post',
+    'success': function(xml) { 
+            jQuery('#result').append(jQuery(xml).text())
+}, 
+    'data': 'struct='+lorzy_generate_struct(jQuery('#wrapper')).toJSON()
+})
+
+
+    });
 
     jQuery('#remove-entry').click(function() {
         var el = jQuery('div.selected');
@@ -98,7 +113,8 @@
     });
     
     jQuery('#clicky').click(function () { 
-   
+  
+ 
     var x =  lorzy_generate_struct(jQuery('#wrapper'));
     
     console.log(x.toJSON());



More information about the Bps-public-commit mailing list