ice 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,45 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- class FooClassCube < Ice::BaseCube
4
- revealing :first, :second
5
- end
6
-
7
- class FooClass
8
- include Ice::Cubeable
9
-
10
- def first
11
- "primero"
12
- end
13
-
14
- def second
15
- @second ||= SecondClass.new
16
- end
17
- end
18
-
19
- class SecondClass
20
- def to_ice
21
- "segundo"
22
- end
23
-
24
- end
25
-
26
-
27
- describe "BaseCube" do
28
- context "a cubeable class" do
29
- it "should automatically to_ice the cube_class" do
30
- FooClass.new.to_ice.class.should == FooClassCube
31
- end
32
-
33
- it "should retrieve revealed properties" do
34
- FooClass.new.to_ice.first.should == "primero"
35
- end
36
-
37
- it "should map revealed properties via to_ice" do
38
- FooClass.new.to_ice.second.should == "segundo"
39
- end
40
-
41
- end
42
-
43
-
44
-
45
- end
data/spec/cube_spec.rb DELETED
@@ -1,119 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- class ParentObj
4
- def to_ice
5
- "parent"
6
- end
7
- end
8
-
9
- class TagObj
10
- def to_ice
11
- @name
12
- end
13
-
14
- def initialize(name)
15
- @name = name
16
- end
17
-
18
- end
19
-
20
-
21
- class ChildModel
22
- def parent
23
- @parent ||= ParentObj.new
24
- end
25
-
26
- def parent_id
27
- 15
28
- end
29
-
30
- def tags
31
- @tags ||= [TagObj.new("tag1"), TagObj.new("tag2")]
32
- end
33
-
34
- def tag_ids
35
- [1, 2]
36
- end
37
-
38
- def children
39
- []
40
- end
41
-
42
- end
43
-
44
-
45
- class BaseCubeWithBelongsTo
46
- extend Ice::CubeAssociation
47
-
48
- def initialize
49
- @source = ChildModel.new
50
- end
51
-
52
- belongs_to :parent
53
- end
54
-
55
- class BaseCubeWithHasMany
56
- extend Ice::CubeAssociation
57
-
58
- def initialize
59
- @source = ChildModel.new
60
- end
61
- has_many :tags
62
- has_many :children
63
- end
64
-
65
- describe "Cube" do
66
-
67
- context "which has associations" do
68
- context "when belongs to an item" do
69
-
70
- it "should delegate object calls to its source object" do
71
- cube = BaseCubeWithBelongsTo.new
72
- cube.parent.should == "parent"
73
- end
74
-
75
- it "should delegate id calls to its source object" do
76
- cube = BaseCubeWithBelongsTo.new
77
- cube.parent_id.should == 15
78
- end
79
-
80
- end
81
-
82
-
83
-
84
- context "when has many of an item" do
85
-
86
- context "for populated collection" do
87
- it "should delegate object calls to its source object" do
88
- cube = BaseCubeWithHasMany.new
89
- cube.tags.should == ["tag1", "tag2"]
90
- end
91
-
92
- it "should return true from has" do
93
- cube = BaseCubeWithHasMany.new
94
- cube.has_tags.should == true
95
- end
96
-
97
- it "should return tag count" do
98
- cube = BaseCubeWithHasMany.new
99
- cube.num_tags.should == 2
100
- end
101
-
102
- it "should delegate id calls to its source object" do
103
- cube = BaseCubeWithHasMany.new
104
- cube.tag_ids.should == [1, 2]
105
- end
106
- end
107
-
108
- context "for empty collection" do
109
- it "should return false from has" do
110
- cube = BaseCubeWithHasMany.new
111
- cube.has_children.should == false
112
- end
113
- end
114
- end
115
- end
116
- end
117
-
118
-
119
-
data/spec/ice_spec.rb DELETED
@@ -1,97 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Ice" do
4
-
5
- it "converts a javascript template to html" do
6
- Ice.convert_template("<%= 'hello world' %>").should == "hello world"
7
- end
8
-
9
- it "takes variables as syms" do
10
- vars = {:hola => "hello", :mundo => "world" }
11
- Ice.convert_template("<%= hola + ' ' + mundo %>", vars).should == "hello world"
12
- end
13
-
14
- it "accepts ampersands" do
15
- vars = {:foo => "&"}
16
- Ice.convert_template("<%= foo %>", vars).should == "&"
17
- end
18
-
19
- it "takes variables as string" do
20
- vars = {'hola' => "hello", 'mundo' => "world" }
21
- Ice.convert_template("<%= hola + ' ' + mundo %>", vars).should == "hello world"
22
- end
23
-
24
- it "takes booleans, strings, and numbers as their value" do
25
- vars = {'integer' => 1, 'float' => 1.1, 'boolean' => true, 'string' => "String"}
26
- Ice.convert_template('<%= integer + " " + float + " " + boolean + " " + string %>',
27
- vars).should == "1 1.1 true String"
28
- end
29
-
30
- context "to_ice function" do
31
- it "should allow identical values for true" do
32
- true.to_ice.should == true
33
- end
34
-
35
- it "should allow identical values for false" do
36
- false.to_ice.should == false
37
- end
38
-
39
- it "should allow identical values for integer" do
40
- 1.to_ice.should == 1
41
- end
42
-
43
- it "should allow identical values for float" do
44
- 1.1.to_ice.should == 1.1
45
- end
46
-
47
- it "should allow identical values for string" do
48
- "hi".to_ice.should == "hi"
49
- end
50
-
51
- it "should default to nil for an object" do
52
- Object.new.to_ice.should be_nil
53
- end
54
- context "for array" do
55
- it "should freeze elements of array" do
56
- i = []
57
- i.should_receive(:to_ice)
58
- [i].to_ice
59
- end
60
- it "should return array" do
61
- array = [1, "foo"]
62
- array.to_ice.should == [1, "foo"]
63
- end
64
- it "should pass in array with details" do
65
- myarray = ["one", "two", "three"]
66
- vars = {"myarray" => myarray }
67
- Ice.convert_template(%{<% for (var i = 0; i < myarray.length; i++) { %><p><%= myarray[i] %></p><% } %>},
68
- vars).should == "<p>one</p><p>two</p><p>three</p>"
69
-
70
- end
71
-
72
- end
73
- context "for hash" do
74
- it "should freeze elements of array" do
75
- i = []
76
- i.should_receive(:to_ice)
77
- {:var => i}.to_ice
78
- end
79
- it "should return hash" do
80
- hash = {"foo" => 1}
81
- hash.to_ice.should == {"foo" => 1}
82
- end
83
- end
84
-
85
- it "should run to_ice on variables" do
86
- message = Object.new
87
- def message.to_ice
88
- "hello world"
89
- end
90
-
91
- vars = {'message' => message }
92
- Ice.convert_template("<%= message %>", vars).should == "hello world"
93
- end
94
- end
95
-
96
-
97
- end
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --color
data/spec/spec_helper.rb DELETED
@@ -1,12 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
-
4
- require File.dirname(__FILE__) + "/../init"
5
- require 'spec'
6
- require 'spec/autorun'
7
-
8
-
9
-
10
- Spec::Runner.configure do |config|
11
-
12
- end
data/togo DELETED
@@ -1,60 +0,0 @@
1
-
2
- class IceView
3
- include RoutesJs
4
- PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
5
- _response url _request _cookies variables_added _flash params _headers request cookies
6
- ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
7
- PROTECTED_INSTANCE_VARIABLES = %w( @_request @controller @_first_render @_memoized__pick_template @view_paths
8
- @helpers @assigns_added @template @_render_stack @template_format @assigns )
9
-
10
- def self.call(template)
11
-
12
- IceView.new(self).render(template)
13
- end
14
-
15
- def initialize(view)
16
- @view = view
17
- end
18
-
19
- def render(template, local_assigns = nil)
20
- puts "rendering... #{@view.inspect} ### #{template.inspect}"
21
-
22
- @view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
23
-
24
-
25
-
26
- # Rails 2.2 Template has source, but not locals
27
- if template.respond_to?(:source) && !template.respond_to?(:locals)
28
- assigns = (@view.instance_variables - PROTECTED_INSTANCE_VARIABLES).inject({}) do |hash, ivar|
29
- hash[ivar[1..-1]] = @view.instance_variable_get(ivar)
30
- hash
31
- end
32
- else
33
- assigns = @view.assigns.reject{ |k,v| PROTECTED_ASSIGNS.include?(k) }
34
- end
35
-
36
- source = template.respond_to?(:source) ? template.source : template
37
- local_assigns = (template.respond_to?(:locals) ? template.locals : local_assigns) || {}
38
-
39
- if content_for_layout = @view.instance_variable_get("@content_for_layout")
40
- assigns['content_for_layout'] = content_for_layout
41
- end
42
- assigns.merge!(local_assigns.stringify_keys)
43
-
44
- route_functions = "<% " + get_routes + " %>"
45
-
46
- path_helper_code = File.read(File.dirname(__FILE__) + "/../../ice_js/lib/path_helper.js")
47
- path_helper = "<% " + path_helper_code + " %>"
48
- source = route_functions + path_helper + source
49
-
50
-
51
- Ice.convert_template(source, assigns)
52
- #ice = Ice::Template.parse(source)
53
- #ice.render(assigns, :filters => [@view.controller.master_helper_module], :registers => {:action_view => @view, :controller => @view.controller})
54
- end
55
-
56
- def compilable?
57
- false
58
- end
59
-
60
- end