ice 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -60,9 +60,13 @@ In order for everything to work easily, you can have your cubes inherit from our
60
60
 
61
61
  class BookCube < Ice::BaseCube
62
62
  revealing :title, :author_id, :genre_id
63
+
64
+ def reviewer_names
65
+ @source.reviewers.map(&:name)
66
+ end
63
67
  end
64
68
 
65
- would provide a cube with access to the title, author_id and genre properties of the underlying ActiveRecord.
69
+ would provide a cube with access to the title, author_id and genre properties of the underlying ActiveRecord. In addition, it exposes a reviewer_names function that uses the @source instance variable to get at the record which is being filtered.
66
70
 
67
71
  These cubes also have simple belongs_to and has_many associations, so you can write things like:
68
72
 
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/ludicast/ice"
12
12
  gem.authors = ["Nate Kidwell"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.add_dependency "therubyracer", "0.7.0"
14
+ gem.add_dependency "therubyracer", "0.7.1"
15
15
  gem.add_dependency "activesupport", ">= 2.2.0"
16
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/ice.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ice}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nate Kidwell"]
12
- s.date = %q{2010-05-31}
12
+ s.date = %q{2010-06-04}
13
13
  s.description = %q{User templates written in javascript}
14
14
  s.email = %q{nate@ludicast.com}
