Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thirdparty javascript library Pure.js exposed methods causing error #33

Closed
kingsleyh opened this issue Jan 9, 2014 · 3 comments
Closed

Comments

@kingsleyh
Copy link

I hope this is the right project to log this.

I'm trying to use opal-jquery with the pure.js (http://beebole.com/pure/documentation/get-started/) library

however when I expose the :render method - I get an error from the pure.js as if it's being triggered when exposed.

This is my application.rb

  puts "go"
  Document.ready? do  
   require "opal"
   require 'jquery'
   require 'opal-jquery'
   require 'pure.min'
    Element.expose :render
    $q = $global["$"]
    $q.('div.template').render({'site' => 'google','url' => 'http://www.google.com'}, {'a' => 'site', 'a@href' => 'url'})
   end
   puts "done"

and the error:

uncaught exception: pure error: cannot have more than one loop on a target
"cannot have more than one loop on a target" pure.min.js:14

Please let me know if you have any suggestions about this.

@kingsleyh
Copy link
Author

looking at the pure.js code - it's possible that the Element.expose(:render) call is not exposing the correct render method as the pure.js code for jquery support looks like this:

jquery:function(){
        jQuery.fn.extend({
            directives:function(directive){
                this._pure_d = directive; return this;
            },
            compile:function(directive, ctxt){
                return $p(this).compile(this._pure_d || directive, ctxt);
            },
            render:function(ctxt, directive){
                return jQuery( $p( this ).render( ctxt, this._pure_d || directive ) );
            },
            autoRender:function(ctxt, directive){
                return jQuery( $p( this ).autoRender( ctxt, this._pure_d || directive ) );
            }
        });
        return function(n, sel){
            return jQuery(n).find(sel);
        };
    },

@elia
Copy link
Member

elia commented Jan 9, 2014

@kingsleyh try this:

require 'pure.min'
require 'native' # adds #to_n
require 'opal-jquery'

Element.expose :render

data = {
  who: 'BeeBole!',
  site: 'http://beebole.com'
}
directive = {
  a: 'who', 
  'a@href'=>'site' 
}

Element.find('div.template').render(data.to_n, directive.to_n)

hashes are not the same as literal js objects

@kingsleyh
Copy link
Author

Aha thanks - after a change to the require lines - this works:

require "opal"
require 'jquery'
require 'opal-jquery'
require 'pure.min'
require 'native' # adds #to_n

Document.ready? do

Element.expose :render

data = {
who: 'BeeBole!',
site: 'http://beebole.com'
}
directive = {
a: 'who',
'a@href'=>'site'
}

Element.find('div.template').render(data.to_n, directive.to_n)

end

I assumed the opal magic was translating ruby hashes into the js world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants