rhodes-translator 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rhodes_translator/binding.rb +13 -0
- data/spec/binding_spec.rb +54 -0
- metadata +22 -5
@@ -61,6 +61,18 @@ module RhodesTranslator
|
|
61
61
|
current = data
|
62
62
|
while element = elements.delete_at(0)
|
63
63
|
element.strip!
|
64
|
+
if element =~ /^#/
|
65
|
+
element.gsub!(/^#/,'')
|
66
|
+
element.gsub!(/\)$/,'')
|
67
|
+
sube = element.split('(')
|
68
|
+
method = sube[0]
|
69
|
+
params = sube[1]
|
70
|
+
if current.respond_to? method.to_sym
|
71
|
+
current = current.send method.to_sym,params
|
72
|
+
else
|
73
|
+
current = data["self"].send method.to_sym,params
|
74
|
+
end
|
75
|
+
else
|
64
76
|
if current.is_a? Array
|
65
77
|
index = element.to_i
|
66
78
|
return "INVALID INDEX" if index == 0 and element[0].chr != '0'
|
@@ -77,6 +89,7 @@ module RhodesTranslator
|
|
77
89
|
return "INVALID DATA TYPE"
|
78
90
|
end
|
79
91
|
end
|
92
|
+
end
|
80
93
|
end #while
|
81
94
|
current
|
82
95
|
end #decode_path
|
data/spec/binding_spec.rb
CHANGED
@@ -85,6 +85,60 @@ describe "Binding" do
|
|
85
85
|
(bind(data,textfieldbind))['value'].should == "Not Me"
|
86
86
|
|
87
87
|
end
|
88
|
+
|
89
|
+
it "should call methods" do
|
90
|
+
textfieldbind = { 'label' => 'Address',
|
91
|
+
'value' => '{{0/#method_call(foo)}}',
|
92
|
+
'name' => 'address1',
|
93
|
+
'type' => 'text',
|
94
|
+
'type_class' => 'show_text' }
|
95
|
+
class TestObject
|
96
|
+
def first_name
|
97
|
+
'Not'
|
98
|
+
end
|
99
|
+
def last_name
|
100
|
+
'Me'
|
101
|
+
end
|
102
|
+
|
103
|
+
def method_call(somestring)
|
104
|
+
somestring
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
testobj = TestObject.new
|
109
|
+
data = [ testobj ,
|
110
|
+
{'first_name' => 'Some', 'last_name' => 'Name'} ]
|
111
|
+
|
112
|
+
(bind(data,textfieldbind))['value'].should == "foo"
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should call undefined methods against self" do
|
117
|
+
textfieldbind = { 'label' => 'Address',
|
118
|
+
'value' => '{{#method_call(foo)}} {{foo}}',
|
119
|
+
'name' => 'address1',
|
120
|
+
'type' => 'text',
|
121
|
+
'type_class' => 'show_text' }
|
122
|
+
class TestObject
|
123
|
+
def first_name
|
124
|
+
'Not'
|
125
|
+
end
|
126
|
+
def last_name
|
127
|
+
'Me'
|
128
|
+
end
|
129
|
+
|
130
|
+
def method_call(somestring)
|
131
|
+
somestring
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
testobj = TestObject.new
|
136
|
+
data = { "self" => testobj, "foo" => "bar" }
|
137
|
+
|
138
|
+
(bind(data,textfieldbind))['value'].should == "foo bar"
|
139
|
+
|
140
|
+
end
|
141
|
+
|
88
142
|
|
89
143
|
it "should handle have error for object" do
|
90
144
|
textfieldbind = { 'label' => 'Address',
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhodes-translator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Rhomobile
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-02-11 00:00:00 -08:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -56,6 +62,11 @@ files:
|
|
56
62
|
- lib/rhodes_translator/templates/view.erb
|
57
63
|
- lib/rhodes_translator/translator.rb
|
58
64
|
- lib/rhodes_translator/validation.rb
|
65
|
+
- spec/binding_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
- spec/stubs.rb
|
68
|
+
- spec/translator_spec.rb
|
69
|
+
- spec/validator_spec.rb
|
59
70
|
has_rdoc: true
|
60
71
|
homepage: http://rhomobile.com/
|
61
72
|
licenses: []
|
@@ -66,21 +77,27 @@ rdoc_options:
|
|
66
77
|
require_paths:
|
67
78
|
- lib
|
68
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
69
81
|
requirements:
|
70
82
|
- - ">="
|
71
83
|
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
72
87
|
version: "0"
|
73
|
-
version:
|
74
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
75
90
|
requirements:
|
76
91
|
- - ">="
|
77
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
78
96
|
version: "0"
|
79
|
-
version:
|
80
97
|
requirements: []
|
81
98
|
|
82
99
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.3.
|
100
|
+
rubygems_version: 1.3.7
|
84
101
|
signing_key:
|
85
102
|
specification_version: 3
|
86
103
|
summary: Rhodes Metadata
|