goat 0.3.17 → 0.3.18

Sign up to get free protection for your applications and to get access to all the features.
data/goat.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'goat'
3
- s.version = '0.3.17'
3
+ s.version = '0.3.18'
4
4
  s.summary = 'Pre-release beta version of Goat'
5
5
  s.author = 'Patrick Collison'
6
6
  s.email = 'patrick@collison.ie'
data/lib/goat.rb CHANGED
@@ -787,6 +787,8 @@ module Goat
787
787
  StateSrvClient.register_page(@id, pg_spec)
788
788
  end
789
789
 
790
+ def _dom; self.dom; end
791
+
790
792
  def html_from_erb
791
793
  html = self.erb(@erb, :layout => false)
792
794
  end
@@ -796,7 +798,7 @@ module Goat
796
798
  helper = ExpansionHelper.new
797
799
 
798
800
  Dynamic.let(:expander => helper) do
799
- exp = DOMTools.expanded_dom(self.dom)
801
+ exp = DOMTools.expanded_dom(self._dom)
800
802
  end
801
803
 
802
804
  distiller = DOMDistiller.new(exp, helper.components)
@@ -1101,6 +1103,7 @@ module Goat
1101
1103
 
1102
1104
  class Component
1103
1105
  attr_reader :id, :handlers, :page, :params, :initargs
1106
+ attr_accessor :parent
1104
1107
 
1105
1108
  include HTMLHelpers # sure just shit it in with everything else - TODO remove?
1106
1109
 
@@ -1129,7 +1132,7 @@ module Goat
1129
1132
  c = Kernel.fetch_class(skel.cls).from_skel(skel)
1130
1133
  c.deserialize(skel.state)
1131
1134
  Profile.out(:create_component)
1132
-
1135
+
1133
1136
  c.rerender
1134
1137
  end
1135
1138
 
@@ -1226,6 +1229,7 @@ module Goat
1226
1229
 
1227
1230
  def initialize
1228
1231
  @id = 'dom_' + String.random(10)
1232
+ @parent = Dynamic[:parent] if Dynamic.variable?(:parent)
1229
1233
  end
1230
1234
 
1231
1235
  def live_for(spec)
@@ -1277,7 +1281,7 @@ module Goat
1277
1281
  def clientside_args; []; end
1278
1282
 
1279
1283
  def clientside_instance
1280
- args = [id, clientside_args].to_json[1..-2]
1284
+ args = [id, @parent ? @parent.id : nil, clientside_args].to_json[1..-2]
1281
1285
  "(new #{self.class.name}('#{self.class.name}', #{args}))"
1282
1286
  end
1283
1287
 
@@ -1319,7 +1323,15 @@ module Goat
1319
1323
  end
1320
1324
 
1321
1325
  def expanded_dom
1322
- @expanded_dom ||= DOMTools.expanded_dom(inject_prefixes(self.dom))
1326
+ @expanded_dom ||= DOMTools.expanded_dom(inject_prefixes(self._dom))
1327
+ end
1328
+
1329
+ def _dom
1330
+ if Dynamic.variable?(:in_a_dom) && !Dynamic.variable(:parent)
1331
+ raise "You must set the parent of a component before inserting it into the DOM tree. Try calling #parent=."
1332
+ end
1333
+
1334
+ Dynamic.let(:parent => self, :in_a_dom => true) { self.dom }
1323
1335
  end
1324
1336
 
1325
1337
  def dom_as_expanded
@@ -1,12 +1,20 @@
1
1
  var Component = Class.extend({
2
- init: function(cls, id, args) {
2
+ init: function(cls, id, par, args) {
3
3
  this.id = id;
4
4
  this.cls = cls;
5
5
  this.loaded = false;
6
+ this.parentid = par;
6
7
 
7
8
  for(var k in args) {
8
9
  this[k] = args[k]
9
10
  }
11
+
12
+ if(this.initialize)
13
+ this.initialize(args);
14
+ },
15
+
16
+ parent: function() {
17
+ return Goat.components[this.parentid];
10
18
  },
11
19
 
12
20
  onLoad: function() {
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
4
+ hash: 55
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 17
10
- version: 0.3.17
9
+ - 18
10
+ version: 0.3.18
11
11
  platform: ruby
12
12
  authors:
13
13
  - Patrick Collison
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-27 00:00:00 +00:00
18
+ date: 2010-11-30 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies: []
21
21