ice 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,13 +34,9 @@ In addition, our ice_view.rb file is almost directly ripped out of the liquid pr
34
34
 
35
35
  ## Installation
36
36
 
37
- For Rails:
37
+ Ice is curently being developed only for Rails 3 (we have a Rails 2 branch as well). Simply add to your Gemfile
38
38
 
39
- config.gem 'ice'
40
-
41
- Otherwise:
42
-
43
- gem install ice
39
+ gem 'ice'
44
40
 
45
41
  ## to_ice
46
42
 
data/Rakefile CHANGED
@@ -11,8 +11,8 @@ 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.4"
15
- gem.add_dependency "activesupport", ">= 2.2.0"
14
+ gem.add_dependency "therubyracer", "0.7.5"
15
+ gem.add_dependency "rails", "3.0.0"
16
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
17
  end
18
18
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ice}
8
- s.version = "0.2.4"
8
+ s.version = "0.3.0"
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-06-17}
12
+ s.date = %q{2010-10-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 = [
@@ -40,22 +40,23 @@ Gem::Specification.new do |s|
40
40
  "init.rb",
41
41
  "lib/extras/ice_view.rb",
42
42
  "lib/ice.rb",
43
+ "lib/ice/base.rb",
43
44
  "lib/ice/base_cube.rb",
44
45
  "lib/ice/cube_association.rb",
45
46
  "lib/ice/cubeable.rb",
47
+ "lib/ice/railtie.rb",
46
48
  "lib/parser.js",
47
- "lib/routes_js.rb",
48
- "rails/init.rb",
49
49
  "spec/base_cube_spec.rb",
50
50
  "spec/cube_spec.rb",
51
51
  "spec/ice_spec.rb",
52
52
  "spec/spec.opts",
53
- "spec/spec_helper.rb"
53
+ "spec/spec_helper.rb",
54
+ "togo"
54
55
  ]
55
56
  s.homepage = %q{http://github.com/ludicast/ice}
56
57
  s.rdoc_options = ["--charset=UTF-8"]
57
58
  s.require_paths = ["lib"]
58
- s.rubygems_version = %q{1.3.5}
59
+ s.rubygems_version = %q{1.3.7}
59
60
  s.summary = %q{User templates written in javascript}
60
61
  s.test_files = [
61
62
  "spec/base_cube_spec.rb",
@@ -68,19 +69,19 @@ Gem::Specification.new do |s|
68
69
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
69
70
  s.specification_version = 3
70
71
 
71
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
72
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
72
73
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
73
- s.add_runtime_dependency(%q<therubyracer>, ["= 0.7.4"])
74
- s.add_runtime_dependency(%q<activesupport>, [">= 2.2.0"])
74
+ s.add_runtime_dependency(%q<therubyracer>, ["= 0.7.5"])
75
+ s.add_runtime_dependency(%q<rails>, ["= 3.0.0"])
75
76
  else
76
77
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
77
- s.add_dependency(%q<therubyracer>, ["= 0.7.4"])
78
- s.add_dependency(%q<activesupport>, [">= 2.2.0"])
78
+ s.add_dependency(%q<therubyracer>, ["= 0.7.5"])
79
+ s.add_dependency(%q<rails>, ["= 3.0.0"])
79
80
  end
80
81
  else
81
82
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
82
- s.add_dependency(%q<therubyracer>, ["= 0.7.4"])
83
- s.add_dependency(%q<activesupport>, [">= 2.2.0"])
83
+ s.add_dependency(%q<therubyracer>, ["= 0.7.5"])
84
+ s.add_dependency(%q<rails>, ["= 3.0.0"])
84
85
  end
85
86
  end
86
87
 
data/init.rb CHANGED
@@ -3,4 +3,4 @@ require 'ice/cubeable'
3
3
  require 'ice/cube_association'
4
4
  require 'ice/base_cube'
5
5
 
6
- require 'active_support'
6
+ require 'rails'
@@ -4,27 +4,127 @@
4
4
  # Example
5
5
  #
6
6
  # ActionView::Base::register_template_handler :ice, IceView
7
+
8
+ module RoutesJs
9
+
10
+ def get_routes
11
+
12
+ response = rails_route_function
13
+
14
+ Rails.application.routes.routes.collect do |route|
15
+
16
+ puts route.class.to_s
17
+ puts route.path
18
+
19
+
20
+
21
+ puts route.inspect
22
+
23
+ path = route.path
24
+ puts "%%%"
25
+ puts route.conditions.inspect
26
+ puts route.requirements
27
+
28
+ named_route = Rails.application.routes.
29
+ named_routes.routes.key(route).to_s
30
+
31
+ if named_route != ''
32
+ puts named_route + " kkyy " + route.path
33
+
34
+ if path.match /(.*)\(\.\:format\)$/
35
+ path = $1
36
+ end
37
+
38
+ response << route_function("#{named_route}_path", path)
39
+ end
40
+ end
41
+ # puts response
42
+ response
43
+ end
44
+
45
+ private
46
+
47
+ def rails_route_function
48
+ <<EOF
49
+ function rails_route(path, var_pairs) {
50
+ var pair_index = 0,
51
+ path_copy = path;
52
+ for(; pair_index < var_pairs.length; pair_index++) {
53
+ path_copy = path_copy.replace(
54
+ ':' + var_pairs[pair_index][0],
55
+ var_pairs[pair_index][1]
56
+ );
57
+ }
58
+ return(
59
+ path_copy
60
+ .replace(/[(][.]:.+[)][?]/g, '')
61
+ .replace(/[(]|[)][?]/g, '')
62
+ );
63
+ }
64
+ EOF
65
+ end
66
+
67
+ def route_function name, path
68
+ <<EOF
69
+ function #{name}(variables) {
70
+ var var_pairs = [];
71
+ for(var key in variables) {
72
+ var_pairs.push([key, variables[key]]);
73
+ }
74
+ return(rails_route('#{path}', var_pairs));
75
+ }
76
+ EOF
77
+ end
78
+ end
79
+
7
80
  class IceView
8
81
  include RoutesJs
82
+ include ActionView::Template::Handlers::Compilable
9
83
  PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
10
84
  _response url _request _cookies variables_added _flash params _headers request cookies
11
85
  ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
12
86
  PROTECTED_INSTANCE_VARIABLES = %w( @_request @controller @_first_render @_memoized__pick_template @view_paths
13
87
  @helpers @assigns_added @template @_render_stack @template_format @assigns )
14
88
 
15
- def self.call(template)
16
- "IceView.new(self).render(template, local_assigns)"
17
- end
89
+ # attr_accessor :controller
90
+
91
+ # def self.call(template)
92
+ # "IceView.new(self).render(#{template})"
93
+ # end
18
94
 
19
- def initialize(view)
95
+ def initialize(view = nil)
20
96
  @view = view
21
97
  end
22
98
 
23
- def render(template, local_assigns = nil)
99
+ def compile(template)
100
+
101
+ "IceView.new(self).render('#{template.inspect}' )"
102
+ end
103
+
104
+ def render(template, local_assigns = {})
105
+
24
106
  @view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'
107
+ source = open(Rails.root + template).read
108
+
109
+ assigns = @view.assigns.reject{ |k,v| PROTECTED_ASSIGNS.include?(k) }
110
+ if content_for_layout = @view.instance_variable_get("@content_for_layout")
111
+ assigns['content_for_layout'] = content_for_layout
112
+ end
113
+ assigns.merge!(local_assigns.stringify_keys)
114
+ route_functions = "<% " + get_routes + " %>\n"
115
+
116
+ path_helper_code = File.read(File.dirname(__FILE__) + "/../../ice_js/lib/path_helper.js")
117
+ path_helper = "<% " + path_helper_code + " %>\n"
118
+
119
+
120
+ source = route_functions + path_helper + source
121
+ # puts source
25
122
 
123
+ Ice.convert_template(source, assigns)
124
+ =begin
26
125
 
27
126
 
127
+ puts "hhhhhhhooooootttt"
28
128
  # Rails 2.2 Template has source, but not locals
29
129
  if template.respond_to?(:source) && !template.respond_to?(:locals)
30
130
  assigns = (@view.instance_variables - PROTECTED_INSTANCE_VARIABLES).inject({}) do |hash, ivar|
@@ -49,10 +149,14 @@ class IceView
49
149
  path_helper = "<% " + path_helper_code + " %>"
50
150
  source = route_functions + path_helper + source
51
151
 
52
-
152
+ puts "ooooootttt"
53
153
  Ice.convert_template(source, assigns)
54
154
  #ice = Ice::Template.parse(source)
55
155
  #ice.render(assigns, :filters => [@view.controller.master_helper_module], :registers => {:action_view => @view, :controller => @view.controller})
156
+
157
+ =end
158
+
159
+
56
160
  end
57
161
 
58
162
  def compilable?
data/lib/ice.rb CHANGED
@@ -1,51 +1,11 @@
1
- require 'rubygems'
2
- require 'v8'
3
-
4
- class Object
5
- def to_ice
6
- nil
7
- end
8
- end
9
-
10
- [FalseClass, TrueClass, Numeric, String].each do |cls|
11
- cls.class_eval do
12
- def to_ice
13
- self
14
- end
15
- end
16
- end
17
-
18
- class Array
19
- def to_ice
20
- map &:to_ice
21
- end
22
- end
23
-
24
- class Hash
25
- def to_ice
26
- res = {}
27
- each_pair do |key,value|
28
- res[key] = value.to_ice
29
- end
30
- res
31
- end
32
- end
33
-
1
+ require 'ice'
2
+ require 'ice/cubeable'
3
+ require 'ice/cube_association'
4
+ require 'ice/base_cube'
5
+ require 'ice/base'
34
6
 
7
+ require 'rails'
35
8
 
36
9
  module Ice
37
- def self.convert_template(template_text, vars = {})
38
-
39
- V8::Context.new do |cxt|
40
- cxt.load "#{File.dirname(__FILE__)}/parser.js"
41
-
42
- vars.each_pair do |key, value|
43
- cxt[key] = value.to_ice
44
- end
45
-
46
- jst = cxt['Jst']
47
- return @evaled = jst.evaluate(jst.compile(template_text), {})
48
- end
49
- end
10
+ require 'ice/railtie' if defined?(Rails)
50
11
  end
51
-
@@ -0,0 +1,50 @@
1
+ require 'v8'
2
+
3
+ class Object
4
+ def to_ice
5
+ nil
6
+ end
7
+ end
8
+
9
+ [FalseClass, TrueClass, Numeric, String].each do |cls|
10
+ cls.class_eval do
11
+ def to_ice
12
+ self
13
+ end
14
+ end
15
+ end
16
+
17
+ class Array
18
+ def to_ice
19
+ map &:to_ice
20
+ end
21
+ end
22
+
23
+ class Hash
24
+ def to_ice
25
+ res = {}
26
+ each_pair do |key,value|
27
+ res[key] = value.to_ice
28
+ end
29
+ res
30
+ end
31
+ end
32
+
33
+
34
+
35
+ module Ice
36
+ def self.convert_template(template_text, vars = {})
37
+
38
+ V8::Context.new do |cxt|
39
+ cxt.load "#{File.dirname(__FILE__)}/../parser.js"
40
+
41
+ vars.each_pair do |key, value|
42
+ cxt[key] = value.to_ice
43
+ end
44
+
45
+ jst = cxt['Jst']
46
+ return @evaled = jst.evaluate(jst.compile(template_text), {})
47
+ end
48
+ end
49
+ end
50
+
@@ -1,6 +1,13 @@
1
+ module Ice
2
+ class Railtie < Rails::Railtie
3
+ initializer "ice.configure_rails_initialization" do
4
+
5
+ end
6
+ end
7
+ end
8
+
1
9
  ActiveRecord::Base.send(:include, Ice::Cubeable)
2
10
 
3
- require File.dirname(__FILE__) + "/../init"
4
11
  require 'extras/ice_view'
5
12
 
6
13
  if defined? ActionView::Template and ActionView::Template.respond_to? :register_template_handler
@@ -1,12 +1,9 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
-
4
-
5
3
  class FooClassCube < Ice::BaseCube
6
4
  revealing :first, :second
7
5
  end
8
6
 
9
-
10
7
  class FooClass
11
8
  include Ice::Cubeable
12
9
 
data/togo ADDED
@@ -0,0 +1,60 @@
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
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Nate Kidwell
@@ -9,39 +14,54 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-06-17 00:00:00 -04:00
17
+ date: 2010-10-04 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
23
32
  version: 1.2.9
24
- version:
33
+ type: :development
34
+ version_requirements: *id001
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: therubyracer
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
30
40
  requirements:
31
41
  - - "="
32
42
  - !ruby/object:Gem::Version
33
- version: 0.7.4
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: activesupport
43
+ segments:
44
+ - 0
45
+ - 7
46
+ - 5
47
+ version: 0.7.5
37
48
  type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rails
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
40
55
  requirements:
41
- - - ">="
56
+ - - "="
42
57
  - !ruby/object:Gem::Version
43
- version: 2.2.0
44
- version:
58
+ segments:
59
+ - 3
60
+ - 0
61
+ - 0
62
+ version: 3.0.0
63
+ type: :runtime
64
+ version_requirements: *id003
45
65
  description: User templates written in javascript
46
66
  email: nate@ludicast.com
47
67
  executables: []
@@ -75,17 +95,18 @@ files:
75
95
  - init.rb
76
96
  - lib/extras/ice_view.rb
77
97
  - lib/ice.rb
98
+ - lib/ice/base.rb
78
99
  - lib/ice/base_cube.rb
79
100
  - lib/ice/cube_association.rb
80
101
  - lib/ice/cubeable.rb
102
+ - lib/ice/railtie.rb
81
103
  - lib/parser.js
82
- - lib/routes_js.rb
83
- - rails/init.rb
84
104
  - spec/base_cube_spec.rb
85
105
  - spec/cube_spec.rb
86
106
  - spec/ice_spec.rb
87
107
  - spec/spec.opts
88
108
  - spec/spec_helper.rb
109
+ - togo
89
110
  has_rdoc: true
90
111
  homepage: http://github.com/ludicast/ice
91
112
  licenses: []
@@ -96,21 +117,25 @@ rdoc_options:
96
117
  require_paths:
97
118
  - lib
98
119
  required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
99
121
  requirements:
100
122
  - - ">="
101
123
  - !ruby/object:Gem::Version
124
+ segments:
125
+ - 0
102
126
  version: "0"
103
- version:
104
127
  required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
105
129
  requirements:
106
130
  - - ">="
107
131
  - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
108
134
  version: "0"
109
- version:
110
135
  requirements: []
111
136
 
112
137
  rubyforge_project:
113
- rubygems_version: 1.3.5
138
+ rubygems_version: 1.3.7
114
139
  signing_key:
115
140
  specification_version: 3
116
141
  summary: User templates written in javascript
@@ -1,55 +0,0 @@
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
-