15
15
  s.extra_rdoc_files = [
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
42
42
  "lib/ice/cube_association.rb",
43
43
  "lib/ice/cubeable.rb",
44
44
  "lib/parser.js",
45
+ "lib/routes_js.rb",
45
46
  "rails/init.rb",
46
47
  "spec/base_cube_spec.rb",
47
48
  "spec/cube_spec.rb",
@@ -67,16 +68,16 @@ Gem::Specification.new do |s|
67
68
 
68
69
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
69
70
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
70
- s.add_runtime_dependency(%q<therubyracer>, ["= 0.7.0"])
71
+ s.add_runtime_dependency(%q<therubyracer>, ["= 0.7.1"])
71
72
  s.add_runtime_dependency(%q<activesupport>, [">= 2.2.0"])
72
73
  else
73
74
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
74
- s.add_dependency(%q<therubyracer>, ["= 0.7.0"])
75
+ s.add_dependency(%q<therubyracer>, ["= 0.7.1"])
75
76
  s.add_dependency(%q<activesupport>, [">= 2.2.0"])
76
77
  end
77
78
  else
78
79
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
79
- s.add_dependency(%q<therubyracer>, ["= 0.7.0"])
80
+ s.add_dependency(%q<therubyracer>, ["= 0.7.1"])
80
81
  s.add_dependency(%q<activesupport>, [">= 2.2.0"])
81
82
  end
82
83
  end
@@ -1,17 +1,24 @@
1
- function view_path(item) {
2
- return "/" + item.class_path + "/" + item.id
1
+ function link_to(location, default_label, opts) {
2
+ if (! default_label) {
3
+ default_label = location
4
+ }
5
+ label = (opts && opts.label) || default_label
6
+ return "<a href=\"" + location + "\">" + label + "</a>"
3
7
  }
4
8
 
5
- function edit_path(item) {
6
- return "/" + item.class_path + "/" + item.id + "/edit"
9
+ var NavBar = function () {
10
+
11
+ }
12
+
13
+ NavBar.prototype.link_to = function (link) {
14
+ return "<li>" + link_to(link) + "</li>"
15
+ }
16
+
17
+ NavBar.prototype.open = function () {
18
+ return "<ul class=\"linkBar\">"
7
19
  }
8
20
 
9
- function view_link(item, opts) {
10
- label = (opts && opts.label) || "View"
11
- return "<a href=\"" + view_path(item) + "\">" + label + "</a>"
21
+ NavBar.prototype.close = function () {
22
+ return "</ul>"
12
23
  }
13
24
 
14
- function edit_link(item, opts) {
15
- label = (opts && opts.label) || "Edit"
16
- return "<a href=\"" + edit_path(item) + "\">" + label + "</a>"
17
- }
@@ -1,40 +1,17 @@
1
-
2
- describe 'path_helper'
1
+ describe "nav bar helper"
3
2
  before_each
4
- user = {id:1, class_path:'users'}
3
+ bar = new NavBar()
5
4
  end
6
5
 
7
- describe 'for paths'
8
- it "should generate view path from item"
9
- view_path(user).should.eql "/users/1"
10
- end
11
6
 
12
- it "should generate edit path from item"
13
- edit_path(user).should.eql "/users/1/edit"
14
- end
7
+ it "should generate list by default"
8
+ (bar.open() + bar.close()).should.eql "<ul class=\"linkBar\"></ul>"
15
9
  end
16
10
 
11
+ it "should generate list with internal links"
17
12
 
18
- describe "for links"
19
- describe "without parameters"
20
- it "should generate view link from item"
21
- view_link(user).should.eql "<a href=\"/users/1\">View</a>"
22
- end
23
- it "should generate edit link from item"
24
- edit_link(user).should.eql "<a href=\"/users/1/edit\">Edit</a>"
25
- end
26
- end
27
-
28
- describe "with parameters"
29
- it "should generate view link from item"
30
- view_link(user, {label:"See Info"}).should.eql "<a href=\"/users/1\">See Info</a>"
31
- end
32
- it "should generate edit link from item"
33
- edit_link(user, {label:"Change Info"}).should.eql "<a href=\"/users/1/edit\">Change Info</a>"
34
- end
35
- end
13
+ links = (bar.open() + bar.link_to("ff") + bar.link_to("aa") + bar.close())
36
14
 
15
+ links.should.eql "<ul class=\"linkBar\"><li><a href=\"ff\">ff</a></li><li><a href=\"aa\">aa</a></li></ul>"
37
16
  end
38
-
39
-
40
- end
17
+ end
@@ -5,6 +5,7 @@
5
5
  #
6
6
  # ActionView::Base::register_template_handler :ice, IceView
7
7
  class IceView
8
+ include RoutesJs
8
9
  PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
9
10
  _response url _request _cookies variables_added _flash params _headers request cookies
10
11
  ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
@@ -41,6 +42,17 @@ class IceView
41
42
  assigns['content_for_layout'] = content_for_layout
42
43
  end
43
44
  assigns.merge!(local_assigns.stringify_keys)
45
+
46
+ route_functions = "<% " + get_routes + " %>"
47
+ puts route_functions
48
+ 5.times {puts "****************************"}
49
+
50
+ path_helper_code = File.read(File.dirname(__FILE__) + "/../../ice_js/lib/path_helper.js")
51
+ path_helper = "<% " + path_helper_code + " %>"
52
+ puts path_helper
53
+ source = route_functions + path_helper + source
54
+
55
+
44
56
  Ice.convert_template(source, assigns)
45
57
  #ice = Ice::Template.parse(source)
46
58
  #ice.render(assigns, :filters => [@view.controller.master_helper_module], :registers => {:action_view => @view, :controller => @view.controller})
data/lib/ice.rb CHANGED
@@ -7,12 +7,12 @@ class Object
7
7
  end
8
8
  end
9
9
 
10
- [FalseClass, TrueClass, Numeric, String].each do |class_name|
11
- eval "class #{class_name}
10
+ [FalseClass, TrueClass, Numeric, String].each do |cls|
11
+ cls.class_eval do
12
12
  def to_ice
13
13
  self
14
14
  end
15
- end"
15
+ end
16
16
  end
17
17
 
18
18
  class Array
@@ -43,12 +43,9 @@ module Ice
43
43
  cxt[key] = value.to_ice
44
44
  end
45
45
 
46
- cxt['____templateText'] = template_text
47
-
48
- @evaled = cxt.eval "Jst.evaluate(Jst.compile(____templateText), {});"
49
-
46
+ jst = cxt['Jst']
47
+ return @evaled = jst.evaluate(jst.compile(template_text), {})
50
48
  end
51
- @evaled
52
49
  end
53
50
  end
54
51
 
data/lib/routes_js.rb ADDED
@@ -0,0 +1,55 @@
1
+ module RoutesJs
2
+
3
+ def get_routes
4
+
5
+ response = rails_route_function
6
+
7
+ ActionController::Routing::Routes.routes.collect do |route|
8
+ path = route.segments.inject('') { |str,s| str << s.to_s }
9
+
10
+ named_route = ActionController::Routing::Routes.
11
+ named_routes.routes.key(route).to_s
12
+
13
+ if named_route != ''
14
+ response << route_function("#{named_route}_path", path)
15
+ end
16
+ end
17
+
18
+ response
19
+ end
20
+
21
+ private
22
+
23
+ def rails_route_function
24
+ <<EOF
25
+ function rails_route(path, var_pairs) {
26
+ var pair_index = 0,
27
+ path_copy = path;
28
+ for(; pair_index < var_pairs.length; pair_index++) {
29
+ path_copy = path_copy.replace(
30
+ ':' + var_pairs[pair_index][0],
31
+ var_pairs[pair_index][1]
32
+ );
33
+ }
34
+ return(
35
+ path_copy
36
+ .replace(/[(][.]:.+[)][?]/g, '')
37
+ .replace(/[(]|[)][?]/g, '')
38
+ );
39
+ }
40
+ EOF
41
+ end
42
+
43
+ def route_function name, path
44
+ <<EOF
45
+ function #{name}(variables) {
46
+ var var_pairs = [];
47
+ for(var key in variables) {
48
+ var_pairs.push([key, variables[key]]);
49
+ }
50
+ return(rails_route('#{path}', var_pairs));
51
+ }
52
+ EOF
53
+ end
54
+ end
55
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nate Kidwell
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-31 00:00:00 -04:00
17
+ date: 2010-06-04 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -41,8 +41,8 @@ dependencies:
41
41
  segments:
42
42
  - 0
43
43
  - 7
44
- - 0
45
- version: 0.7.0
44
+ - 1
45
+ version: 0.7.1
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
@@ -94,6 +94,7 @@ files:
94
94
  - lib/ice/cube_association.rb
95
95
  - lib/ice/cubeable.rb
96
96
  - lib/parser.js
97
+ - lib/routes_js.rb
97
98
  - rails/init.rb
98
99
  - spec/base_cube_spec.rb
99
100
  - spec/cube_spec.rb